ShopController.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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\Admin;
  10. use backendApi\modules\v1\models\exportForms\OrderExportForm;
  11. use backendApi\modules\v1\models\exportForms\ShopExportForm;
  12. use backendApi\modules\v1\models\lists\shop\DecOrderList;
  13. use backendApi\modules\v1\models\lists\shop\GoodsList;
  14. use backendApi\modules\v1\models\lists\shop\OrderDecList;
  15. use backendApi\modules\v1\models\lists\shop\OrderList;
  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 common\helpers\bonus\CalcCache;
  21. use backendApi\modules\v1\models\lists\shop\RemainPvList;
  22. use backendApi\modules\v1\models\lists\shop\FlowRemainPvList;
  23. use common\helpers\Cache;
  24. use common\helpers\Date;
  25. use common\helpers\Form;
  26. use common\helpers\Log;
  27. use common\helpers\snowflake\SnowFake;
  28. use common\libs\export\module\ShopExport;
  29. use common\models\DeclarationPackage;
  30. use common\models\DecOrder;
  31. use common\models\ExcelOrderShop;
  32. use common\models\FlowExchangePoints;
  33. use common\models\FlowReconsumePoints;
  34. use common\models\FlowWallet;
  35. use common\models\forms\DecPackageForm;
  36. use common\models\forms\ExcelOrderDecForm;
  37. use common\models\forms\ExcelOrderShopForm;
  38. use common\models\forms\ExcelOrderStandardForm;
  39. use common\models\forms\OrderDeleteForm;
  40. use common\models\forms\OrderForm;
  41. use common\models\forms\OrderPeriodAdjustForm;
  42. use common\models\forms\ShopGoodsForm;
  43. use common\models\forms\UploadForm;
  44. use common\models\Order;
  45. use common\models\OrderPeriodAdjust;
  46. use common\models\Period;
  47. use common\models\ShopGoods;
  48. use common\models\User;
  49. use common\models\UserInfo;
  50. use yii\web\UploadedFile;
  51. use yii\base\Exception;
  52. class ShopController extends BaseController {
  53. public $modelClass = DecOrder::class;
  54. public function behaviors() {
  55. $behaviors = parent::behaviors();
  56. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  57. return $behaviors;
  58. }
  59. /**
  60. * 商品列表
  61. * @return mixed
  62. * @throws Exception
  63. * @throws \yii\web\HttpException
  64. */
  65. public function actionIndex() {
  66. $filter = $this->filterCondition([
  67. 'TYPE'=> 'TYPE',
  68. 'GIFT_TYPE'=> 'GIFT_TYPE',
  69. 'STATUS'=> 'STATUS',
  70. 'GOODS_NAME'=> 'GOODS_NAME',
  71. 'GOODS_NO'=> 'GOODS_NO',
  72. 'SELL_TYPE'=> 'SELL_TYPE',
  73. 'SELL_PRICE'=> 'SELL_PRICE',
  74. 'PRICE_PV'=> 'PRICE_PV',
  75. ]);
  76. $condition = $filter['condition'];
  77. $params = $filter['params'];
  78. $condition .= ' ';
  79. $listObj = new GoodsList();
  80. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  81. return static::notice($data);
  82. }
  83. /**
  84. * 商品列表导出
  85. * @return mixed
  86. * @throws \yii\db\Exception
  87. * @throws \yii\web\HttpException
  88. */
  89. public function actionGoodsListExport()
  90. {
  91. $filter = $this->filterCondition([
  92. 'TYPE'=> 'TYPE',
  93. 'GIFT_TYPE'=> 'GIFT_TYPE',
  94. 'STATUS'=> 'STATUS',
  95. 'GOODS_NAME'=> 'GOODS_NAME',
  96. 'GOODS_NO'=> 'GOODS_NO',
  97. 'SELL_TYPE'=> 'SELL_TYPE',
  98. 'SELL_PRICE'=> 'SELL_PRICE',
  99. 'PRICE_PV'=> 'PRICE_PV',
  100. ]);
  101. $form = new ShopExportForm();
  102. $result = $form->run($filter, '商品列表');
  103. if (!$result) {
  104. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  105. }
  106. return static::notice('导出开始,请到文件管理-导出文件查看');
  107. }
  108. /**
  109. * 添加商品
  110. * @return mixed
  111. * @throws Exception
  112. * @throws \yii\web\HttpException
  113. */
  114. public function actionGoodsAdd() {
  115. if (\Yii::$app->request->isPost) {
  116. $formModel = new ShopGoodsForm();
  117. $formModel->scenario = 'add';
  118. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  119. return static::notice('商品添加成功');
  120. } else {
  121. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  122. }
  123. }
  124. return static::notice(['sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  125. }
  126. /**
  127. * 编辑商品
  128. * @return mixed
  129. * @throws Exception
  130. * @throws \yii\web\HttpException
  131. */
  132. public function actionGoodsEdit() {
  133. $id = \Yii::$app->request->get('id');
  134. if (\Yii::$app->request->isPost) {
  135. $formModel = new ShopGoodsForm();
  136. $formModel->scenario = 'edit';
  137. $formModel->id = $id;
  138. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  139. return static::notice('商品编辑成功');
  140. } else {
  141. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  142. }
  143. }
  144. $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
  145. $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
  146. $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
  147. return static::notice(['goodsInfo'=>$data,'sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
  148. }
  149. /**
  150. * 上传图片
  151. * @return mixed
  152. * @throws \yii\base\Exception
  153. * @throws \yii\db\Exception
  154. * @throws \yii\web\HttpException
  155. */
  156. public function actionUpload(){
  157. if(\Yii::$app->request->isPost){
  158. $formModel = new UploadForm();
  159. $formModel->scenario = 'goodsImg';
  160. $formModel->file = UploadedFile::getInstanceByName('file');
  161. $formModel->token = \Yii::$app->request->request('uploadToken');
  162. if($formModel->file && $uploader = $formModel->upload()){
  163. return static::notice($uploader->URL);
  164. } else {
  165. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  166. }
  167. } else {
  168. $token = Cache::setUploadToken();
  169. return static::notice($token);
  170. }
  171. }
  172. /**
  173. * 商品上下架
  174. * @return mixed
  175. * @throws Exception
  176. */
  177. public function actionGoodsStatus() {
  178. $id = \Yii::$app->request->get('id');
  179. if (\Yii::$app->request->isPost) {
  180. $formModel = new ShopGoodsForm();
  181. $formModel->scenario = 'changeStatus';
  182. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  183. // foreach ($result['logs'] as $k => $value) {
  184. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  185. // }
  186. return static::notice('状态设置成功');
  187. } else {
  188. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  189. }
  190. }
  191. }
  192. /**
  193. * 删除商品
  194. * @return mixed
  195. * @throws \yii\db\Exception
  196. * @throws \yii\web\HttpException
  197. */
  198. public function actionGoodsDelete(){
  199. $result = static::delete(ShopGoods::class);
  200. return $result;
  201. }
  202. /**
  203. * 套餐列表
  204. * @return mixed
  205. * @throws Exception
  206. * @throws \yii\web\HttpException
  207. */
  208. public function actionPackage() {
  209. $filter = $this->filterCondition([
  210. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  211. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  212. 'AMOUNT'=> 'DP.AMOUNT',
  213. 'PV'=> 'DP.PV',
  214. 'STATUS'=> 'DP.STATUS',
  215. 'STORE_NUMS'=>'DP.STORE_NUMS',
  216. 'STATUS_DATE'=>'DP.STATUS_DATE',
  217. 'PACKAGE_DATE'=>'DP.PACKAGE_DATE',
  218. 'PACKAGE_STATUS_DATE'=>'DP.PACKAGE_STATUS_DATE'
  219. ]);
  220. $condition = $filter['condition'];
  221. $params = $filter['params'];
  222. $condition .= ' AND DP.IS_DEL=0';
  223. $listObj = new PackageList();
  224. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  225. return static::notice($data);
  226. }
  227. /**
  228. * 添加报单套餐
  229. * @return mixed
  230. * @throws \yii\web\HttpException
  231. */
  232. public function actionPackageAdd() {
  233. if (\Yii::$app->request->isPost) {
  234. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  235. // Log::adminHandle('添加报单套餐', 1);
  236. });
  237. }
  238. return static::notice('非发请求', 405);
  239. }
  240. /**
  241. * 报单套餐获取
  242. * @return mixed
  243. * @throws \yii\web\HttpException
  244. */
  245. public function actionPackageGet() {
  246. $id = \Yii::$app->request->get('id');
  247. if (\Yii::$app->request->isPost) {
  248. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  249. // Log::adminHandle('编辑报单套餐', 1);
  250. });
  251. }
  252. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  253. 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']]);
  254. }
  255. /**
  256. * 套餐上下架
  257. * @return mixed
  258. * @throws Exception
  259. */
  260. public function actionPackageStatus() {
  261. $id = \Yii::$app->request->get('id');
  262. if (\Yii::$app->request->isPost) {
  263. $formModel = new DecPackageForm();
  264. $formModel->scenario = 'changeStatus';
  265. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  266. return static::notice('状态设置成功');
  267. } else {
  268. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  269. }
  270. }
  271. }
  272. /**
  273. * 删除套餐
  274. * @return mixed
  275. * @throws \yii\db\Exception
  276. * @throws \yii\web\HttpException
  277. */
  278. public function actionPackageDelete(){
  279. $result = static::delete(DeclarationPackage::class);
  280. return $result;
  281. }
  282. /**
  283. * 报单表
  284. * @return mixed
  285. * @throws Exception
  286. * @throws \yii\web\HttpException
  287. */
  288. public function actionDecOrderList() {
  289. $filter = $this->filterCondition([
  290. 'DEC_SN'=> 'DO.DEC_SN',
  291. 'ORDER_SN'=> 'DO.ORDER_SN',
  292. 'USER_NAME'=> 'U.USER_NAME',
  293. 'TO_USER_NAME'=> 'TU.USER_NAME',
  294. 'REAL_NAME'=> 'TU.REAL_NAME',
  295. 'ID_CARD'=> 'TU.ID_CARD',
  296. 'MOBILE'=> 'TU.MOBILE',
  297. 'DEC_LV_NAME' => 'TU.DEC_LV',
  298. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  299. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  300. 'DEC_PV'=> 'DO.DEC_PV',
  301. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  302. 'REC_USER_NAME'=> 'RU.USER_NAME',
  303. 'CREATED_AT'=> 'DO.CREATED_AT',
  304. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  305. ]);
  306. $condition = $filter['condition'];
  307. $params = $filter['params'];
  308. $condition .= ' AND DO.IS_DEL=0';
  309. $listObj = new DecOrderList();
  310. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  311. return static::notice($data);
  312. }
  313. /**
  314. * 报单表导出
  315. * @return mixed
  316. * @throws \yii\db\Exception
  317. * @throws \yii\web\HttpException
  318. */
  319. public function actionDecOrderListExport()
  320. {
  321. $filter = $this->filterCondition([
  322. 'DEC_SN'=> 'DO.DEC_SN',
  323. 'ORDER_SN'=> 'DO.ORDER_SN',
  324. 'USER_NAME'=> 'U.USER_NAME',
  325. 'TO_USER_NAME'=> 'TU.USER_NAME',
  326. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  327. 'DEC_PV'=> 'DO.DEC_PV',
  328. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  329. 'CREATED_AT'=> 'DO.CREATED_AT',
  330. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  331. ]);
  332. $filter['condition'] .= ' AND DO.IS_DEL=0';
  333. $form = new ShopExportForm();
  334. $result = $form->run($filter, '报单列表');
  335. if (!$result) {
  336. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  337. }
  338. return static::notice('导出开始,请到文件管理-导出文件查看');
  339. }
  340. /**
  341. * 订单表
  342. * @return mixed
  343. * @throws Exception
  344. * @throws \yii\web\HttpException
  345. */
  346. public function actionOrderList() {
  347. $filter = $this->filterCondition([
  348. 'SN'=> 'O.SN',
  349. 'USER_NAME'=> 'U.USER_NAME',
  350. 'MOBILE'=> 'O.MOBILE',
  351. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  352. 'CREATED_AT'=> 'O.CREATED_AT',
  353. 'PAY_TYPE'=> 'O.PAY_TYPE',
  354. ]);
  355. // $condition = ' 1=1 ' . $filter['condition'];
  356. // $params = $filter['params'];
  357. // $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  358. $condition = $filter['condition'];
  359. $params = $filter['params'];
  360. $condition .= ' AND O.IS_DELETE=0';
  361. $listObj = new OrderList();
  362. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  363. return static::notice($data);
  364. }
  365. // 删除订单
  366. public function actionDeleteOrder() {
  367. if (\Yii::$app->request->isPost) {
  368. $formModel = new OrderDeleteForm();
  369. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  370. return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
  371. } else {
  372. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  373. }
  374. }
  375. }
  376. /**
  377. * 订单表导出
  378. * @return mixed
  379. * @throws \yii\db\Exception
  380. * @throws \yii\web\HttpException
  381. */
  382. public function actionOrderListExport()
  383. {
  384. $filter = $this->filterCondition([
  385. 'SN'=> 'O.SN',
  386. 'USER_NAME'=> 'U.USER_NAME',
  387. 'MOBILE'=> 'O.MOBILE',
  388. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  389. 'CREATED_AT'=> 'O.CREATED_AT',
  390. 'PAY_TYPE'=> 'O.PAY_TYPE',
  391. ]);
  392. // $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  393. $filter['condition'] .= ' AND O.IS_DELETE=0';
  394. $form = new ShopExportForm();
  395. $result = $form->run($filter, '订单列表');
  396. if (!$result) {
  397. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  398. }
  399. return static::notice('导出开始,请到文件管理-导出文件查看');
  400. }
  401. /**
  402. * 外部商城订单列表
  403. * @return mixed
  404. * @throws Exception
  405. * @throws \yii\web\HttpException
  406. */
  407. public function actionOrderShopList() {
  408. $filter = $this->filterCondition([
  409. 'SN'=> 'O.SN',
  410. 'USER_NAME'=> 'U.USER_NAME',
  411. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  412. 'CREATED_AT'=> 'O.CREATED_AT',
  413. ]);
  414. $condition = $filter['condition'];
  415. $params = $filter['params'];
  416. $condition .= ' AND O.IS_DELETE=0';
  417. $listObj = new OrderShopList();
  418. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  419. return static::notice($data);
  420. }
  421. /**
  422. * 外部商城报单列表
  423. * @return mixed
  424. * @throws Exception
  425. * @throws \yii\web\HttpException
  426. */
  427. public function actionOrderDecList() {
  428. $filter = $this->filterCondition([
  429. 'SN'=> 'O.SN',
  430. 'USER_NAME'=> 'U.USER_NAME',
  431. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  432. 'CREATED_AT'=> 'O.CREATED_AT',
  433. ]);
  434. $condition = $filter['condition'];
  435. $params = $filter['params'];
  436. $condition .= ' AND O.IS_DELETE=0';
  437. $listObj = new OrderDecList();
  438. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  439. return static::notice($data);
  440. }
  441. /**
  442. * 分页导入excel文件到待导入数据的表中
  443. * @return mixed
  444. */
  445. public function actionImportOrderShopToExcelTable()
  446. {
  447. // 先上传到服务器文件
  448. if (\Yii::$app->request->isPost) {
  449. $excelImportId = \Yii::$app->request->post('excelImportId');
  450. $rowCount = \Yii::$app->request->post('rowCount');
  451. //$periodNum = \Yii::$app->request->post('periodNum');
  452. $orderDay = \Yii::$app->request->post('orderDay');
  453. $orderType = \Yii::$app->request->post('orderType');
  454. $startRow = \Yii::$app->request->post('startRow');
  455. $limit = \Yii::$app->request->post('limit', 1000);
  456. $errorMsg = '';
  457. try {
  458. if( $startRow == 1 ) {
  459. $excelOrderShop = new ExcelOrderShopForm();
  460. $excelOrderShop->checkStatus($orderDay,$orderType);
  461. }
  462. $excel = new \common\helpers\Excel();
  463. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  464. } catch (\Exception $e) {
  465. $result = false;
  466. $errorMsg = $e->getMessage();
  467. }
  468. // 还有数据
  469. if ($result === 1) {
  470. return static::notice(['finish' => false]);
  471. } elseif ($result === 0) {
  472. return static::notice(['finish' => true]);
  473. } else {
  474. return static::notice('发生错误:' . $errorMsg, 400);
  475. }
  476. }
  477. }
  478. /**
  479. * 导入完成标记
  480. * @return mixed
  481. * @throws \yii\web\HttpException
  482. */
  483. public function actionImportOrderShop() {
  484. //$periodNum = \Yii::$app->request->post('periodNum');
  485. $orderDay = \Yii::$app->request->post('orderDay');
  486. $orderType = \Yii::$app->request->post('orderType');
  487. $excelOrderShop = new ExcelOrderShopForm();
  488. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  489. if ($finishStatus) {
  490. return static::notice(['finish' => true]);
  491. } else {
  492. return static::notice('状态更新错误', 400);
  493. }
  494. }
  495. /**
  496. * 报单订单——分页导入excel文件到待导入数据的表中
  497. * @return mixed
  498. */
  499. public function actionImportOrderDecToExcelTable()
  500. {
  501. // 先上传到服务器文件
  502. if (\Yii::$app->request->isPost) {
  503. $excelImportId = \Yii::$app->request->post('excelImportId');
  504. $rowCount = \Yii::$app->request->post('rowCount');
  505. //$periodNum = \Yii::$app->request->post('periodNum');
  506. $orderDay = \Yii::$app->request->post('orderDay');
  507. $startRow = \Yii::$app->request->post('startRow');
  508. $limit = \Yii::$app->request->post('limit', 1000);
  509. $errorMsg = '';
  510. try {
  511. if( $startRow == 1 ) {
  512. $excelOrderShop = new ExcelOrderDecForm();
  513. $excelOrderShop->checkStatus($orderDay);
  514. }
  515. $excel = new \common\helpers\Excel();
  516. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  517. } catch (\Exception $e) {
  518. $result = false;
  519. $errorMsg = $e->getMessage();
  520. }
  521. // 还有数据
  522. if ($result === 1) {
  523. return static::notice(['finish' => false]);
  524. } elseif ($result === 0) {
  525. return static::notice(['finish' => true]);
  526. } else {
  527. return static::notice('发生错误:' . $errorMsg, 400);
  528. }
  529. }
  530. }
  531. /**
  532. * 报单订单导入完成标记
  533. * @return mixed
  534. * @throws \yii\web\HttpException
  535. */
  536. public function actionImportOrderDec() {
  537. //$periodNum = \Yii::$app->request->post('periodNum');
  538. $orderDay = \Yii::$app->request->post('orderDay');
  539. $excelOrderShop = new ExcelOrderDecForm();
  540. $finishStatus = $excelOrderShop->finished($orderDay);
  541. if ($finishStatus) {
  542. return static::notice(['finish' => true]);
  543. } else {
  544. return static::notice('状态更新错误', 400);
  545. }
  546. }
  547. /**
  548. * 见习达标订单列表
  549. * @return mixed
  550. * @throws Exception
  551. * @throws \yii\web\HttpException
  552. */
  553. public function actionOrderStandardList() {
  554. $filter = $this->filterCondition([
  555. 'SN'=> 'O.SN',
  556. 'USER_NAME'=> 'U.USER_NAME',
  557. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  558. 'CREATED_AT'=> 'O.CREATED_AT',
  559. ]);
  560. $condition = $filter['condition'];
  561. $params = $filter['params'];
  562. $condition .= ' AND O.IS_DELETE=0';
  563. $listObj = new OrderStandardList();
  564. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  565. return static::notice($data);
  566. }
  567. /**
  568. * 分页导入excel文件到待导入数据的表中
  569. * @return mixed
  570. * @throws \yii\web\HttpException
  571. */
  572. public function actionImportOrderStandardToExcelTable()
  573. {
  574. // 先上传到服务器文件
  575. if (\Yii::$app->request->isPost) {
  576. $excelImportId = \Yii::$app->request->post('excelImportId');
  577. $rowCount = \Yii::$app->request->post('rowCount');
  578. //$periodNum = \Yii::$app->request->post('periodNum');
  579. $orderMonth = \Yii::$app->request->post('orderMonth');
  580. // $orderType = \Yii::$app->request->post('orderType');
  581. $orderType = 'cash';
  582. $startRow = \Yii::$app->request->post('startRow');
  583. $limit = \Yii::$app->request->post('limit', 1000);
  584. $errorMsg = '';
  585. try {
  586. if( $startRow == 1 ) {
  587. //清空已经导入的表数据
  588. $excelOrderStandard = new ExcelOrderStandardForm();
  589. $excelOrderStandard->checkStatus($orderMonth);
  590. }
  591. $excel = new \common\helpers\Excel();
  592. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  593. } catch (Exception $e) {
  594. $result = false;
  595. $errorMsg = $e->getMessage();
  596. }
  597. // 还有数据
  598. if ($result === 1) {
  599. return static::notice(['finish' => false]);
  600. } elseif ($result === 0) {
  601. return static::notice(['finish' => true]);
  602. } else {
  603. return static::notice('发生错误:' . $errorMsg, 400);
  604. }
  605. }
  606. }
  607. /**
  608. * 达标订单导入完成标记
  609. * @return mixed
  610. * @throws \yii\web\HttpException
  611. */
  612. public function actionImportOrderStandard() {
  613. $orderMonth = \Yii::$app->request->post('orderMonth');
  614. $excelOrderStandard = new ExcelOrderStandardForm();
  615. $finishStatus = $excelOrderStandard->finished($orderMonth);
  616. if ($finishStatus) {
  617. return static::notice(['finish' => true]);
  618. } else {
  619. return static::notice('状态更新错误', 400);
  620. }
  621. }
  622. /**
  623. * 管理员发货
  624. * @return mixed
  625. * @throws \yii\web\HttpException
  626. */
  627. public function actionOrderDelivery() {
  628. if(\Yii::$app->request->isPost) {
  629. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  630. }
  631. return static::notice('非法请求', 400);
  632. }
  633. /*
  634. * 剩余BV页
  635. *
  636. */
  637. public function actionRemainPv()
  638. {
  639. $filter = $this->filterCondition([
  640. 'USER_NAME' => 'U.USER_NAME',
  641. ]);
  642. $condition = $filter['condition'];
  643. $params = $filter['params'];
  644. $listObj = new RemainPvList();
  645. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  646. return static::notice($data);
  647. }
  648. /*
  649. * 剩余BV流水
  650. *
  651. */
  652. public function actionFlowRemainPv()
  653. {
  654. $filter = $this->filterCondition([
  655. 'USER_NAME' => 'U.USER_NAME',
  656. ]);
  657. $condition = $filter['condition'];
  658. $params = $filter['params'];
  659. $listObj = new FlowRemainPvList();
  660. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  661. return static::notice($data);
  662. }
  663. /**
  664. * 订单详情
  665. * @return mixed
  666. * @throws \yii\web\HttpException
  667. */
  668. public function actionOrderDetail()
  669. {
  670. $orderSn = \Yii::$app->request->get('orderSn');
  671. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  672. if (!$order) {
  673. return static::notice('订单不存在', 400);
  674. }
  675. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? '首单' : '复消';
  676. // 如果当前订单所在期数已挂网,则不可调整
  677. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  678. if (!$period) {
  679. return static::notice('期数无效', 400);
  680. }
  681. if ($period['IS_SENT'] > 0) {
  682. return static::notice('订单已挂网', 400);
  683. }
  684. // 根据订单期数查询可调整期数
  685. $availablePeriod = [];
  686. if ($order['PERIOD_NUM']) {
  687. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  688. foreach ($availablePeriod as $k => $item) {
  689. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  690. }
  691. }
  692. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  693. }
  694. /**
  695. * 期数检查
  696. * @return mixed
  697. * @throws \yii\web\HttpException
  698. */
  699. public function actionPeriodInspect()
  700. {
  701. $modernPeriod = \Yii::$app->request->get('modernPeriod');
  702. $period = Period::getInfoByPeriodNum($modernPeriod);
  703. if (!$period) {
  704. return static::notice('期数不存在', 400);
  705. }
  706. if ($period['IS_SENT'] > 0) {
  707. return static::notice('调整后的期数已未挂网', 400);
  708. }
  709. }
  710. /**
  711. * 调整订单期数
  712. * @return mixed
  713. * @throws Exception
  714. * @throws \yii\db\Exception
  715. * @throws \yii\web\HttpException
  716. */
  717. public function actionOrderPeriodAdjust()
  718. {
  719. if (\Yii::$app->request->isPost) {
  720. $formModel = new OrderPeriodAdjustForm();
  721. $formModel->scenario = 'orderPeriodAdjust';
  722. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  723. return static::notice('成功');
  724. } else {
  725. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  726. }
  727. } else {
  728. $filter = $this->filterCondition([
  729. 'ORDER_SN' => 'P.ORDER_SN',
  730. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  731. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  732. 'CREATED_AT'=> 'P.CREATED_AT',
  733. ]);
  734. $listObj = new OrderPeriodAdjustList();
  735. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  736. return static::notice($data);
  737. }
  738. }
  739. public function actionOrderPeriodAdjustBatch()
  740. {
  741. // if (\Yii::$app->request->isPost) {
  742. $db = \Yii::$app->db;
  743. $transaction = $db->beginTransaction();
  744. $orderList = ['OS202408124810250102', 'OS202408125510154541', 'OS202408129710155101', 'OS202408129950985348', 'OS202408125153559954', 'OS202408125651509952', 'OS202408122632848244', 'OS202408122142828444', 'OS202408124332467022', 'OS202408123211846634', 'OS202408125704667483', 'OS202408124455418626', 'OS202408122717654666', 'OS202408120441445446', 'OS202408126815950310', 'OS202408128289488841', 'OS202408122459822888', 'OS202408126942458027', 'OS202408124366873315', 'OS202408121024910210', 'OS202408125710056531', 'OS202408125550100544', 'OS202408125498521021', 'OS202408129949994857', 'OS202408125054555354', 'OS202408125099501025', 'OS202408126671797982', 'OS202408129862232343', 'OS202408121498243182', 'OS202408126605496278', 'OS202408126152036612', 'OS202408121015557101', 'OS202408125610152505', 'OS202408125750521015', 'OS202408125557574856', 'OS202408125754525656', 'OS202408124856511029', 'OS202408121009799505', 'OS202408125010048505', 'OS202408125452989998', 'OS202408125749539848', 'OS202408125452545054', 'OS202408121005299100', 'OS202408125798102521', 'OS202408121001004855', 'OS202408125498101485', 'OS202408125210155525', 'OS202408125497974810', 'OS202408121005110210', 'OS202408125553511005', 'OS202408129956100521', 'OS202408129750102485', 'OS202408124855531011', 'OS202408121019910048', 'OS202408125110248569', 'OS202408125349985752', 'OS202408125797575748', 'OS202408125654975355', 'OS202408129810010252', 'OS202408125352575049', 'OS202408124810057575', 'OS202408129850525497', 'OS202408125553531019', 'OS202408125697535552', 'OS202408125297569755', 'OS202408125110198100', 'OS202408125548559997', 'OS202408129798525454', 'OS202408121005153999', 'OS202408129898559998', 'OS202408124949495755', 'OS202408124998521005', 'OS202408125654485710', 'OS202408125255975399', 'OS202408125454994949', 'OS202408129898525049', 'OS202408121025710098', 'OS202408121004810048', 'OS202408125453525653', 'OS202408124997985249', 'OS202408129752549750', 'OS202408121011014948', 'OS202408121025454509', 'OS202408129951985010', 'OS202408129750515349', 'OS202408125652529910', 'OS202408125699575054', 'OS202408126373959498', 'OS202408122855234468', 'OS202408129897999997', 'OS202408125198101509', 'OS202408125397481015', 'OS202408121025155569', 'OS202408121025797102', 'OS202408125149541021', 'OS202408125055501019', 'OS202408125710048101', 'OS202408125710050531', 'OS202408124910010051', 'OS202408125250519910', 'OS202408121024951495', 'OS202408120278963899', 'OS202408122468558358', 'OS202408128488898728', 'OS202408120668414449', 'OS202408122203908524', 'OS202408120842886466', 'OS202408125655971019', 'OS202408122864806084', 'OS202408125750534856', 'OS202408121015050975', 'OS202408128841334459', 'OS202408126548409724', 'OS202408123469880431', 'OS202408122139215963', 'OS202408124638848447', 'OS202408126610424679', 'OS202408127186683544', 'OS202408127213461201', 'OS202408126889501454', 'OS202408128235014016', 'OS202408123826968604', 'OS202408126324628624', 'OS202408125026200244', 'OS202408122671636578', 'OS202408122272420084', 'OS202408128421826164', 'OS202408129284082866', 'OS202408129951144421', 'OS202408122832368750', 'OS202408125633836704', 'OS202408126318481378', 'OS202408129062986684', 'OS202408126358961486', 'OS202408123033853388', 'OS202408124994261531', 'OS202408128289462234', 'OS202408128407101645', 'OS202408122786586662', 'OS202408125858809548', 'OS202408124850575553', 'OS202408125754535752', 'OS202408121005450515', 'OS202408129753515510', 'OS202408125153541029', 'OS202408121025497505', 'OS202408125656985555', 'OS202408121005649501', 'OS202408125756100991', 'OS202408129855565097', 'OS202408125310252491', 'OS202408125651100101', 'OS202408124953985156', 'OS202408125198525098', 'OS202408125657559852', 'OS202408125297981009', 'OS202408125210249985', 'OS202408125597525298', 'OS202408125250101505', 'OS202408124810097514', 'OS202408129899971005', 'OS202408125498545599', 'OS202408129910049509', 'OS202408125254101505', 'OS202408125197101541', 'OS202408121005249102', 'OS202408125656981029', 'OS202408125251495310', 'OS202408129951999798', 'OS202408129899100495', 'OS202408124948515248', 'OS202408125099579898', 'OS202408129955981009', 'OS202408125099511005', 'OS202408125010248579', 'OS202408129797575550', 'OS202408125456101514', 'OS202408124897525610', 'OS202408124898984855', 'OS202408121005654501', 'OS202408129857555348', 'OS202408124849989957', 'OS202408125056515610', 'OS202408125798100975', 'OS202408125450564898', 'OS202408124899515552', 'OS202408125657531004', 'OS202408125557561005', 'OS202408129850100991', 'OS202408121029855100', 'OS202408125010097575', 'OS202408125697535598', 'OS202408121025097491', 'OS202408129998102985', 'OS202408121025597555', 'OS202408124998979753', 'OS202408125449985310', 'OS202408125010155991', 'OS202408125051531005', 'OS202408125251102515', 'OS202408125350101975', 'OS202408125552101565', 'OS202408121015249515', 'OS202408129997100100', 'OS202408129999979848', 'OS202408125748539956', 'OS202408129952531001', 'OS202408125310098555', 'OS202408125455499850', 'OS202408124951501025', 'OS202408125555494955', 'OS202408125050574857', 'OS202408129948521015', 'OS202408125249101991', 'OS202408125699102991', 'OS202408121015599515', 'OS202408121029956529', 'OS202408125310057555', 'OS202408125410149525', 'OS202408125210154555', 'OS202408125252101515', 'OS202408121005157995', 'OS202408129851989910', 'OS202408125054531024', 'OS202408129849565399', 'OS202408125753519757', 'OS202408125156101979', 'OS202408125010010156', 'OS202408125698555010', 'OS202408125010053495', 'OS202408129853505010', 'OS202408129853534851', 'OS202408125398545110', 'OS202408129950101505', 'OS202408129950535757', 'OS202408125453975756', 'OS202408121025348534', 'OS202408121021001015', 'OS202408121011004897', 'OS202408125510049100', 'OS202408124856525252', 'OS202408129954975556', 'OS202408125597549853', 'OS202408125552565152', 'OS202408125097545354', 'OS202408125199531025', 'OS202408121021019757', 'OS202408125055575110', 'OS202408129756101535', 'OS202408125155101985', 'OS202408125055999810', 'OS202408124952554997', 'OS202408125097555597', 'OS202408125454541025', 'OS202408121015150545', 'OS202408125354102975', 'OS202408125357535356', 'OS202408125599501019', 'OS202408125410248499', 'OS202408121025651985', 'OS202408129952569797', 'OS202408129799985250', 'OS202408129849999999', 'OS202408125054539854', 'OS202408121015351574', 'OS202408125054545398', 'OS202408125253100989', 'OS202408125399575710', 'OS202408124681070152', 'OS202408124462194243', 'OS202408120425594620', 'OS202408124828680424', 'OS202408122868688902', 'OS202408126361869462', 'OS202408124822505150', 'OS202408127258081101', 'OS202408129444885180', 'OS202408122488221666', 'OS202408125883858578', 'OS202408120281842426', 'OS202408125866482622', 'OS202408121464468638', 'OS202408124485834920', 'OS202408129683286546', 'OS202408125799991019', 'OS202408129898100519', 'OS202408125098100101', 'OS202408129910054975', 'OS202408124854555453', 'OS202408125310249489', 'OS202408121011015749', 'OS202408125410154499', 'OS202408129754985756', 'OS202408125353485253', 'OS202408129710055535', 'OS202408128858023692', 'OS202408122284407634', 'OS202408121015648511', 'OS202408122026862936', 'OS202408120164243569', 'OS202408128184071952', 'OS202408120622725287', 'OS202408125054495553', 'OS202408128767496844', 'OS202408124892248462', 'OS202408127081682268', 'OS202408123144285829', 'OS202408124422125882', 'OS202408122384408102', 'OS202408129810250559', 'OS202408129749102555', 'OS202408121021015450'];
  745. $orderErr = [];
  746. try {
  747. $modernPeriod = 227;
  748. foreach ($orderList as $orderSn) {
  749. $orderObj = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  750. if (!$orderObj) {
  751. $orderErr[] = $orderSn;
  752. continue;
  753. }
  754. // 调整订单期数
  755. Order::updateAll(['PERIOD_NUM' => $modernPeriod], 'SN = :SN', [':SN' => $orderSn]);
  756. if ($orderObj['ORDER_TYPE'] === 'ZC') {
  757. // 调整报单期数
  758. DecOrder::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  759. // 调整会员的期数
  760. User::updateAll(['PERIOD_AT' => $modernPeriod], 'ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
  761. UserInfo::updateAll(['HIGHEST_EMP_LV_PERIOD' => $modernPeriod], 'USER_ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
  762. }
  763. // 调整流水的期数
  764. switch ($orderObj['PAY_TYPE']){
  765. case 'cash':
  766. FlowWallet::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  767. break;
  768. case 'point':
  769. FlowReconsumePoints::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  770. break;
  771. case 'exchange':
  772. FlowExchangePoints::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  773. break;
  774. default:
  775. break;
  776. }
  777. // 写入调整记录
  778. $orderModel = new OrderPeriodAdjust();
  779. $orderModel->ORDER_SN = $orderSn;
  780. $orderModel->ORIGIN_PERIOD = 224;
  781. $orderModel->MODERN_PERIOD = $modernPeriod;
  782. $orderModel->ADMIN_ID = '3rwvmynvct';
  783. $orderModel->CREATED_AT = Date::nowTime();
  784. if (!$orderModel->save()) {
  785. return static::notice($orderModel->getErrors(), 400);
  786. }
  787. }
  788. $transaction->commit();
  789. } catch(\Exception $e) {
  790. $transaction->rollBack();
  791. return static::notice($e->getMessage(), 400);
  792. }
  793. return static::notice('成功. ' . json_encode($orderErr));
  794. // }
  795. }
  796. }