ShopController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use backendApi\modules\v1\models\exportForms\OrderExportForm;
  10. use backendApi\modules\v1\models\exportForms\ShopExportForm;
  11. use backendApi\modules\v1\models\lists\shop\DecOrderList;
  12. use backendApi\modules\v1\models\lists\shop\GoodsList;
  13. use backendApi\modules\v1\models\lists\shop\OrderDecList;
  14. use backendApi\modules\v1\models\lists\shop\OrderList;
  15. use backendApi\modules\v1\models\lists\shop\OrderShopList;
  16. use backendApi\modules\v1\models\lists\shop\OrderStandardList;
  17. use backendApi\modules\v1\models\lists\shop\PackageList;
  18. use common\helpers\bonus\CalcCache;
  19. use common\helpers\Cache;
  20. use common\helpers\Date;
  21. use common\helpers\Form;
  22. use common\helpers\Log;
  23. use common\helpers\snowflake\SnowFake;
  24. use common\libs\export\module\ShopExport;
  25. use common\models\DeclarationPackage;
  26. use common\models\DecOrder;
  27. use common\models\ExcelOrderShop;
  28. use common\models\forms\DecPackageForm;
  29. use common\models\forms\ExcelOrderDecForm;
  30. use common\models\forms\ExcelOrderShopForm;
  31. use common\models\forms\ExcelOrderStandardForm;
  32. use common\models\forms\OrderDeleteForm;
  33. use common\models\forms\OrderForm;
  34. use common\models\forms\ShopGoodsForm;
  35. use common\models\forms\UploadForm;
  36. use common\models\ShopGoods;
  37. use yii\web\UploadedFile;
  38. use yii\base\Exception;
  39. class ShopController extends BaseController {
  40. public $modelClass = DecOrder::class;
  41. public function behaviors() {
  42. $behaviors = parent::behaviors();
  43. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  44. return $behaviors;
  45. }
  46. /**
  47. * 商品列表
  48. * @return mixed
  49. * @throws Exception
  50. * @throws \yii\web\HttpException
  51. */
  52. public function actionIndex() {
  53. $filter = $this->filterCondition([
  54. 'TYPE'=> 'TYPE',
  55. 'GIFT_TYPE'=> 'GIFT_TYPE',
  56. 'STATUS'=> 'STATUS',
  57. 'GOODS_NAME'=> 'GOODS_NAME',
  58. 'GOODS_NO'=> 'GOODS_NO',
  59. 'SELL_TYPE'=> 'SELL_TYPE',
  60. 'SELL_PRICE'=> 'SELL_PRICE',
  61. 'PRICE_PV'=> 'PRICE_PV',
  62. ]);
  63. $condition = $filter['condition'];
  64. $params = $filter['params'];
  65. $condition .= ' ';
  66. $listObj = new GoodsList();
  67. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  68. return static::notice($data);
  69. }
  70. /**
  71. * 商品列表导出
  72. * @return mixed
  73. * @throws \yii\db\Exception
  74. * @throws \yii\web\HttpException
  75. */
  76. public function actionGoodsListExport()
  77. {
  78. $filter = $this->filterCondition([
  79. 'TYPE'=> 'TYPE',
  80. 'GIFT_TYPE'=> 'GIFT_TYPE',
  81. 'STATUS'=> 'STATUS',
  82. 'GOODS_NAME'=> 'GOODS_NAME',
  83. 'GOODS_NO'=> 'GOODS_NO',
  84. 'SELL_TYPE'=> 'SELL_TYPE',
  85. 'SELL_PRICE'=> 'SELL_PRICE',
  86. 'PRICE_PV'=> 'PRICE_PV',
  87. ]);
  88. $form = new ShopExportForm();
  89. $result = $form->run($filter, '商品列表');
  90. if (!$result) {
  91. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  92. }
  93. return static::notice('导出开始,请到文件管理-导出文件查看');
  94. }
  95. /**
  96. * 添加商品
  97. * @return mixed
  98. * @throws Exception
  99. * @throws \yii\web\HttpException
  100. */
  101. public function actionGoodsAdd() {
  102. if (\Yii::$app->request->isPost) {
  103. $formModel = new ShopGoodsForm();
  104. $formModel->scenario = 'add';
  105. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  106. return static::notice('商品添加成功');
  107. } else {
  108. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  109. }
  110. }
  111. return static::notice(['sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  112. }
  113. /**
  114. * 编辑商品
  115. * @return mixed
  116. * @throws Exception
  117. * @throws \yii\web\HttpException
  118. */
  119. public function actionGoodsEdit() {
  120. $id = \Yii::$app->request->get('id');
  121. if (\Yii::$app->request->isPost) {
  122. $formModel = new ShopGoodsForm();
  123. $formModel->scenario = 'edit';
  124. $formModel->id = $id;
  125. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  126. return static::notice('商品编辑成功');
  127. } else {
  128. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  129. }
  130. }
  131. $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
  132. $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
  133. $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
  134. if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
  135. $data['SELL_DISCOUNT'] = ShopGoods::GOODS_TYPE[$data['TYPE']]['discount']/100;
  136. }
  137. return static::notice(['goodsInfo'=>$data,'sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  138. }
  139. /**
  140. * 上传图片
  141. * @return mixed
  142. * @throws \yii\base\Exception
  143. * @throws \yii\db\Exception
  144. * @throws \yii\web\HttpException
  145. */
  146. public function actionUpload(){
  147. if(\Yii::$app->request->isPost){
  148. $formModel = new UploadForm();
  149. $formModel->scenario = 'goodsImg';
  150. $formModel->file = UploadedFile::getInstanceByName('file');
  151. $formModel->token = \Yii::$app->request->request('uploadToken');
  152. if($formModel->file && $uploader = $formModel->upload()){
  153. return static::notice($uploader->URL);
  154. } else {
  155. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  156. }
  157. } else {
  158. $token = Cache::setUploadToken();
  159. return static::notice($token);
  160. }
  161. }
  162. /**
  163. * 商品上下架
  164. * @return mixed
  165. * @throws Exception
  166. */
  167. public function actionGoodsStatus() {
  168. $id = \Yii::$app->request->get('id');
  169. if (\Yii::$app->request->isPost) {
  170. $formModel = new ShopGoodsForm();
  171. $formModel->scenario = 'changeStatus';
  172. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  173. // foreach ($result['logs'] as $k => $value) {
  174. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  175. // }
  176. return static::notice('状态设置成功');
  177. } else {
  178. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  179. }
  180. }
  181. }
  182. /**
  183. * 删除商品
  184. * @return mixed
  185. * @throws \yii\db\Exception
  186. * @throws \yii\web\HttpException
  187. */
  188. public function actionGoodsDelete(){
  189. $result = static::delete(ShopGoods::class);
  190. return $result;
  191. }
  192. /**
  193. * 套餐列表
  194. * @return mixed
  195. * @throws Exception
  196. * @throws \yii\web\HttpException
  197. */
  198. public function actionPackage() {
  199. $filter = $this->filterCondition([
  200. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  201. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  202. 'AMOUNT'=> 'DP.AMOUNT',
  203. 'PV'=> 'DP.PV',
  204. 'STATUS'=> 'DP.STATUS',
  205. 'STORE_NUMS'=>'DP.STORE_NUMS',
  206. 'STATUS_DATE'=>'DP.STATUS_DATE',
  207. 'PACKAGE_DATE'=>'DP.PACKAGE_DATE',
  208. 'PACKAGE_STATUS_DATE'=>'DP.PACKAGE_STATUS_DATE'
  209. ]);
  210. $condition = $filter['condition'];
  211. $params = $filter['params'];
  212. $condition .= ' AND DP.IS_DEL=0';
  213. $listObj = new PackageList();
  214. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  215. return static::notice($data);
  216. }
  217. /**
  218. * 添加报单套餐
  219. * @return mixed
  220. * @throws \yii\web\HttpException
  221. */
  222. public function actionPackageAdd() {
  223. if (\Yii::$app->request->isPost) {
  224. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  225. // Log::adminHandle('添加报单套餐', 1);
  226. });
  227. }
  228. return static::notice('非发请求', 405);
  229. }
  230. /**
  231. * 报单套餐获取
  232. * @return mixed
  233. * @throws \yii\web\HttpException
  234. */
  235. public function actionPackageGet() {
  236. $id = \Yii::$app->request->get('id');
  237. if (\Yii::$app->request->isPost) {
  238. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  239. // Log::adminHandle('编辑报单套餐', 1);
  240. });
  241. }
  242. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  243. return static::notice(['id' => $package['ID'], 'packageName' => $package['PACKAGE_NAME'],'packageNo' => $package['PACKAGE_NO'], 'amount' => $package['AMOUNT'], 'amountPv' => $package['PV'], 'levelId' => $package['LEVEL_ID'], 'packageContent' => $package['PACKAGE_CONTENT'],'storenums' => $package['STORE_NUMS'],'statusdate'=>$package['STATUS_DATE'],'packagedate'=>$package['PACKAGE_DATE'],'packagestatusdate'=>$package['PACKAGE_STATUS_DATE']]);
  244. }
  245. /**
  246. * 套餐上下架
  247. * @return mixed
  248. * @throws Exception
  249. */
  250. public function actionPackageStatus() {
  251. $id = \Yii::$app->request->get('id');
  252. if (\Yii::$app->request->isPost) {
  253. $formModel = new DecPackageForm();
  254. $formModel->scenario = 'changeStatus';
  255. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  256. return static::notice('状态设置成功');
  257. } else {
  258. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  259. }
  260. }
  261. }
  262. /**
  263. * 删除套餐
  264. * @return mixed
  265. * @throws \yii\db\Exception
  266. * @throws \yii\web\HttpException
  267. */
  268. public function actionPackageDelete(){
  269. $result = static::delete(DeclarationPackage::class);
  270. return $result;
  271. }
  272. /**
  273. * 报单表
  274. * @return mixed
  275. * @throws Exception
  276. * @throws \yii\web\HttpException
  277. */
  278. public function actionDecOrderList() {
  279. $filter = $this->filterCondition([
  280. 'DEC_SN'=> 'DO.DEC_SN',
  281. 'ORDER_SN'=> 'DO.ORDER_SN',
  282. 'USER_NAME'=> 'U.USER_NAME',
  283. 'TO_USER_NAME'=> 'TU.USER_NAME',
  284. 'REAL_NAME'=> 'TU.REAL_NAME',
  285. 'ID_CARD'=> 'TU.ID_CARD',
  286. 'MOBILE'=> 'TU.MOBILE',
  287. 'DEC_LV_NAME' => 'TU.DEC_LV',
  288. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  289. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  290. 'DEC_PV'=> 'DO.DEC_PV',
  291. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  292. 'REC_USER_NAME'=> 'RU.USER_NAME',
  293. 'CREATED_AT'=> 'DO.CREATED_AT',
  294. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  295. ]);
  296. $condition = $filter['condition'];
  297. $params = $filter['params'];
  298. $condition .= ' AND DO.IS_DEL=0';
  299. $listObj = new DecOrderList();
  300. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  301. return static::notice($data);
  302. }
  303. /**
  304. * 报单表导出
  305. * @return mixed
  306. * @throws \yii\db\Exception
  307. * @throws \yii\web\HttpException
  308. */
  309. public function actionDecOrderListExport()
  310. {
  311. $filter = $this->filterCondition([
  312. 'DEC_SN'=> 'DO.DEC_SN',
  313. 'ORDER_SN'=> 'DO.ORDER_SN',
  314. 'USER_NAME'=> 'U.USER_NAME',
  315. 'TO_USER_NAME'=> 'TU.USER_NAME',
  316. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  317. 'DEC_PV'=> 'DO.DEC_PV',
  318. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  319. 'CREATED_AT'=> 'DO.CREATED_AT',
  320. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  321. ]);
  322. $filter['condition'] .= ' AND DO.IS_DEL=0';
  323. $form = new ShopExportForm();
  324. $result = $form->run($filter, '报单列表');
  325. if (!$result) {
  326. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  327. }
  328. return static::notice('导出开始,请到文件管理-导出文件查看');
  329. }
  330. /**
  331. * 订单表
  332. * @return mixed
  333. * @throws Exception
  334. * @throws \yii\web\HttpException
  335. */
  336. public function actionOrderList() {
  337. $filter = $this->filterCondition([
  338. 'SN'=> 'O.SN',
  339. 'USER_NAME'=> 'U.USER_NAME',
  340. 'MOBILE'=> 'O.MOBILE',
  341. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  342. 'CREATED_AT'=> 'O.CREATED_AT',
  343. ]);
  344. $condition = $filter['condition'];
  345. $params = $filter['params'];
  346. $condition .= ' AND O.IS_DELETE=0';
  347. $listObj = new OrderList();
  348. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  349. return static::notice($data);
  350. }
  351. // 删除订单
  352. public function actionDeleteOrder() {
  353. if (\Yii::$app->request->isPost) {
  354. $formModel = new OrderDeleteForm();
  355. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  356. return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
  357. } else {
  358. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  359. }
  360. }
  361. }
  362. /**
  363. * 订单表导出
  364. * @return mixed
  365. * @throws \yii\db\Exception
  366. * @throws \yii\web\HttpException
  367. */
  368. public function actionOrderListExport()
  369. {
  370. $filter = $this->filterCondition([
  371. 'SN'=> 'O.SN',
  372. 'USER_NAME'=> 'U.USER_NAME',
  373. 'MOBILE'=> 'O.MOBILE',
  374. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  375. 'CREATED_AT'=> 'O.CREATED_AT',
  376. ]);
  377. $filter['condition'] .= ' AND O.IS_DELETE=0';
  378. $form = new ShopExportForm();
  379. $result = $form->run($filter, '订单列表');
  380. if (!$result) {
  381. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  382. }
  383. return static::notice('导出开始,请到文件管理-导出文件查看');
  384. }
  385. /**
  386. * 外部商城订单列表
  387. * @return mixed
  388. * @throws Exception
  389. * @throws \yii\web\HttpException
  390. */
  391. public function actionOrderShopList() {
  392. $filter = $this->filterCondition([
  393. 'SN'=> 'O.SN',
  394. 'USER_NAME'=> 'U.USER_NAME',
  395. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  396. 'CREATED_AT'=> 'O.CREATED_AT',
  397. ]);
  398. $condition = $filter['condition'];
  399. $params = $filter['params'];
  400. $condition .= ' AND O.IS_DELETE=0';
  401. $listObj = new OrderShopList();
  402. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  403. return static::notice($data);
  404. }
  405. /**
  406. * 外部商城报单列表
  407. * @return mixed
  408. * @throws Exception
  409. * @throws \yii\web\HttpException
  410. */
  411. public function actionOrderDecList() {
  412. $filter = $this->filterCondition([
  413. 'SN'=> 'O.SN',
  414. 'USER_NAME'=> 'U.USER_NAME',
  415. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  416. 'CREATED_AT'=> 'O.CREATED_AT',
  417. ]);
  418. $condition = $filter['condition'];
  419. $params = $filter['params'];
  420. $condition .= ' AND O.IS_DELETE=0';
  421. $listObj = new OrderDecList();
  422. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  423. return static::notice($data);
  424. }
  425. /**
  426. * 分页导入excel文件到待导入数据的表中
  427. * @return mixed
  428. */
  429. public function actionImportOrderShopToExcelTable()
  430. {
  431. // 先上传到服务器文件
  432. if (\Yii::$app->request->isPost) {
  433. $excelImportId = \Yii::$app->request->post('excelImportId');
  434. $rowCount = \Yii::$app->request->post('rowCount');
  435. //$periodNum = \Yii::$app->request->post('periodNum');
  436. $orderDay = \Yii::$app->request->post('orderDay');
  437. $orderType = \Yii::$app->request->post('orderType');
  438. $startRow = \Yii::$app->request->post('startRow');
  439. $limit = \Yii::$app->request->post('limit', 1000);
  440. $errorMsg = '';
  441. try {
  442. if( $startRow == 1 ) {
  443. $excelOrderShop = new ExcelOrderShopForm();
  444. $excelOrderShop->checkStatus($orderDay,$orderType);
  445. }
  446. $excel = new \common\helpers\Excel();
  447. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  448. } catch (\Exception $e) {
  449. $result = false;
  450. $errorMsg = $e->getMessage();
  451. }
  452. // 还有数据
  453. if ($result === 1) {
  454. return static::notice(['finish' => false]);
  455. } elseif ($result === 0) {
  456. return static::notice(['finish' => true]);
  457. } else {
  458. return static::notice('发生错误:' . $errorMsg, 400);
  459. }
  460. }
  461. }
  462. /**
  463. * 导入完成标记
  464. * @return mixed
  465. * @throws \yii\web\HttpException
  466. */
  467. public function actionImportOrderShop() {
  468. //$periodNum = \Yii::$app->request->post('periodNum');
  469. $orderDay = \Yii::$app->request->post('orderDay');
  470. $orderType = \Yii::$app->request->post('orderType');
  471. $excelOrderShop = new ExcelOrderShopForm();
  472. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  473. if ($finishStatus) {
  474. return static::notice(['finish' => true]);
  475. } else {
  476. return static::notice('状态更新错误', 400);
  477. }
  478. }
  479. /**
  480. * 报单订单——分页导入excel文件到待导入数据的表中
  481. * @return mixed
  482. */
  483. public function actionImportOrderDecToExcelTable()
  484. {
  485. // 先上传到服务器文件
  486. if (\Yii::$app->request->isPost) {
  487. $excelImportId = \Yii::$app->request->post('excelImportId');
  488. $rowCount = \Yii::$app->request->post('rowCount');
  489. //$periodNum = \Yii::$app->request->post('periodNum');
  490. $orderDay = \Yii::$app->request->post('orderDay');
  491. $startRow = \Yii::$app->request->post('startRow');
  492. $limit = \Yii::$app->request->post('limit', 1000);
  493. $errorMsg = '';
  494. try {
  495. if( $startRow == 1 ) {
  496. $excelOrderShop = new ExcelOrderDecForm();
  497. $excelOrderShop->checkStatus($orderDay);
  498. }
  499. $excel = new \common\helpers\Excel();
  500. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  501. } catch (\Exception $e) {
  502. $result = false;
  503. $errorMsg = $e->getMessage();
  504. }
  505. // 还有数据
  506. if ($result === 1) {
  507. return static::notice(['finish' => false]);
  508. } elseif ($result === 0) {
  509. return static::notice(['finish' => true]);
  510. } else {
  511. return static::notice('发生错误:' . $errorMsg, 400);
  512. }
  513. }
  514. }
  515. /**
  516. * 报单订单导入完成标记
  517. * @return mixed
  518. * @throws \yii\web\HttpException
  519. */
  520. public function actionImportOrderDec() {
  521. //$periodNum = \Yii::$app->request->post('periodNum');
  522. $orderDay = \Yii::$app->request->post('orderDay');
  523. $excelOrderShop = new ExcelOrderDecForm();
  524. $finishStatus = $excelOrderShop->finished($orderDay);
  525. if ($finishStatus) {
  526. return static::notice(['finish' => true]);
  527. } else {
  528. return static::notice('状态更新错误', 400);
  529. }
  530. }
  531. /**
  532. * 见习达标订单列表
  533. * @return mixed
  534. * @throws Exception
  535. * @throws \yii\web\HttpException
  536. */
  537. public function actionOrderStandardList() {
  538. $filter = $this->filterCondition([
  539. 'SN'=> 'O.SN',
  540. 'USER_NAME'=> 'U.USER_NAME',
  541. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  542. 'CREATED_AT'=> 'O.CREATED_AT',
  543. ]);
  544. $condition = $filter['condition'];
  545. $params = $filter['params'];
  546. $condition .= ' AND O.IS_DELETE=0';
  547. $listObj = new OrderStandardList();
  548. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  549. return static::notice($data);
  550. }
  551. /**
  552. * 分页导入excel文件到待导入数据的表中
  553. * @return mixed
  554. * @throws \yii\web\HttpException
  555. */
  556. public function actionImportOrderStandardToExcelTable()
  557. {
  558. // 先上传到服务器文件
  559. if (\Yii::$app->request->isPost) {
  560. $excelImportId = \Yii::$app->request->post('excelImportId');
  561. $rowCount = \Yii::$app->request->post('rowCount');
  562. //$periodNum = \Yii::$app->request->post('periodNum');
  563. $orderMonth = \Yii::$app->request->post('orderMonth');
  564. // $orderType = \Yii::$app->request->post('orderType');
  565. $orderType = 'cash';
  566. $startRow = \Yii::$app->request->post('startRow');
  567. $limit = \Yii::$app->request->post('limit', 1000);
  568. $errorMsg = '';
  569. try {
  570. if( $startRow == 1 ) {
  571. //清空已经导入的表数据
  572. $excelOrderStandard = new ExcelOrderStandardForm();
  573. $excelOrderStandard->checkStatus($orderMonth);
  574. }
  575. $excel = new \common\helpers\Excel();
  576. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  577. } catch (Exception $e) {
  578. $result = false;
  579. $errorMsg = $e->getMessage();
  580. }
  581. // 还有数据
  582. if ($result === 1) {
  583. return static::notice(['finish' => false]);
  584. } elseif ($result === 0) {
  585. return static::notice(['finish' => true]);
  586. } else {
  587. return static::notice('发生错误:' . $errorMsg, 400);
  588. }
  589. }
  590. }
  591. /**
  592. * 达标订单导入完成标记
  593. * @return mixed
  594. * @throws \yii\web\HttpException
  595. */
  596. public function actionImportOrderStandard() {
  597. $orderMonth = \Yii::$app->request->post('orderMonth');
  598. $excelOrderStandard = new ExcelOrderStandardForm();
  599. $finishStatus = $excelOrderStandard->finished($orderMonth);
  600. if ($finishStatus) {
  601. return static::notice(['finish' => true]);
  602. } else {
  603. return static::notice('状态更新错误', 400);
  604. }
  605. }
  606. /**
  607. * 管理员发货
  608. * @return mixed
  609. * @throws \yii\web\HttpException
  610. */
  611. public function actionOrderDelivery() {
  612. if(\Yii::$app->request->isPost) {
  613. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  614. }
  615. return static::notice('非法请求', 400);
  616. }
  617. }