ShopController.php 32 KB

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