ShopController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. ]);
  366. $condition = $filter['condition'];
  367. $params = $filter['params'];
  368. $condition .= ' AND O.IS_DELETE=0';
  369. $listObj = new OrderList();
  370. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  371. return static::notice($data);
  372. }
  373. /**
  374. * 订单表导出
  375. * @return mixed
  376. * @throws \yii\db\Exception
  377. * @throws \yii\web\HttpException
  378. */
  379. public function actionOrderListExport()
  380. {
  381. $filter = $this->filterCondition([
  382. 'SN'=> 'O.SN',
  383. 'USER_NAME'=> 'U.USER_NAME',
  384. 'MOBILE'=> 'O.MOBILE',
  385. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  386. 'CREATED_AT'=> 'O.CREATED_AT',
  387. ]);
  388. $filter['condition'] .= ' AND O.IS_DELETE=0';
  389. $form = new ShopExportForm();
  390. $result = $form->run($filter, '订单列表');
  391. if (!$result) {
  392. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  393. }
  394. return static::notice('导出开始,请到文件管理-导出文件查看');
  395. }
  396. /**
  397. * 外部商城订单列表
  398. * @return mixed
  399. * @throws Exception
  400. * @throws \yii\web\HttpException
  401. */
  402. public function actionOrderShopList() {
  403. $filter = $this->filterCondition([
  404. 'SN'=> 'O.SN',
  405. 'USER_NAME'=> 'U.USER_NAME',
  406. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  407. 'CREATED_AT'=> 'O.CREATED_AT',
  408. ]);
  409. $condition = $filter['condition'];
  410. $params = $filter['params'];
  411. $condition .= ' AND O.IS_DELETE=0';
  412. $listObj = new OrderShopList();
  413. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  414. return static::notice($data);
  415. }
  416. /**
  417. * 外部商城报单列表
  418. * @return mixed
  419. * @throws Exception
  420. * @throws \yii\web\HttpException
  421. */
  422. public function actionOrderDecList() {
  423. $filter = $this->filterCondition([
  424. 'SN'=> 'O.SN',
  425. 'USER_NAME'=> 'U.USER_NAME',
  426. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  427. 'CREATED_AT'=> 'O.CREATED_AT',
  428. ]);
  429. $condition = $filter['condition'];
  430. $params = $filter['params'];
  431. $condition .= ' AND O.IS_DELETE=0';
  432. $listObj = new OrderDecList();
  433. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  434. return static::notice($data);
  435. }
  436. /**
  437. * 分页导入excel文件到待导入数据的表中
  438. * @return mixed
  439. */
  440. public function actionImportOrderShopToExcelTable()
  441. {
  442. // 先上传到服务器文件
  443. if (\Yii::$app->request->isPost) {
  444. $excelImportId = \Yii::$app->request->post('excelImportId');
  445. $rowCount = \Yii::$app->request->post('rowCount');
  446. //$periodNum = \Yii::$app->request->post('periodNum');
  447. $orderDay = \Yii::$app->request->post('orderDay');
  448. $orderType = \Yii::$app->request->post('orderType');
  449. $startRow = \Yii::$app->request->post('startRow');
  450. $limit = \Yii::$app->request->post('limit', 1000);
  451. $errorMsg = '';
  452. try {
  453. if( $startRow == 1 ) {
  454. $excelOrderShop = new ExcelOrderShopForm();
  455. $excelOrderShop->checkStatus($orderDay,$orderType);
  456. }
  457. $excel = new \common\helpers\Excel();
  458. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  459. } catch (\Exception $e) {
  460. $result = false;
  461. $errorMsg = $e->getMessage();
  462. }
  463. // 还有数据
  464. if ($result === 1) {
  465. return static::notice(['finish' => false]);
  466. } elseif ($result === 0) {
  467. return static::notice(['finish' => true]);
  468. } else {
  469. return static::notice('发生错误:' . $errorMsg, 400);
  470. }
  471. }
  472. }
  473. /**
  474. * 导入完成标记
  475. * @return mixed
  476. * @throws \yii\web\HttpException
  477. */
  478. public function actionImportOrderShop() {
  479. //$periodNum = \Yii::$app->request->post('periodNum');
  480. $orderDay = \Yii::$app->request->post('orderDay');
  481. $orderType = \Yii::$app->request->post('orderType');
  482. $excelOrderShop = new ExcelOrderShopForm();
  483. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  484. if ($finishStatus) {
  485. return static::notice(['finish' => true]);
  486. } else {
  487. return static::notice('状态更新错误', 400);
  488. }
  489. }
  490. /**
  491. * 报单订单——分页导入excel文件到待导入数据的表中
  492. * @return mixed
  493. */
  494. public function actionImportOrderDecToExcelTable()
  495. {
  496. // 先上传到服务器文件
  497. if (\Yii::$app->request->isPost) {
  498. $excelImportId = \Yii::$app->request->post('excelImportId');
  499. $rowCount = \Yii::$app->request->post('rowCount');
  500. //$periodNum = \Yii::$app->request->post('periodNum');
  501. $orderDay = \Yii::$app->request->post('orderDay');
  502. $startRow = \Yii::$app->request->post('startRow');
  503. $limit = \Yii::$app->request->post('limit', 1000);
  504. $errorMsg = '';
  505. try {
  506. if( $startRow == 1 ) {
  507. $excelOrderShop = new ExcelOrderDecForm();
  508. $excelOrderShop->checkStatus($orderDay);
  509. }
  510. $excel = new \common\helpers\Excel();
  511. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  512. } catch (\Exception $e) {
  513. $result = false;
  514. $errorMsg = $e->getMessage();
  515. }
  516. // 还有数据
  517. if ($result === 1) {
  518. return static::notice(['finish' => false]);
  519. } elseif ($result === 0) {
  520. return static::notice(['finish' => true]);
  521. } else {
  522. return static::notice('发生错误:' . $errorMsg, 400);
  523. }
  524. }
  525. }
  526. /**
  527. * 报单订单导入完成标记
  528. * @return mixed
  529. * @throws \yii\web\HttpException
  530. */
  531. public function actionImportOrderDec() {
  532. //$periodNum = \Yii::$app->request->post('periodNum');
  533. $orderDay = \Yii::$app->request->post('orderDay');
  534. $excelOrderShop = new ExcelOrderDecForm();
  535. $finishStatus = $excelOrderShop->finished($orderDay);
  536. if ($finishStatus) {
  537. return static::notice(['finish' => true]);
  538. } else {
  539. return static::notice('状态更新错误', 400);
  540. }
  541. }
  542. /**
  543. * 见习达标订单列表
  544. * @return mixed
  545. * @throws Exception
  546. * @throws \yii\web\HttpException
  547. */
  548. public function actionOrderStandardList() {
  549. $filter = $this->filterCondition([
  550. 'SN'=> 'O.SN',
  551. 'USER_NAME'=> 'U.USER_NAME',
  552. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  553. 'CREATED_AT'=> 'O.CREATED_AT',
  554. ]);
  555. $condition = $filter['condition'];
  556. $params = $filter['params'];
  557. $condition .= ' AND O.IS_DELETE=0';
  558. $listObj = new OrderStandardList();
  559. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  560. return static::notice($data);
  561. }
  562. /**
  563. * 分页导入excel文件到待导入数据的表中
  564. * @return mixed
  565. * @throws \yii\web\HttpException
  566. */
  567. public function actionImportOrderStandardToExcelTable()
  568. {
  569. // 先上传到服务器文件
  570. if (\Yii::$app->request->isPost) {
  571. $excelImportId = \Yii::$app->request->post('excelImportId');
  572. $rowCount = \Yii::$app->request->post('rowCount');
  573. //$periodNum = \Yii::$app->request->post('periodNum');
  574. $orderMonth = \Yii::$app->request->post('orderMonth');
  575. // $orderType = \Yii::$app->request->post('orderType');
  576. $orderType = 'cash';
  577. $startRow = \Yii::$app->request->post('startRow');
  578. $limit = \Yii::$app->request->post('limit', 1000);
  579. $errorMsg = '';
  580. try {
  581. if( $startRow == 1 ) {
  582. //清空已经导入的表数据
  583. $excelOrderStandard = new ExcelOrderStandardForm();
  584. $excelOrderStandard->checkStatus($orderMonth);
  585. }
  586. $excel = new \common\helpers\Excel();
  587. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  588. } catch (Exception $e) {
  589. $result = false;
  590. $errorMsg = $e->getMessage();
  591. }
  592. // 还有数据
  593. if ($result === 1) {
  594. return static::notice(['finish' => false]);
  595. } elseif ($result === 0) {
  596. return static::notice(['finish' => true]);
  597. } else {
  598. return static::notice('发生错误:' . $errorMsg, 400);
  599. }
  600. }
  601. }
  602. /**
  603. * 达标订单导入完成标记
  604. * @return mixed
  605. * @throws \yii\web\HttpException
  606. */
  607. public function actionImportOrderStandard() {
  608. $orderMonth = \Yii::$app->request->post('orderMonth');
  609. $excelOrderStandard = new ExcelOrderStandardForm();
  610. $finishStatus = $excelOrderStandard->finished($orderMonth);
  611. if ($finishStatus) {
  612. return static::notice(['finish' => true]);
  613. } else {
  614. return static::notice('状态更新错误', 400);
  615. }
  616. }
  617. /**
  618. * 管理员发货
  619. * @return mixed
  620. * @throws \yii\web\HttpException
  621. */
  622. public function actionOrderDelivery() {
  623. if(\Yii::$app->request->isPost) {
  624. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  625. }
  626. return static::notice('非法请求', 400);
  627. }
  628. /**
  629. * 报单表导出
  630. * @return mixed
  631. * @throws \yii\db\Exception
  632. * @throws \yii\web\HttpException
  633. */
  634. public function actionOrderListExportPdf()
  635. {
  636. $orderSn = \Yii::$app->request->get('orderSn');
  637. $filter = $this->filterCondition([
  638. 'SN'=> 'O.SN',
  639. 'USER_NAME'=> 'U.USER_NAME',
  640. 'MOBILE'=> 'O.MOBILE',
  641. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  642. 'CREATED_AT'=> 'O.CREATED_AT',
  643. ]);
  644. $filter['condition'] = ' AND O.IS_DELETE=0 AND O.SN=:SN';
  645. $filter['params'] = [':SN' => $orderSn];
  646. $form = new ShopExportForm();
  647. $result = $form->run($filter, '订单列表');
  648. if (!$result) {
  649. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  650. }
  651. return static::notice('导出开始,请到文件管理-导出文件查看');
  652. }
  653. /**
  654. * 报单表导出
  655. * @return mixed
  656. * @throws \yii\db\Exception
  657. * @throws \yii\web\HttpException
  658. */
  659. public function actionDecOrderListExportPdf()
  660. {
  661. $orderSn = \Yii::$app->request->get('orderSn');
  662. $filter = $this->filterCondition([
  663. 'SN'=> 'O.SN',
  664. 'USER_NAME'=> 'U.USER_NAME',
  665. 'MOBILE'=> 'O.MOBILE',
  666. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  667. 'CREATED_AT'=> 'O.CREATED_AT',
  668. ]);
  669. $filter['condition'] = ' AND O.IS_DELETE=0 AND O.SN=:SN';
  670. $filter['params'] = [':SN' => $orderSn];
  671. $form = new ShopExportForm();
  672. $result = $form->run($filter, '订单列表');
  673. if (!$result) {
  674. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  675. }
  676. return static::notice('导出开始,请到文件管理-导出文件查看');
  677. }
  678. /**
  679. * 管理员订单退款
  680. * @return mixed
  681. * @throws \yii\web\HttpException
  682. */
  683. public function actionOrderRefund()
  684. {
  685. if(\Yii::$app->request->isPost) {
  686. return parent::edit(OrderForm::class, '退款成功', 'adminRefund', ['adminRefund']);
  687. }
  688. return static::notice('非法请求', 400);
  689. }
  690. }