ShopController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. 'STORE_NUMS'=>'DP.STORE_NUMS'
  204. ]);
  205. $condition = $filter['condition'];
  206. $params = $filter['params'];
  207. $condition .= ' AND DP.IS_DEL=0';
  208. $listObj = new PackageList();
  209. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  210. return static::notice($data);
  211. }
  212. /**
  213. * 添加报单套餐
  214. * @return mixed
  215. * @throws \yii\web\HttpException
  216. */
  217. public function actionPackageAdd() {
  218. if (\Yii::$app->request->isPost) {
  219. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  220. // Log::adminHandle('添加报单套餐', 1);
  221. });
  222. }
  223. return static::notice('非发请求', 405);
  224. }
  225. /**
  226. * 报单套餐获取
  227. * @return mixed
  228. * @throws \yii\web\HttpException
  229. */
  230. public function actionPackageGet() {
  231. $id = \Yii::$app->request->get('id');
  232. if (\Yii::$app->request->isPost) {
  233. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  234. // Log::adminHandle('编辑报单套餐', 1);
  235. });
  236. }
  237. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  238. 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']]);
  239. }
  240. /**
  241. * 套餐上下架
  242. * @return mixed
  243. * @throws Exception
  244. */
  245. public function actionPackageStatus() {
  246. $id = \Yii::$app->request->get('id');
  247. if (\Yii::$app->request->isPost) {
  248. $formModel = new DecPackageForm();
  249. $formModel->scenario = 'changeStatus';
  250. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  251. return static::notice('状态设置成功');
  252. } else {
  253. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  254. }
  255. }
  256. }
  257. /**
  258. * 删除套餐
  259. * @return mixed
  260. * @throws \yii\db\Exception
  261. * @throws \yii\web\HttpException
  262. */
  263. public function actionPackageDelete(){
  264. $result = static::delete(DeclarationPackage::class);
  265. return $result;
  266. }
  267. /**
  268. * 报单表
  269. * @return mixed
  270. * @throws Exception
  271. * @throws \yii\web\HttpException
  272. */
  273. public function actionDecOrderList() {
  274. $filter = $this->filterCondition([
  275. 'DEC_SN'=> 'DO.DEC_SN',
  276. 'ORDER_SN'=> 'DO.ORDER_SN',
  277. 'USER_NAME'=> 'U.USER_NAME',
  278. 'TO_USER_NAME'=> 'TU.USER_NAME',
  279. 'REAL_NAME'=> 'TU.REAL_NAME',
  280. 'ID_CARD'=> 'TU.ID_CARD',
  281. 'MOBILE'=> 'TU.MOBILE',
  282. 'DEC_LV_NAME' => 'TU.DEC_LV',
  283. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  284. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  285. 'DEC_PV'=> 'DO.DEC_PV',
  286. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  287. 'REC_USER_NAME'=> 'RU.USER_NAME',
  288. 'CREATED_AT'=> 'DO.CREATED_AT',
  289. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  290. ]);
  291. $condition = $filter['condition'];
  292. $params = $filter['params'];
  293. $condition .= ' AND DO.IS_DEL=0';
  294. $listObj = new DecOrderList();
  295. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  296. return static::notice($data);
  297. }
  298. /**
  299. * 报单表导出
  300. * @return mixed
  301. * @throws \yii\db\Exception
  302. * @throws \yii\web\HttpException
  303. */
  304. public function actionDecOrderListExport()
  305. {
  306. $filter = $this->filterCondition([
  307. 'DEC_SN'=> 'DO.DEC_SN',
  308. 'ORDER_SN'=> 'DO.ORDER_SN',
  309. 'USER_NAME'=> 'U.USER_NAME',
  310. 'TO_USER_NAME'=> 'TU.USER_NAME',
  311. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  312. 'DEC_PV'=> 'DO.DEC_PV',
  313. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  314. 'CREATED_AT'=> 'DO.CREATED_AT',
  315. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  316. ]);
  317. $filter['condition'] .= ' AND DO.IS_DEL=0';
  318. $form = new ShopExportForm();
  319. $result = $form->run($filter, '报单列表');
  320. if (!$result) {
  321. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  322. }
  323. return static::notice('导出开始,请到文件管理-导出文件查看');
  324. }
  325. /**
  326. * 订单表
  327. * @return mixed
  328. * @throws Exception
  329. * @throws \yii\web\HttpException
  330. */
  331. public function actionOrderList() {
  332. $filter = $this->filterCondition([
  333. 'SN'=> 'O.SN',
  334. 'USER_NAME'=> 'U.USER_NAME',
  335. 'MOBILE'=> 'O.MOBILE',
  336. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  337. 'CREATED_AT'=> 'O.CREATED_AT',
  338. ]);
  339. $condition = $filter['condition'];
  340. $params = $filter['params'];
  341. $condition .= ' AND O.IS_DELETE=0';
  342. $listObj = new OrderList();
  343. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  344. return static::notice($data);
  345. }
  346. /**
  347. * 订单表导出
  348. * @return mixed
  349. * @throws \yii\db\Exception
  350. * @throws \yii\web\HttpException
  351. */
  352. public function actionOrderListExport()
  353. {
  354. $filter = $this->filterCondition([
  355. 'SN'=> 'O.SN',
  356. 'USER_NAME'=> 'U.USER_NAME',
  357. 'MOBILE'=> 'O.MOBILE',
  358. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  359. 'CREATED_AT'=> 'O.CREATED_AT',
  360. ]);
  361. $filter['condition'] .= ' AND O.IS_DELETE=0';
  362. $form = new ShopExportForm();
  363. $result = $form->run($filter, '订单列表');
  364. if (!$result) {
  365. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  366. }
  367. return static::notice('导出开始,请到文件管理-导出文件查看');
  368. }
  369. /**
  370. * 外部商城订单列表
  371. * @return mixed
  372. * @throws Exception
  373. * @throws \yii\web\HttpException
  374. */
  375. public function actionOrderShopList() {
  376. $filter = $this->filterCondition([
  377. 'SN'=> 'O.SN',
  378. 'USER_NAME'=> 'U.USER_NAME',
  379. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  380. 'CREATED_AT'=> 'O.CREATED_AT',
  381. ]);
  382. $condition = $filter['condition'];
  383. $params = $filter['params'];
  384. $condition .= ' AND O.IS_DELETE=0';
  385. $listObj = new OrderShopList();
  386. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  387. return static::notice($data);
  388. }
  389. /**
  390. * 外部商城报单列表
  391. * @return mixed
  392. * @throws Exception
  393. * @throws \yii\web\HttpException
  394. */
  395. public function actionOrderDecList() {
  396. $filter = $this->filterCondition([
  397. 'SN'=> 'O.SN',
  398. 'USER_NAME'=> 'U.USER_NAME',
  399. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  400. 'CREATED_AT'=> 'O.CREATED_AT',
  401. ]);
  402. $condition = $filter['condition'];
  403. $params = $filter['params'];
  404. $condition .= ' AND O.IS_DELETE=0';
  405. $listObj = new OrderDecList();
  406. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  407. return static::notice($data);
  408. }
  409. /**
  410. * 分页导入excel文件到待导入数据的表中
  411. * @return mixed
  412. */
  413. public function actionImportOrderShopToExcelTable()
  414. {
  415. // 先上传到服务器文件
  416. if (\Yii::$app->request->isPost) {
  417. $excelImportId = \Yii::$app->request->post('excelImportId');
  418. $rowCount = \Yii::$app->request->post('rowCount');
  419. //$periodNum = \Yii::$app->request->post('periodNum');
  420. $orderDay = \Yii::$app->request->post('orderDay');
  421. $orderType = \Yii::$app->request->post('orderType');
  422. $startRow = \Yii::$app->request->post('startRow');
  423. $limit = \Yii::$app->request->post('limit', 1000);
  424. $errorMsg = '';
  425. try {
  426. if( $startRow == 1 ) {
  427. $excelOrderShop = new ExcelOrderShopForm();
  428. $excelOrderShop->checkStatus($orderDay,$orderType);
  429. }
  430. $excel = new \common\helpers\Excel();
  431. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  432. } catch (\Exception $e) {
  433. $result = false;
  434. $errorMsg = $e->getMessage();
  435. }
  436. // 还有数据
  437. if ($result === 1) {
  438. return static::notice(['finish' => false]);
  439. } elseif ($result === 0) {
  440. return static::notice(['finish' => true]);
  441. } else {
  442. return static::notice('发生错误:' . $errorMsg, 400);
  443. }
  444. }
  445. }
  446. /**
  447. * 导入完成标记
  448. * @return mixed
  449. * @throws \yii\web\HttpException
  450. */
  451. public function actionImportOrderShop() {
  452. //$periodNum = \Yii::$app->request->post('periodNum');
  453. $orderDay = \Yii::$app->request->post('orderDay');
  454. $orderType = \Yii::$app->request->post('orderType');
  455. $excelOrderShop = new ExcelOrderShopForm();
  456. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  457. if ($finishStatus) {
  458. return static::notice(['finish' => true]);
  459. } else {
  460. return static::notice('状态更新错误', 400);
  461. }
  462. }
  463. /**
  464. * 报单订单——分页导入excel文件到待导入数据的表中
  465. * @return mixed
  466. */
  467. public function actionImportOrderDecToExcelTable()
  468. {
  469. // 先上传到服务器文件
  470. if (\Yii::$app->request->isPost) {
  471. $excelImportId = \Yii::$app->request->post('excelImportId');
  472. $rowCount = \Yii::$app->request->post('rowCount');
  473. //$periodNum = \Yii::$app->request->post('periodNum');
  474. $orderDay = \Yii::$app->request->post('orderDay');
  475. $startRow = \Yii::$app->request->post('startRow');
  476. $limit = \Yii::$app->request->post('limit', 1000);
  477. $errorMsg = '';
  478. try {
  479. if( $startRow == 1 ) {
  480. $excelOrderShop = new ExcelOrderDecForm();
  481. $excelOrderShop->checkStatus($orderDay);
  482. }
  483. $excel = new \common\helpers\Excel();
  484. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  485. } catch (\Exception $e) {
  486. $result = false;
  487. $errorMsg = $e->getMessage();
  488. }
  489. // 还有数据
  490. if ($result === 1) {
  491. return static::notice(['finish' => false]);
  492. } elseif ($result === 0) {
  493. return static::notice(['finish' => true]);
  494. } else {
  495. return static::notice('发生错误:' . $errorMsg, 400);
  496. }
  497. }
  498. }
  499. /**
  500. * 报单订单导入完成标记
  501. * @return mixed
  502. * @throws \yii\web\HttpException
  503. */
  504. public function actionImportOrderDec() {
  505. //$periodNum = \Yii::$app->request->post('periodNum');
  506. $orderDay = \Yii::$app->request->post('orderDay');
  507. $excelOrderShop = new ExcelOrderDecForm();
  508. $finishStatus = $excelOrderShop->finished($orderDay);
  509. if ($finishStatus) {
  510. return static::notice(['finish' => true]);
  511. } else {
  512. return static::notice('状态更新错误', 400);
  513. }
  514. }
  515. /**
  516. * 见习达标订单列表
  517. * @return mixed
  518. * @throws Exception
  519. * @throws \yii\web\HttpException
  520. */
  521. public function actionOrderStandardList() {
  522. $filter = $this->filterCondition([
  523. 'SN'=> 'O.SN',
  524. 'USER_NAME'=> 'U.USER_NAME',
  525. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  526. 'CREATED_AT'=> 'O.CREATED_AT',
  527. ]);
  528. $condition = $filter['condition'];
  529. $params = $filter['params'];
  530. $condition .= ' AND O.IS_DELETE=0';
  531. $listObj = new OrderStandardList();
  532. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  533. return static::notice($data);
  534. }
  535. /**
  536. * 分页导入excel文件到待导入数据的表中
  537. * @return mixed
  538. * @throws \yii\web\HttpException
  539. */
  540. public function actionImportOrderStandardToExcelTable()
  541. {
  542. // 先上传到服务器文件
  543. if (\Yii::$app->request->isPost) {
  544. $excelImportId = \Yii::$app->request->post('excelImportId');
  545. $rowCount = \Yii::$app->request->post('rowCount');
  546. //$periodNum = \Yii::$app->request->post('periodNum');
  547. $orderMonth = \Yii::$app->request->post('orderMonth');
  548. // $orderType = \Yii::$app->request->post('orderType');
  549. $orderType = 'cash';
  550. $startRow = \Yii::$app->request->post('startRow');
  551. $limit = \Yii::$app->request->post('limit', 1000);
  552. $errorMsg = '';
  553. try {
  554. if( $startRow == 1 ) {
  555. //清空已经导入的表数据
  556. $excelOrderStandard = new ExcelOrderStandardForm();
  557. $excelOrderStandard->checkStatus($orderMonth);
  558. }
  559. $excel = new \common\helpers\Excel();
  560. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  561. } catch (Exception $e) {
  562. $result = false;
  563. $errorMsg = $e->getMessage();
  564. }
  565. // 还有数据
  566. if ($result === 1) {
  567. return static::notice(['finish' => false]);
  568. } elseif ($result === 0) {
  569. return static::notice(['finish' => true]);
  570. } else {
  571. return static::notice('发生错误:' . $errorMsg, 400);
  572. }
  573. }
  574. }
  575. /**
  576. * 达标订单导入完成标记
  577. * @return mixed
  578. * @throws \yii\web\HttpException
  579. */
  580. public function actionImportOrderStandard() {
  581. $orderMonth = \Yii::$app->request->post('orderMonth');
  582. $excelOrderStandard = new ExcelOrderStandardForm();
  583. $finishStatus = $excelOrderStandard->finished($orderMonth);
  584. if ($finishStatus) {
  585. return static::notice(['finish' => true]);
  586. } else {
  587. return static::notice('状态更新错误', 400);
  588. }
  589. }
  590. /**
  591. * 管理员发货
  592. * @return mixed
  593. * @throws \yii\web\HttpException
  594. */
  595. public function actionOrderDelivery() {
  596. if(\Yii::$app->request->isPost) {
  597. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  598. }
  599. return static::notice('非法请求', 400);
  600. }
  601. }