ShopController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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\BaShopExportForm;
  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\BaOrderList;
  16. use backendApi\modules\v1\models\lists\shop\OrderPeriodAdjustList;
  17. use backendApi\modules\v1\models\lists\shop\OrderShopList;
  18. use backendApi\modules\v1\models\lists\shop\OrderStandardList;
  19. use backendApi\modules\v1\models\lists\shop\PackageList;
  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\Form;
  24. use common\models\DeclarationPackage;
  25. use common\models\DecOrder;
  26. use common\models\forms\DecPackageForm;
  27. use common\models\forms\ExcelOrderDecForm;
  28. use common\models\forms\ExcelOrderShopForm;
  29. use common\models\forms\ExcelOrderStandardForm;
  30. use common\models\forms\OrderDeleteForm;
  31. use common\models\forms\OrderForm;
  32. use common\models\forms\OrderPeriodAdjustForm;
  33. use common\models\forms\ShopGoodsForm;
  34. use common\models\forms\UploadForm;
  35. use common\models\Order;
  36. use common\models\Period;
  37. use common\models\ShopGoods;
  38. use yii\web\HttpException;
  39. use yii\web\UploadedFile;
  40. use yii\base\Exception;
  41. class ShopController extends BaseController {
  42. public $modelClass = DecOrder::class;
  43. public function behaviors() {
  44. $behaviors = parent::behaviors();
  45. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  46. return $behaviors;
  47. }
  48. /**
  49. * 商品列表
  50. * @return mixed
  51. * @throws Exception
  52. * @throws HttpException
  53. */
  54. public function actionIndex() {
  55. $filter = $this->filterCondition([
  56. 'TYPE'=> 'TYPE',
  57. 'GIFT_TYPE'=> 'GIFT_TYPE',
  58. 'STATUS'=> 'STATUS',
  59. 'GOODS_NAME'=> 'GOODS_NAME',
  60. 'GOODS_NO'=> 'GOODS_NO',
  61. 'SELL_TYPE'=> 'SELL_TYPE',
  62. 'SELL_PRICE'=> 'SELL_PRICE',
  63. 'PRICE_PV'=> 'PRICE_PV',
  64. 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
  65. ]);
  66. $condition = $filter['condition'];
  67. $params = $filter['params'];
  68. $condition .= ' ';
  69. $listObj = new GoodsList();
  70. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  71. return static::notice($data);
  72. }
  73. /**
  74. * 商品列表导出
  75. * @return mixed
  76. * @throws \yii\db\Exception
  77. * @throws HttpException
  78. */
  79. public function actionGoodsListExport()
  80. {
  81. $filter = $this->filterCondition([
  82. 'TYPE'=> 'TYPE',
  83. 'GIFT_TYPE'=> 'GIFT_TYPE',
  84. 'STATUS'=> 'STATUS',
  85. 'GOODS_NAME'=> 'GOODS_NAME',
  86. 'GOODS_NO'=> 'GOODS_NO',
  87. 'SELL_TYPE'=> 'SELL_TYPE',
  88. 'SELL_PRICE'=> 'SELL_PRICE',
  89. 'PRICE_PV'=> 'PRICE_PV',
  90. 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
  91. ]);
  92. $form = new ShopExportForm();
  93. $result = $form->run($filter, \Yii::t('ctx', 'shopExportListName')); // 商品列表
  94. if (!$result) {
  95. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  96. }
  97. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  98. }
  99. /**
  100. * 添加商品
  101. * @return mixed
  102. * @throws Exception
  103. * @throws HttpException
  104. */
  105. public function actionGoodsAdd() {
  106. if (\Yii::$app->request->isPost) {
  107. $formModel = new ShopGoodsForm();
  108. $formModel->scenario = 'add';
  109. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  110. return static::notice(\Yii::t('ctx', 'shopProductAddSucceededNotice'));
  111. } else {
  112. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  113. }
  114. }
  115. return static::notice([
  116. 'sellType' => ShopGoods::getSaleType(),
  117. 'goodsType' => ShopGoods::getGoodType(),
  118. 'giftType' => ShopGoods::getGiftType(),//ShopGoods::GIFT_TYPE,
  119. 'categoryType' => ShopGoods::getCategoryType(),//ShopGoods::CATEGORY_TYPE,
  120. ]);
  121. }
  122. /**
  123. * 编辑商品
  124. * @return mixed
  125. * @throws Exception
  126. * @throws HttpException
  127. */
  128. public function actionGoodsEdit() {
  129. $id = \Yii::$app->request->get('id');
  130. if (\Yii::$app->request->isPost) {
  131. $formModel = new ShopGoodsForm();
  132. $formModel->scenario = 'edit';
  133. $formModel->id = $id;
  134. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  135. return static::notice(\Yii::t('ctx', 'shopProductEditSucceed'));
  136. } else {
  137. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  138. }
  139. }
  140. $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
  141. $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
  142. $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
  143. if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
  144. $data['SELL_DISCOUNT'] = ShopGoods::getGoodType()[$data['TYPE']]['discount']/100;
  145. }
  146. return static::notice(
  147. [
  148. 'goodsInfo'=>$data,
  149. 'sellType' => ShopGoods::getSaleType(),
  150. 'goodsType' => ShopGoods::getGoodType(),
  151. 'giftType' => ShopGoods::getGiftType(),//ShopGoods::GIFT_TYPE,
  152. 'categoryType' => ShopGoods::getCategoryType(),//ShopGoods::CATEGORY_TYPE,
  153. ]
  154. );
  155. }
  156. /**
  157. * 上传图片
  158. * @return mixed
  159. * @throws \yii\base\Exception
  160. * @throws \yii\db\Exception
  161. * @throws HttpException
  162. */
  163. public function actionUpload(){
  164. if(\Yii::$app->request->isPost){
  165. $formModel = new UploadForm();
  166. $formModel->scenario = 'goodsImg';
  167. $formModel->file = UploadedFile::getInstanceByName('file');
  168. $formModel->token = \Yii::$app->request->request('uploadToken');
  169. if($formModel->file && $uploader = $formModel->upload()){
  170. return static::notice($uploader->URL);
  171. } else {
  172. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  173. }
  174. } else {
  175. $token = Cache::setUploadToken();
  176. return static::notice($token);
  177. }
  178. }
  179. /**
  180. * 商品上下架
  181. * @return mixed
  182. * @throws Exception
  183. */
  184. public function actionGoodsStatus() {
  185. $id = \Yii::$app->request->get('id');
  186. if (\Yii::$app->request->isPost) {
  187. $formModel = new ShopGoodsForm();
  188. $formModel->scenario = 'changeStatus';
  189. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  190. // foreach ($result['logs'] as $k => $value) {
  191. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  192. // }
  193. return static::notice(\Yii::t('ctx', 'shopStatusSetSucceedNotice')); // 状态设置成功
  194. } else {
  195. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  196. }
  197. }
  198. }
  199. /**
  200. * 删除商品
  201. * @return mixed
  202. * @throws \yii\db\Exception
  203. * @throws HttpException
  204. */
  205. public function actionGoodsDelete(){
  206. $result = static::delete(ShopGoods::class);
  207. return $result;
  208. }
  209. /**
  210. * 套餐列表
  211. * @return mixed
  212. * @throws Exception
  213. * @throws HttpException
  214. */
  215. public function actionPackage() {
  216. $filter = $this->filterCondition([
  217. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  218. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  219. 'AMOUNT'=> 'DP.AMOUNT',
  220. 'PV'=> 'DP.PV',
  221. 'STATUS'=> 'DP.STATUS',
  222. 'STORE_NUMS'=>'DP.STORE_NUMS',
  223. ]);
  224. $condition = $filter['condition'];
  225. $params = $filter['params'];
  226. $condition .= ' AND DP.IS_DEL=0';
  227. $listObj = new PackageList();
  228. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  229. return static::notice($data);
  230. }
  231. /**
  232. * 添加报单套餐
  233. * @return mixed
  234. * @throws HttpException
  235. */
  236. public function actionPackageAdd() {
  237. if (\Yii::$app->request->isPost) {
  238. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  239. // Log::adminHandle('添加报单套餐', 1);
  240. });
  241. }
  242. return static::notice('非发请求', 405);
  243. }
  244. /**
  245. * 报单套餐获取
  246. * @return mixed
  247. * @throws HttpException
  248. */
  249. public function actionPackageGet() {
  250. $id = \Yii::$app->request->get('id');
  251. if (\Yii::$app->request->isPost) {
  252. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  253. // Log::adminHandle('编辑报单套餐', 1);
  254. });
  255. }
  256. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  257. 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']]);
  258. }
  259. /**
  260. * 套餐上下架
  261. * @return mixed
  262. * @throws Exception
  263. */
  264. public function actionPackageStatus() {
  265. $id = \Yii::$app->request->get('id');
  266. if (\Yii::$app->request->isPost) {
  267. $formModel = new DecPackageForm();
  268. $formModel->scenario = 'changeStatus';
  269. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  270. return static::notice('Status setting succeeded'); // 状态设置成功
  271. } else {
  272. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  273. }
  274. }
  275. }
  276. /**
  277. * 删除套餐
  278. * @return mixed
  279. * @throws \yii\db\Exception
  280. * @throws HttpException
  281. */
  282. public function actionPackageDelete(){
  283. $result = static::delete(DeclarationPackage::class);
  284. return $result;
  285. }
  286. /**
  287. * 报单表
  288. * @return mixed
  289. * @throws Exception
  290. * @throws HttpException
  291. */
  292. public function actionDecOrderList() {
  293. $filter = $this->filterCondition([
  294. 'DEC_SN'=> 'DO.DEC_SN',
  295. 'ORDER_SN'=> 'DO.ORDER_SN',
  296. 'USER_NAME'=> 'U.USER_NAME',
  297. 'TO_USER_NAME'=> 'TU.USER_NAME',
  298. 'REAL_NAME'=> 'TU.REAL_NAME',
  299. 'ID_CARD'=> 'TU.ID_CARD',
  300. 'MOBILE'=> 'TU.MOBILE',
  301. 'DEC_LV_NAME' => 'TU.DEC_LV',
  302. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  303. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  304. 'DEC_PV'=> 'DO.DEC_PV',
  305. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  306. 'REC_USER_NAME'=> 'RU.USER_NAME',
  307. 'CREATED_AT'=> 'DO.CREATED_AT',
  308. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  309. ]);
  310. $condition = $filter['condition'];
  311. $params = $filter['params'];
  312. $condition .= ' AND DO.IS_DEL=0';
  313. $listObj = new DecOrderList();
  314. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  315. return static::notice($data);
  316. }
  317. /**
  318. * 报单表导出
  319. * @return mixed
  320. * @throws \yii\db\Exception
  321. * @throws HttpException
  322. */
  323. public function actionDecOrderListExport()
  324. {
  325. $filter = $this->filterCondition([
  326. 'DEC_SN'=> 'DO.DEC_SN',
  327. 'ORDER_SN'=> 'DO.ORDER_SN',
  328. 'USER_NAME'=> 'U.USER_NAME',
  329. 'TO_USER_NAME'=> 'TU.USER_NAME',
  330. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  331. 'DEC_PV'=> 'DO.DEC_PV',
  332. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  333. 'CREATED_AT'=> 'DO.CREATED_AT',
  334. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  335. ]);
  336. $filter['condition'] .= ' AND DO.IS_DEL=0';
  337. $form = new ShopExportForm();
  338. $result = $form->run($filter, \Yii::t('ctx', 'shopDecOrderListExport'));
  339. if (!$result) {
  340. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  341. }
  342. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  343. }
  344. // 删除订单
  345. public function actionDeleteOrder() {
  346. if (\Yii::$app->request->isPost) {
  347. $formModel = new OrderDeleteForm();
  348. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  349. return static::notice(\Yii::t('ctx', 'shopDelOrderSuccedNotice'));
  350. } else {
  351. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  352. }
  353. }
  354. }
  355. /**
  356. * 订单表
  357. * @return mixed
  358. * @throws Exception
  359. * @throws HttpException
  360. */
  361. public function actionOrderList() {
  362. $filter = $this->filterCondition([
  363. 'SN'=> 'O.SN',
  364. 'USER_NAME'=> 'U.USER_NAME',
  365. 'MOBILE'=> 'O.MOBILE',
  366. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  367. 'CREATED_AT'=> 'O.CREATED_AT',
  368. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  369. 'STATUS' => 'O.STATUS',
  370. 'IS_AUTO' => 'O.IS_AUTO'
  371. ]);
  372. $condition = ' 1=1 ' . $filter['condition'];
  373. $params = $filter['params'];
  374. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  375. $listObj = new OrderList();
  376. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  377. return static::notice($data);
  378. }
  379. /**
  380. * 订单表导出
  381. * @return mixed
  382. * @throws \yii\db\Exception
  383. * @throws HttpException
  384. */
  385. public function actionOrderListExport()
  386. {
  387. $filter = $this->filterCondition([
  388. 'SN'=> 'O.SN',
  389. 'USER_NAME'=> 'U.USER_NAME',
  390. 'MOBILE'=> 'O.MOBILE',
  391. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  392. 'CREATED_AT'=> 'O.CREATED_AT',
  393. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  394. 'STATUS' => 'O.STATUS',
  395. 'IS_AUTO' => 'O.IS_AUTO'
  396. ]);
  397. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  398. $form = new ShopExportForm();
  399. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExport')); // 订单列表
  400. if (!$result) {
  401. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  402. }
  403. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  404. }
  405. /**
  406. * 外部商城订单列表
  407. * @return mixed
  408. * @throws Exception
  409. * @throws HttpException
  410. */
  411. public function actionOrderShopList() {
  412. $filter = $this->filterCondition([
  413. 'SN'=> 'O.SN',
  414. 'USER_NAME'=> 'U.USER_NAME',
  415. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  416. 'CREATED_AT'=> 'O.CREATED_AT',
  417. ]);
  418. $condition = $filter['condition'];
  419. $params = $filter['params'];
  420. $condition .= ' AND O.IS_DELETE=0';
  421. $listObj = new OrderShopList();
  422. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  423. return static::notice($data);
  424. }
  425. /**
  426. * 外部商城报单列表
  427. * @return mixed
  428. * @throws Exception
  429. * @throws HttpException
  430. */
  431. public function actionOrderDecList() {
  432. $filter = $this->filterCondition([
  433. 'SN'=> 'O.SN',
  434. 'USER_NAME'=> 'U.USER_NAME',
  435. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  436. 'CREATED_AT'=> 'O.CREATED_AT',
  437. ]);
  438. $condition = $filter['condition'];
  439. $params = $filter['params'];
  440. $condition .= ' AND O.IS_DELETE=0';
  441. $listObj = new OrderDecList();
  442. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  443. return static::notice($data);
  444. }
  445. /**
  446. * 分页导入excel文件到待导入数据的表中
  447. * @return mixed
  448. */
  449. public function actionImportOrderShopToExcelTable()
  450. {
  451. // 先上传到服务器文件
  452. if (\Yii::$app->request->isPost) {
  453. $excelImportId = \Yii::$app->request->post('excelImportId');
  454. $rowCount = \Yii::$app->request->post('rowCount');
  455. //$periodNum = \Yii::$app->request->post('periodNum');
  456. $orderDay = \Yii::$app->request->post('orderDay');
  457. $orderType = \Yii::$app->request->post('orderType');
  458. $startRow = \Yii::$app->request->post('startRow');
  459. $limit = \Yii::$app->request->post('limit', 1000);
  460. $errorMsg = '';
  461. try {
  462. if( $startRow == 1 ) {
  463. $excelOrderShop = new ExcelOrderShopForm();
  464. $excelOrderShop->checkStatus($orderDay,$orderType);
  465. }
  466. $excel = new \common\helpers\Excel();
  467. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  468. } catch (\Exception $e) {
  469. $result = false;
  470. $errorMsg = $e->getMessage();
  471. }
  472. // 还有数据
  473. if ($result === 1) {
  474. return static::notice(['finish' => false]);
  475. } elseif ($result === 0) {
  476. return static::notice(['finish' => true]);
  477. } else {
  478. return static::notice('Error:' . $errorMsg, 400);
  479. }
  480. }
  481. }
  482. /**
  483. * 导入完成标记
  484. * @return mixed
  485. * @throws HttpException
  486. */
  487. public function actionImportOrderShop() {
  488. //$periodNum = \Yii::$app->request->post('periodNum');
  489. $orderDay = \Yii::$app->request->post('orderDay');
  490. $orderType = \Yii::$app->request->post('orderType');
  491. $excelOrderShop = new ExcelOrderShopForm();
  492. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  493. if ($finishStatus) {
  494. return static::notice(['finish' => true]);
  495. } else {
  496. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  497. }
  498. }
  499. /**
  500. * 报单订单——分页导入excel文件到待导入数据的表中
  501. * @return mixed
  502. */
  503. public function actionImportOrderDecToExcelTable()
  504. {
  505. // 先上传到服务器文件
  506. if (\Yii::$app->request->isPost) {
  507. $excelImportId = \Yii::$app->request->post('excelImportId');
  508. $rowCount = \Yii::$app->request->post('rowCount');
  509. //$periodNum = \Yii::$app->request->post('periodNum');
  510. $orderDay = \Yii::$app->request->post('orderDay');
  511. $startRow = \Yii::$app->request->post('startRow');
  512. $limit = \Yii::$app->request->post('limit', 1000);
  513. $errorMsg = '';
  514. try {
  515. if( $startRow == 1 ) {
  516. $excelOrderShop = new ExcelOrderDecForm();
  517. $excelOrderShop->checkStatus($orderDay);
  518. }
  519. $excel = new \common\helpers\Excel();
  520. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  521. } catch (\Exception $e) {
  522. $result = false;
  523. $errorMsg = $e->getMessage();
  524. }
  525. // 还有数据
  526. if ($result === 1) {
  527. return static::notice(['finish' => false]);
  528. } elseif ($result === 0) {
  529. return static::notice(['finish' => true]);
  530. } else {
  531. return static::notice('Error:' . $errorMsg, 400);
  532. }
  533. }
  534. }
  535. /**
  536. * 报单订单导入完成标记
  537. * @return mixed
  538. * @throws HttpException
  539. */
  540. public function actionImportOrderDec() {
  541. //$periodNum = \Yii::$app->request->post('periodNum');
  542. $orderDay = \Yii::$app->request->post('orderDay');
  543. $excelOrderShop = new ExcelOrderDecForm();
  544. $finishStatus = $excelOrderShop->finished($orderDay);
  545. if ($finishStatus) {
  546. return static::notice(['finish' => true]);
  547. } else {
  548. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  549. }
  550. }
  551. /**
  552. * 见习达标订单列表
  553. * @return mixed
  554. * @throws Exception
  555. * @throws HttpException
  556. */
  557. public function actionOrderStandardList() {
  558. $filter = $this->filterCondition([
  559. 'SN'=> 'O.SN',
  560. 'USER_NAME'=> 'U.USER_NAME',
  561. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  562. 'CREATED_AT'=> 'O.CREATED_AT',
  563. ]);
  564. $condition = $filter['condition'];
  565. $params = $filter['params'];
  566. $condition .= ' AND O.IS_DELETE=0';
  567. $listObj = new OrderStandardList();
  568. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  569. return static::notice($data);
  570. }
  571. /**
  572. * 分页导入excel文件到待导入数据的表中
  573. * @return mixed
  574. * @throws HttpException
  575. */
  576. public function actionImportOrderStandardToExcelTable()
  577. {
  578. // 先上传到服务器文件
  579. if (\Yii::$app->request->isPost) {
  580. $excelImportId = \Yii::$app->request->post('excelImportId');
  581. $rowCount = \Yii::$app->request->post('rowCount');
  582. //$periodNum = \Yii::$app->request->post('periodNum');
  583. $orderMonth = \Yii::$app->request->post('orderMonth');
  584. // $orderType = \Yii::$app->request->post('orderType');
  585. $orderType = 'cash';
  586. $startRow = \Yii::$app->request->post('startRow');
  587. $limit = \Yii::$app->request->post('limit', 1000);
  588. $errorMsg = '';
  589. try {
  590. if( $startRow == 1 ) {
  591. //清空已经导入的表数据
  592. $excelOrderStandard = new ExcelOrderStandardForm();
  593. $excelOrderStandard->checkStatus($orderMonth);
  594. }
  595. $excel = new \common\helpers\Excel();
  596. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  597. } catch (Exception $e) {
  598. $result = false;
  599. $errorMsg = $e->getMessage();
  600. }
  601. // 还有数据
  602. if ($result === 1) {
  603. return static::notice(['finish' => false]);
  604. } elseif ($result === 0) {
  605. return static::notice(['finish' => true]);
  606. } else {
  607. return static::notice('Error:' . $errorMsg, 400);
  608. }
  609. }
  610. }
  611. /**
  612. * 达标订单导入完成标记
  613. * @return mixed
  614. * @throws HttpException
  615. */
  616. public function actionImportOrderStandard() {
  617. $orderMonth = \Yii::$app->request->post('orderMonth');
  618. $excelOrderStandard = new ExcelOrderStandardForm();
  619. $finishStatus = $excelOrderStandard->finished($orderMonth);
  620. if ($finishStatus) {
  621. return static::notice(['finish' => true]);
  622. } else {
  623. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  624. }
  625. }
  626. /**
  627. * 管理员发货
  628. * @return mixed
  629. * @throws HttpException
  630. */
  631. public function actionOrderDelivery() {
  632. if(\Yii::$app->request->isPost) {
  633. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  634. }
  635. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  636. }
  637. /**
  638. * 报单表导出
  639. * @return mixed
  640. * @throws \yii\db\Exception
  641. * @throws HttpException
  642. */
  643. public function actionOrderListExportPdf()
  644. {
  645. $orderSn = \Yii::$app->request->get('orderSn');
  646. $filter = $this->filterCondition([
  647. 'SN'=> 'O.SN',
  648. 'USER_NAME'=> 'U.USER_NAME',
  649. 'MOBILE'=> 'O.MOBILE',
  650. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  651. 'CREATED_AT'=> 'O.CREATED_AT',
  652. ]);
  653. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  654. $filter['params'] = [':SN' => $orderSn];
  655. $form = new ShopExportForm();
  656. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  657. if (!$result) {
  658. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  659. }
  660. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  661. }
  662. /**
  663. * 报单表导出
  664. * @return mixed
  665. * @throws \yii\db\Exception
  666. * @throws HttpException
  667. */
  668. public function actionDecOrderListExportPdf()
  669. {
  670. $orderSn = \Yii::$app->request->get('orderSn');
  671. $filter = $this->filterCondition([
  672. 'SN'=> 'O.SN',
  673. 'USER_NAME'=> 'U.USER_NAME',
  674. 'MOBILE'=> 'O.MOBILE',
  675. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  676. 'CREATED_AT'=> 'O.CREATED_AT',
  677. ]);
  678. $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
  679. $filter['params'] = [':SN' => $orderSn];
  680. $form = new ShopExportForm();
  681. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  682. if (!$result) {
  683. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  684. }
  685. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  686. }
  687. /**
  688. * 管理员订单退款
  689. * @return mixed
  690. * @throws HttpException
  691. */
  692. public function actionOrderRefund()
  693. {
  694. if(\Yii::$app->request->isPost) {
  695. return parent::edit(OrderForm::class, \Yii::t('ctx', 'shopadminRefund'), 'adminRefund', ['adminRefund']);
  696. }
  697. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  698. }
  699. /*
  700. * 剩余BV页
  701. *
  702. */
  703. public function actionRemainPv()
  704. {
  705. $filter = $this->filterCondition([
  706. 'USER_NAME' => 'U.USER_NAME',
  707. ]);
  708. $condition = $filter['condition'];
  709. $params = $filter['params'];
  710. $listObj = new RemainPvList();
  711. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  712. return static::notice($data);
  713. }
  714. /*
  715. * 剩余BV流水
  716. *
  717. */
  718. public function actionFlowRemainPv()
  719. {
  720. $filter = $this->filterCondition([
  721. 'USER_NAME' => 'U.USER_NAME',
  722. ]);
  723. $condition = $filter['condition'];
  724. $params = $filter['params'];
  725. $listObj = new FlowRemainPvList();
  726. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  727. return static::notice($data);
  728. }
  729. /**
  730. * BA订单表
  731. * @return mixed
  732. * @throws Exception
  733. * @throws HttpException
  734. */
  735. public function actionBaOrderList() {
  736. $filter = $this->filterCondition([
  737. 'SN'=> 'O.SN',
  738. 'USER_NAME'=> 'U.USER_NAME',
  739. 'MOBILE'=> 'O.MOBILE',
  740. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  741. 'CREATED_AT'=> 'O.CREATED_AT',
  742. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  743. 'STATUS' => 'O.STATUS',
  744. ]);
  745. $condition = ' 1=1 ' . $filter['condition'];
  746. $params = $filter['params'];
  747. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  748. $listObj = new BaOrderList();
  749. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  750. return static::notice($data);
  751. }
  752. /**
  753. * BA订单表导出
  754. * @return mixed
  755. * @throws \yii\db\Exception
  756. * @throws HttpException
  757. */
  758. public function actionBaOrderListExport()
  759. {
  760. $filter = $this->filterCondition([
  761. 'SN'=> 'O.SN',
  762. 'USER_NAME'=> 'U.USER_NAME',
  763. 'MOBILE'=> 'O.MOBILE',
  764. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  765. 'CREATED_AT'=> 'O.CREATED_AT',
  766. 'STATUS' => 'O.STATUS',
  767. ]);
  768. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  769. $form = new BaShopExportForm();
  770. $result = $form->run($filter, \Yii::t('ctx', 'shopBaOrderListExport')); // 订单列表
  771. if (!$result) {
  772. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  773. }
  774. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  775. }
  776. /**
  777. * 报单表导出
  778. * @return mixed
  779. * @throws \yii\db\Exception
  780. * @throws HttpException
  781. */
  782. public function actionBaOrderListExportPdf()
  783. {
  784. $orderSn = \Yii::$app->request->get('orderSn');
  785. $filter = $this->filterCondition([
  786. 'SN'=> 'O.SN',
  787. 'USER_NAME'=> 'U.USER_NAME',
  788. 'MOBILE'=> 'O.MOBILE',
  789. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  790. 'CREATED_AT'=> 'O.CREATED_AT',
  791. ]);
  792. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  793. $filter['params'] = [':SN' => $orderSn];
  794. $form = new BaShopExportForm();
  795. $result = $form->run($filter, \Yii::t('ctx', 'shopBrandAmbassadorOrderExport'));
  796. if (!$result) {
  797. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  798. }
  799. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  800. }
  801. /**
  802. * 调整订单期数
  803. * @return mixed
  804. * @throws Exception
  805. * @throws \yii\db\Exception
  806. * @throws \yii\web\HttpException
  807. */
  808. public function actionOrderPeriodAdjust()
  809. {
  810. if (\Yii::$app->request->isPost) {
  811. $formModel = new OrderPeriodAdjustForm();
  812. $formModel->scenario = 'orderPeriodAdjust';
  813. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  814. return static::notice('成功');
  815. } else {
  816. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  817. }
  818. } else {
  819. $filter = $this->filterCondition([
  820. 'ORDER_SN' => 'P.ORDER_SN',
  821. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  822. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  823. 'CREATED_AT'=> 'P.CREATED_AT',
  824. ]);
  825. $listObj = new OrderPeriodAdjustList();
  826. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  827. return static::notice($data);
  828. }
  829. }
  830. /**
  831. * 订单详情
  832. * @return mixed
  833. * @throws \yii\web\HttpException
  834. */
  835. public function actionOrderDetail()
  836. {
  837. $orderSn = \Yii::$app->request->get('orderSn');
  838. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  839. if (!$order) {
  840. return static::notice('订单不存在', 400);
  841. }
  842. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? '首单' : '复消';
  843. // 如果当前订单所在期数已挂网,则不可调整
  844. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  845. if (!$period) {
  846. return static::notice('期数无效', 400);
  847. }
  848. if ($period['IS_SENT'] > 0) {
  849. return static::notice('订单已挂网', 400);
  850. }
  851. // 根据订单期数查询可调整期数
  852. $availablePeriod = [];
  853. if ($order['PERIOD_NUM']) {
  854. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  855. foreach ($availablePeriod as $k => $item) {
  856. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  857. }
  858. }
  859. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  860. }
  861. }