ShopController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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\OrderPeriodAdjustList;
  16. use backendApi\modules\v1\models\lists\shop\OrderShopList;
  17. use backendApi\modules\v1\models\lists\shop\OrderStandardList;
  18. use backendApi\modules\v1\models\lists\shop\PackageList;
  19. use common\helpers\bonus\CalcCache;
  20. use backendApi\modules\v1\models\lists\shop\RemainPvList;
  21. use backendApi\modules\v1\models\lists\shop\FlowRemainPvList;
  22. use common\helpers\Cache;
  23. use common\helpers\Date;
  24. use common\helpers\Form;
  25. use common\helpers\Log;
  26. use common\helpers\snowflake\SnowFake;
  27. use common\libs\export\module\ShopExport;
  28. use common\models\DeclarationPackage;
  29. use common\models\DecOrder;
  30. use common\models\ExcelOrderShop;
  31. use common\models\forms\DecPackageForm;
  32. use common\models\forms\ExcelOrderDecForm;
  33. use common\models\forms\ExcelOrderShopForm;
  34. use common\models\forms\ExcelOrderStandardForm;
  35. use common\models\forms\OrderDeleteForm;
  36. use common\models\forms\OrderForm;
  37. use common\models\forms\OrderPeriodAdjustForm;
  38. use common\models\forms\ShopGoodsForm;
  39. use common\models\forms\UploadForm;
  40. use common\models\Order;
  41. use common\models\Period;
  42. use common\models\ShopGoods;
  43. use yii\web\UploadedFile;
  44. use yii\base\Exception;
  45. class ShopController extends BaseController {
  46. public $modelClass = DecOrder::class;
  47. public function behaviors() {
  48. $behaviors = parent::behaviors();
  49. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  50. return $behaviors;
  51. }
  52. /**
  53. * 商品列表
  54. * @return mixed
  55. * @throws Exception
  56. * @throws \yii\web\HttpException
  57. */
  58. public function actionIndex() {
  59. $filter = $this->filterCondition([
  60. 'TYPE'=> 'TYPE',
  61. 'GIFT_TYPE'=> 'GIFT_TYPE',
  62. 'STATUS'=> 'STATUS',
  63. 'GOODS_NAME'=> 'GOODS_NAME',
  64. 'GOODS_NO'=> 'GOODS_NO',
  65. 'SELL_TYPE'=> 'SELL_TYPE',
  66. 'SELL_PRICE'=> 'SELL_PRICE',
  67. 'PRICE_PV'=> 'PRICE_PV',
  68. ]);
  69. $condition = $filter['condition'];
  70. $params = $filter['params'];
  71. $condition .= ' ';
  72. $listObj = new GoodsList();
  73. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  74. return static::notice($data);
  75. }
  76. /**
  77. * 商品列表导出
  78. * @return mixed
  79. * @throws \yii\db\Exception
  80. * @throws \yii\web\HttpException
  81. */
  82. public function actionGoodsListExport()
  83. {
  84. $filter = $this->filterCondition([
  85. 'TYPE'=> 'TYPE',
  86. 'GIFT_TYPE'=> 'GIFT_TYPE',
  87. 'STATUS'=> 'STATUS',
  88. 'GOODS_NAME'=> 'GOODS_NAME',
  89. 'GOODS_NO'=> 'GOODS_NO',
  90. 'SELL_TYPE'=> 'SELL_TYPE',
  91. 'SELL_PRICE'=> 'SELL_PRICE',
  92. 'PRICE_PV'=> 'PRICE_PV',
  93. ]);
  94. $form = new ShopExportForm();
  95. $result = $form->run($filter, '商品列表');
  96. if (!$result) {
  97. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  98. }
  99. return static::notice('导出开始,请到文件管理-导出文件查看');
  100. }
  101. /**
  102. * 添加商品
  103. * @return mixed
  104. * @throws Exception
  105. * @throws \yii\web\HttpException
  106. */
  107. public function actionGoodsAdd() {
  108. if (\Yii::$app->request->isPost) {
  109. $formModel = new ShopGoodsForm();
  110. $formModel->scenario = 'add';
  111. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  112. return static::notice('商品添加成功');
  113. } else {
  114. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  115. }
  116. }
  117. return static::notice(['sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  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. return static::notice(['goodsInfo'=>$data,'sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  141. }
  142. /**
  143. * 上传图片
  144. * @return mixed
  145. * @throws \yii\base\Exception
  146. * @throws \yii\db\Exception
  147. * @throws \yii\web\HttpException
  148. */
  149. public function actionUpload(){
  150. if(\Yii::$app->request->isPost){
  151. $formModel = new UploadForm();
  152. $formModel->scenario = 'goodsImg';
  153. $formModel->file = UploadedFile::getInstanceByName('file');
  154. $formModel->token = \Yii::$app->request->request('uploadToken');
  155. if($formModel->file && $uploader = $formModel->upload()){
  156. return static::notice($uploader->URL);
  157. } else {
  158. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  159. }
  160. } else {
  161. $token = Cache::setUploadToken();
  162. return static::notice($token);
  163. }
  164. }
  165. /**
  166. * 商品上下架
  167. * @return mixed
  168. * @throws Exception
  169. */
  170. public function actionGoodsStatus() {
  171. $id = \Yii::$app->request->get('id');
  172. if (\Yii::$app->request->isPost) {
  173. $formModel = new ShopGoodsForm();
  174. $formModel->scenario = 'changeStatus';
  175. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  176. // foreach ($result['logs'] as $k => $value) {
  177. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  178. // }
  179. return static::notice('状态设置成功');
  180. } else {
  181. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  182. }
  183. }
  184. }
  185. /**
  186. * 删除商品
  187. * @return mixed
  188. * @throws \yii\db\Exception
  189. * @throws \yii\web\HttpException
  190. */
  191. public function actionGoodsDelete(){
  192. $result = static::delete(ShopGoods::class);
  193. return $result;
  194. }
  195. /**
  196. * 套餐列表
  197. * @return mixed
  198. * @throws Exception
  199. * @throws \yii\web\HttpException
  200. */
  201. public function actionPackage() {
  202. $filter = $this->filterCondition([
  203. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  204. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  205. 'AMOUNT'=> 'DP.AMOUNT',
  206. 'PV'=> 'DP.PV',
  207. 'STATUS'=> 'DP.STATUS',
  208. 'STORE_NUMS'=>'DP.STORE_NUMS',
  209. 'STATUS_DATE'=>'DP.STATUS_DATE',
  210. 'PACKAGE_DATE'=>'DP.PACKAGE_DATE',
  211. 'PACKAGE_STATUS_DATE'=>'DP.PACKAGE_STATUS_DATE'
  212. ]);
  213. $condition = $filter['condition'];
  214. $params = $filter['params'];
  215. $condition .= ' AND DP.IS_DEL=0';
  216. $listObj = new PackageList();
  217. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  218. return static::notice($data);
  219. }
  220. /**
  221. * 添加报单套餐
  222. * @return mixed
  223. * @throws \yii\web\HttpException
  224. */
  225. public function actionPackageAdd() {
  226. if (\Yii::$app->request->isPost) {
  227. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  228. // Log::adminHandle('添加报单套餐', 1);
  229. });
  230. }
  231. return static::notice('非发请求', 405);
  232. }
  233. /**
  234. * 报单套餐获取
  235. * @return mixed
  236. * @throws \yii\web\HttpException
  237. */
  238. public function actionPackageGet() {
  239. $id = \Yii::$app->request->get('id');
  240. if (\Yii::$app->request->isPost) {
  241. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  242. // Log::adminHandle('编辑报单套餐', 1);
  243. });
  244. }
  245. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  246. 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'],'sort'=>$package['SORT']]);
  247. }
  248. /**
  249. * 套餐上下架
  250. * @return mixed
  251. * @throws Exception
  252. */
  253. public function actionPackageStatus() {
  254. $id = \Yii::$app->request->get('id');
  255. if (\Yii::$app->request->isPost) {
  256. $formModel = new DecPackageForm();
  257. $formModel->scenario = 'changeStatus';
  258. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  259. return static::notice('状态设置成功');
  260. } else {
  261. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  262. }
  263. }
  264. }
  265. /**
  266. * 删除套餐
  267. * @return mixed
  268. * @throws \yii\db\Exception
  269. * @throws \yii\web\HttpException
  270. */
  271. public function actionPackageDelete(){
  272. $result = static::delete(DeclarationPackage::class);
  273. return $result;
  274. }
  275. /**
  276. * 报单表
  277. * @return mixed
  278. * @throws Exception
  279. * @throws \yii\web\HttpException
  280. */
  281. public function actionDecOrderList() {
  282. $filter = $this->filterCondition([
  283. 'DEC_SN'=> 'DO.DEC_SN',
  284. 'ORDER_SN'=> 'DO.ORDER_SN',
  285. 'USER_NAME'=> 'U.USER_NAME',
  286. 'TO_USER_NAME'=> 'TU.USER_NAME',
  287. 'REAL_NAME'=> 'TU.REAL_NAME',
  288. 'ID_CARD'=> 'TU.ID_CARD',
  289. 'MOBILE'=> 'TU.MOBILE',
  290. 'DEC_LV_NAME' => 'TU.DEC_LV',
  291. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  292. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  293. 'DEC_PV'=> 'DO.DEC_PV',
  294. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  295. 'REC_USER_NAME'=> 'RU.USER_NAME',
  296. 'CREATED_AT'=> 'DO.CREATED_AT',
  297. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  298. ]);
  299. $condition = $filter['condition'];
  300. $params = $filter['params'];
  301. $condition .= ' AND DO.IS_DEL=0';
  302. $listObj = new DecOrderList();
  303. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  304. return static::notice($data);
  305. }
  306. /**
  307. * 报单表导出
  308. * @return mixed
  309. * @throws \yii\db\Exception
  310. * @throws \yii\web\HttpException
  311. */
  312. public function actionDecOrderListExport()
  313. {
  314. $filter = $this->filterCondition([
  315. 'DEC_SN'=> 'DO.DEC_SN',
  316. 'ORDER_SN'=> 'DO.ORDER_SN',
  317. 'USER_NAME'=> 'U.USER_NAME',
  318. 'TO_USER_NAME'=> 'TU.USER_NAME',
  319. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  320. 'DEC_PV'=> 'DO.DEC_PV',
  321. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  322. 'CREATED_AT'=> 'DO.CREATED_AT',
  323. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  324. ]);
  325. $filter['condition'] .= ' AND DO.IS_DEL=0';
  326. $form = new ShopExportForm();
  327. $result = $form->run($filter, '报单列表');
  328. if (!$result) {
  329. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  330. }
  331. return static::notice('导出开始,请到文件管理-导出文件查看');
  332. }
  333. /**
  334. * 订单表
  335. * @return mixed
  336. * @throws Exception
  337. * @throws \yii\web\HttpException
  338. */
  339. public function actionOrderList() {
  340. $filter = $this->filterCondition([
  341. 'SN'=> 'O.SN',
  342. 'USER_NAME'=> 'U.USER_NAME',
  343. 'MOBILE'=> 'O.MOBILE',
  344. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  345. 'CREATED_AT'=> 'O.CREATED_AT',
  346. ]);
  347. // $condition = ' 1=1 ' . $filter['condition'];
  348. // $params = $filter['params'];
  349. // $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  350. $condition = $filter['condition'];
  351. $params = $filter['params'];
  352. $condition .= ' AND O.IS_DELETE=0';
  353. $listObj = new OrderList();
  354. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  355. return static::notice($data);
  356. }
  357. // 删除订单
  358. public function actionDeleteOrder() {
  359. if (\Yii::$app->request->isPost) {
  360. $formModel = new OrderDeleteForm();
  361. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  362. return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
  363. } else {
  364. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  365. }
  366. }
  367. }
  368. /**
  369. * 订单表导出
  370. * @return mixed
  371. * @throws \yii\db\Exception
  372. * @throws \yii\web\HttpException
  373. */
  374. public function actionOrderListExport()
  375. {
  376. $filter = $this->filterCondition([
  377. 'SN'=> 'O.SN',
  378. 'USER_NAME'=> 'U.USER_NAME',
  379. 'MOBILE'=> 'O.MOBILE',
  380. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  381. 'CREATED_AT'=> 'O.CREATED_AT',
  382. ]);
  383. // $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  384. $condition = $filter['condition'];
  385. $params = $filter['params'];
  386. $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. * 剩余BV页
  628. *
  629. */
  630. public function actionRemainPv()
  631. {
  632. $filter = $this->filterCondition([
  633. 'USER_NAME' => 'U.USER_NAME',
  634. ]);
  635. $condition = $filter['condition'];
  636. $params = $filter['params'];
  637. $listObj = new RemainPvList();
  638. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  639. return static::notice($data);
  640. }
  641. /*
  642. * 剩余BV流水
  643. *
  644. */
  645. public function actionFlowRemainPv()
  646. {
  647. $filter = $this->filterCondition([
  648. 'USER_NAME' => 'U.USER_NAME',
  649. ]);
  650. $condition = $filter['condition'];
  651. $params = $filter['params'];
  652. $listObj = new FlowRemainPvList();
  653. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  654. return static::notice($data);
  655. }
  656. /**
  657. * 订单详情
  658. * @return mixed
  659. * @throws \yii\web\HttpException
  660. */
  661. public function actionOrderDetail()
  662. {
  663. $orderSn = \Yii::$app->request->get('orderSn');
  664. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  665. if (!$order) {
  666. return static::notice('订单不存在', 400);
  667. }
  668. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? '首单' : '复消';
  669. // 如果当前订单所在期数已挂网,则不可调整
  670. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  671. if (!$period) {
  672. return static::notice('期数无效', 400);
  673. }
  674. if ($period['IS_SENT'] > 0) {
  675. return static::notice('订单已挂网', 400);
  676. }
  677. // 根据订单期数查询可调整期数
  678. $availablePeriod = [];
  679. if ($order['PERIOD_NUM']) {
  680. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  681. foreach ($availablePeriod as $k => $item) {
  682. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  683. }
  684. }
  685. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  686. }
  687. /**
  688. * 期数检查
  689. * @return mixed
  690. * @throws \yii\web\HttpException
  691. */
  692. public function actionPeriodInspect()
  693. {
  694. $modernPeriod = \Yii::$app->request->get('modernPeriod');
  695. $period = Period::getInfoByPeriodNum($modernPeriod);
  696. if (!$period) {
  697. return static::notice('期数不存在', 400);
  698. }
  699. if ($period['IS_SENT'] > 0) {
  700. return static::notice('调整后的期数已未挂网', 400);
  701. }
  702. }
  703. /**
  704. * 调整订单期数
  705. * @return mixed
  706. * @throws Exception
  707. * @throws \yii\db\Exception
  708. * @throws \yii\web\HttpException
  709. */
  710. public function actionOrderPeriodAdjust()
  711. {
  712. if (\Yii::$app->request->isPost) {
  713. $formModel = new OrderPeriodAdjustForm();
  714. $formModel->scenario = 'orderPeriodAdjust';
  715. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  716. return static::notice('成功');
  717. } else {
  718. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  719. }
  720. } else {
  721. $filter = $this->filterCondition([
  722. 'ORDER_SN' => 'P.ORDER_SN',
  723. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  724. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  725. 'CREATED_AT'=> 'P.CREATED_AT',
  726. ]);
  727. $listObj = new OrderPeriodAdjustList();
  728. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  729. return static::notice($data);
  730. }
  731. }
  732. }