ShopController.php 25 KB

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