ShopController.php 25 KB

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