ShopController.php 22 KB

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