ShopController.php 23 KB

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