ShopController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  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. 'COUNTRY' => 'O.COUNTRY_ID',
  381. 'IS_AUTO' => 'O.IS_AUTO'
  382. ]);
  383. $condition = ' 1=1 ' . $filter['condition'];
  384. $params = $filter['params'];
  385. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  386. $listObj = new OrderList();
  387. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  388. return static::notice($data);
  389. }
  390. /**
  391. * 订单表导出
  392. * @return mixed
  393. * @throws \yii\db\Exception
  394. * @throws HttpException
  395. */
  396. public function actionOrderListExport()
  397. {
  398. $filter = $this->filterCondition([
  399. 'SN'=> 'O.SN',
  400. 'USER_NAME'=> 'U.USER_NAME',
  401. 'MOBILE'=> 'O.MOBILE',
  402. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  403. 'CREATED_AT'=> 'O.CREATED_AT',
  404. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  405. 'STATUS' => 'O.STATUS',
  406. 'IS_AUTO' => 'O.IS_AUTO'
  407. ]);
  408. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  409. $form = new ShopExportForm();
  410. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExport')); // 订单列表
  411. if (!$result) {
  412. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  413. }
  414. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  415. }
  416. /**
  417. * 外部商城订单列表
  418. * @return mixed
  419. * @throws Exception
  420. * @throws HttpException
  421. */
  422. public function actionOrderShopList() {
  423. $filter = $this->filterCondition([
  424. 'SN'=> 'O.SN',
  425. 'USER_NAME'=> 'U.USER_NAME',
  426. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  427. 'CREATED_AT'=> 'O.CREATED_AT',
  428. ]);
  429. $condition = $filter['condition'];
  430. $params = $filter['params'];
  431. $condition .= ' AND O.IS_DELETE=0';
  432. $listObj = new OrderShopList();
  433. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  434. return static::notice($data);
  435. }
  436. /**
  437. * 外部商城报单列表
  438. * @return mixed
  439. * @throws Exception
  440. * @throws HttpException
  441. */
  442. public function actionOrderDecList() {
  443. $filter = $this->filterCondition([
  444. 'SN'=> 'O.SN',
  445. 'USER_NAME'=> 'U.USER_NAME',
  446. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  447. 'CREATED_AT'=> 'O.CREATED_AT',
  448. ]);
  449. $condition = $filter['condition'];
  450. $params = $filter['params'];
  451. $condition .= ' AND O.IS_DELETE=0';
  452. $listObj = new OrderDecList();
  453. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  454. return static::notice($data);
  455. }
  456. /**
  457. * 分页导入excel文件到待导入数据的表中
  458. * @return mixed
  459. */
  460. public function actionImportOrderShopToExcelTable()
  461. {
  462. // 先上传到服务器文件
  463. if (\Yii::$app->request->isPost) {
  464. $excelImportId = \Yii::$app->request->post('excelImportId');
  465. $rowCount = \Yii::$app->request->post('rowCount');
  466. //$periodNum = \Yii::$app->request->post('periodNum');
  467. $orderDay = \Yii::$app->request->post('orderDay');
  468. $orderType = \Yii::$app->request->post('orderType');
  469. $startRow = \Yii::$app->request->post('startRow');
  470. $limit = \Yii::$app->request->post('limit', 1000);
  471. $errorMsg = '';
  472. try {
  473. if( $startRow == 1 ) {
  474. $excelOrderShop = new ExcelOrderShopForm();
  475. $excelOrderShop->checkStatus($orderDay,$orderType);
  476. }
  477. $excel = new \common\helpers\Excel();
  478. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  479. } catch (\Exception $e) {
  480. $result = false;
  481. $errorMsg = $e->getMessage();
  482. }
  483. // 还有数据
  484. if ($result === 1) {
  485. return static::notice(['finish' => false]);
  486. } elseif ($result === 0) {
  487. return static::notice(['finish' => true]);
  488. } else {
  489. return static::notice('Error:' . $errorMsg, 400);
  490. }
  491. }
  492. }
  493. /**
  494. * 导入完成标记
  495. * @return mixed
  496. * @throws HttpException
  497. */
  498. public function actionImportOrderShop() {
  499. //$periodNum = \Yii::$app->request->post('periodNum');
  500. $orderDay = \Yii::$app->request->post('orderDay');
  501. $orderType = \Yii::$app->request->post('orderType');
  502. $excelOrderShop = new ExcelOrderShopForm();
  503. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  504. if ($finishStatus) {
  505. return static::notice(['finish' => true]);
  506. } else {
  507. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  508. }
  509. }
  510. /**
  511. * 报单订单——分页导入excel文件到待导入数据的表中
  512. * @return mixed
  513. */
  514. public function actionImportOrderDecToExcelTable()
  515. {
  516. // 先上传到服务器文件
  517. if (\Yii::$app->request->isPost) {
  518. $excelImportId = \Yii::$app->request->post('excelImportId');
  519. $rowCount = \Yii::$app->request->post('rowCount');
  520. //$periodNum = \Yii::$app->request->post('periodNum');
  521. $orderDay = \Yii::$app->request->post('orderDay');
  522. $startRow = \Yii::$app->request->post('startRow');
  523. $limit = \Yii::$app->request->post('limit', 1000);
  524. $errorMsg = '';
  525. try {
  526. if( $startRow == 1 ) {
  527. $excelOrderShop = new ExcelOrderDecForm();
  528. $excelOrderShop->checkStatus($orderDay);
  529. }
  530. $excel = new \common\helpers\Excel();
  531. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  532. } catch (\Exception $e) {
  533. $result = false;
  534. $errorMsg = $e->getMessage();
  535. }
  536. // 还有数据
  537. if ($result === 1) {
  538. return static::notice(['finish' => false]);
  539. } elseif ($result === 0) {
  540. return static::notice(['finish' => true]);
  541. } else {
  542. return static::notice('Error:' . $errorMsg, 400);
  543. }
  544. }
  545. }
  546. /**
  547. * 报单订单导入完成标记
  548. * @return mixed
  549. * @throws HttpException
  550. */
  551. public function actionImportOrderDec() {
  552. //$periodNum = \Yii::$app->request->post('periodNum');
  553. $orderDay = \Yii::$app->request->post('orderDay');
  554. $excelOrderShop = new ExcelOrderDecForm();
  555. $finishStatus = $excelOrderShop->finished($orderDay);
  556. if ($finishStatus) {
  557. return static::notice(['finish' => true]);
  558. } else {
  559. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  560. }
  561. }
  562. /**
  563. * 见习达标订单列表
  564. * @return mixed
  565. * @throws Exception
  566. * @throws HttpException
  567. */
  568. public function actionOrderStandardList() {
  569. $filter = $this->filterCondition([
  570. 'SN'=> 'O.SN',
  571. 'USER_NAME'=> 'U.USER_NAME',
  572. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  573. 'CREATED_AT'=> 'O.CREATED_AT',
  574. ]);
  575. $condition = $filter['condition'];
  576. $params = $filter['params'];
  577. $condition .= ' AND O.IS_DELETE=0';
  578. $listObj = new OrderStandardList();
  579. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  580. return static::notice($data);
  581. }
  582. /**
  583. * 分页导入excel文件到待导入数据的表中
  584. * @return mixed
  585. * @throws HttpException
  586. */
  587. public function actionImportOrderStandardToExcelTable()
  588. {
  589. // 先上传到服务器文件
  590. if (\Yii::$app->request->isPost) {
  591. $excelImportId = \Yii::$app->request->post('excelImportId');
  592. $rowCount = \Yii::$app->request->post('rowCount');
  593. //$periodNum = \Yii::$app->request->post('periodNum');
  594. $orderMonth = \Yii::$app->request->post('orderMonth');
  595. // $orderType = \Yii::$app->request->post('orderType');
  596. $orderType = 'cash';
  597. $startRow = \Yii::$app->request->post('startRow');
  598. $limit = \Yii::$app->request->post('limit', 1000);
  599. $errorMsg = '';
  600. try {
  601. if( $startRow == 1 ) {
  602. //清空已经导入的表数据
  603. $excelOrderStandard = new ExcelOrderStandardForm();
  604. $excelOrderStandard->checkStatus($orderMonth);
  605. }
  606. $excel = new \common\helpers\Excel();
  607. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  608. } catch (Exception $e) {
  609. $result = false;
  610. $errorMsg = $e->getMessage();
  611. }
  612. // 还有数据
  613. if ($result === 1) {
  614. return static::notice(['finish' => false]);
  615. } elseif ($result === 0) {
  616. return static::notice(['finish' => true]);
  617. } else {
  618. return static::notice('Error:' . $errorMsg, 400);
  619. }
  620. }
  621. }
  622. /**
  623. * 达标订单导入完成标记
  624. * @return mixed
  625. * @throws HttpException
  626. */
  627. public function actionImportOrderStandard() {
  628. $orderMonth = \Yii::$app->request->post('orderMonth');
  629. $excelOrderStandard = new ExcelOrderStandardForm();
  630. $finishStatus = $excelOrderStandard->finished($orderMonth);
  631. if ($finishStatus) {
  632. return static::notice(['finish' => true]);
  633. } else {
  634. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  635. }
  636. }
  637. /**
  638. * 管理员发货
  639. * @return mixed
  640. * @throws HttpException
  641. */
  642. public function actionOrderDelivery() {
  643. if(\Yii::$app->request->isPost) {
  644. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  645. }
  646. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  647. }
  648. /**
  649. * 报单表导出
  650. * @return mixed
  651. * @throws \yii\db\Exception
  652. * @throws HttpException
  653. */
  654. public function actionOrderListExportPdf()
  655. {
  656. $orderSn = \Yii::$app->request->get('orderSn');
  657. $filter = $this->filterCondition([
  658. 'SN'=> 'O.SN',
  659. 'USER_NAME'=> 'U.USER_NAME',
  660. 'MOBILE'=> 'O.MOBILE',
  661. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  662. 'CREATED_AT'=> 'O.CREATED_AT',
  663. ]);
  664. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  665. $filter['params'] = [':SN' => $orderSn];
  666. $form = new ShopExportForm();
  667. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  668. if (!$result) {
  669. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  670. }
  671. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  672. }
  673. /**
  674. * 报单表导出
  675. * @return mixed
  676. * @throws \yii\db\Exception
  677. * @throws HttpException
  678. */
  679. public function actionDecOrderListExportPdf()
  680. {
  681. $orderSn = \Yii::$app->request->get('orderSn');
  682. $filter = $this->filterCondition([
  683. 'SN'=> 'O.SN',
  684. 'USER_NAME'=> 'U.USER_NAME',
  685. 'MOBILE'=> 'O.MOBILE',
  686. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  687. 'CREATED_AT'=> 'O.CREATED_AT',
  688. ]);
  689. $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
  690. $filter['params'] = [':SN' => $orderSn];
  691. $form = new ShopExportForm();
  692. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  693. if (!$result) {
  694. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  695. }
  696. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  697. }
  698. /**
  699. * 管理员订单退款
  700. * @return mixed
  701. * @throws HttpException
  702. */
  703. public function actionOrderRefund()
  704. {
  705. if(\Yii::$app->request->isPost) {
  706. return parent::edit(OrderForm::class, \Yii::t('ctx', 'shopadminRefund'), 'adminRefund', ['adminRefund']);
  707. }
  708. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  709. }
  710. /*
  711. * 剩余BV页
  712. *
  713. */
  714. public function actionRemainPv()
  715. {
  716. $filter = $this->filterCondition([
  717. 'USER_NAME' => 'U.USER_NAME',
  718. ]);
  719. $condition = $filter['condition'];
  720. $params = $filter['params'];
  721. $listObj = new RemainPvList();
  722. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  723. return static::notice($data);
  724. }
  725. /*
  726. * 剩余BV流水
  727. *
  728. */
  729. public function actionFlowRemainPv()
  730. {
  731. $filter = $this->filterCondition([
  732. 'USER_NAME' => 'U.USER_NAME',
  733. ]);
  734. $condition = $filter['condition'];
  735. $params = $filter['params'];
  736. $listObj = new FlowRemainPvList();
  737. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  738. return static::notice($data);
  739. }
  740. /**
  741. * BA订单表
  742. * @return mixed
  743. * @throws Exception
  744. * @throws HttpException
  745. */
  746. public function actionBaOrderList() {
  747. $filter = $this->filterCondition([
  748. 'SN'=> 'O.SN',
  749. 'USER_NAME'=> 'U.USER_NAME',
  750. 'MOBILE'=> 'O.MOBILE',
  751. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  752. 'CREATED_AT'=> 'O.CREATED_AT',
  753. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  754. 'STATUS' => 'O.STATUS',
  755. ]);
  756. $condition = ' 1=1 ' . $filter['condition'];
  757. $params = $filter['params'];
  758. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  759. $listObj = new BaOrderList();
  760. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  761. return static::notice($data);
  762. }
  763. /**
  764. * BA订单表导出
  765. * @return mixed
  766. * @throws \yii\db\Exception
  767. * @throws HttpException
  768. */
  769. public function actionBaOrderListExport()
  770. {
  771. $filter = $this->filterCondition([
  772. 'SN'=> 'O.SN',
  773. 'USER_NAME'=> 'U.USER_NAME',
  774. 'MOBILE'=> 'O.MOBILE',
  775. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  776. 'CREATED_AT'=> 'O.CREATED_AT',
  777. 'STATUS' => 'O.STATUS',
  778. ]);
  779. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  780. $form = new BaShopExportForm();
  781. $result = $form->run($filter, \Yii::t('ctx', 'shopBaOrderListExport')); // 订单列表
  782. if (!$result) {
  783. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  784. }
  785. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  786. }
  787. /**
  788. * 报单表导出
  789. * @return mixed
  790. * @throws \yii\db\Exception
  791. * @throws HttpException
  792. */
  793. public function actionBaOrderListExportPdf()
  794. {
  795. $orderSn = \Yii::$app->request->get('orderSn');
  796. $filter = $this->filterCondition([
  797. 'SN'=> 'O.SN',
  798. 'USER_NAME'=> 'U.USER_NAME',
  799. 'MOBILE'=> 'O.MOBILE',
  800. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  801. 'CREATED_AT'=> 'O.CREATED_AT',
  802. ]);
  803. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  804. $filter['params'] = [':SN' => $orderSn];
  805. $form = new BaShopExportForm();
  806. $result = $form->run($filter, \Yii::t('ctx', 'shopBrandAmbassadorOrderExport'));
  807. if (!$result) {
  808. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  809. }
  810. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  811. }
  812. /**
  813. * 调整订单期数
  814. * @return mixed
  815. * @throws Exception
  816. * @throws \yii\db\Exception
  817. * @throws \yii\web\HttpException
  818. */
  819. public function actionOrderPeriodAdjust()
  820. {
  821. if (\Yii::$app->request->isPost) {
  822. $formModel = new OrderPeriodAdjustForm();
  823. $formModel->scenario = 'orderPeriodAdjust';
  824. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  825. return static::notice(Yii::t('ctx', 'successfully'));
  826. } else {
  827. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  828. }
  829. } else {
  830. $filter = $this->filterCondition([
  831. 'ORDER_SN' => 'P.ORDER_SN',
  832. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  833. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  834. 'CREATED_AT'=> 'P.CREATED_AT',
  835. ]);
  836. $listObj = new OrderPeriodAdjustList();
  837. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  838. return static::notice($data);
  839. }
  840. }
  841. /**
  842. * 订单详情
  843. * @return mixed
  844. * @throws \yii\web\HttpException
  845. */
  846. public function actionOrderDetail()
  847. {
  848. $orderSn = \Yii::$app->request->get('orderSn');
  849. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  850. if (!$order) {
  851. return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
  852. }
  853. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? Yii::t('ctx', 'shopOrderListOrderTypeZc') : Yii::t('ctx', 'shopOrderListOrderTypeFx');
  854. // 如果当前订单所在期数已挂网,则不可调整
  855. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  856. if (!$period) {
  857. return static::notice(Yii::t('ctx', 'invalidPcNo'), 400);
  858. }
  859. if ($period['IS_SENT'] > 0) {
  860. return static::notice(Yii::t('ctx', 'orderHasBeenConnected'), 400);
  861. }
  862. // 根据订单期数查询可调整期数
  863. $availablePeriod = [];
  864. if ($order['PERIOD_NUM']) {
  865. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  866. foreach ($availablePeriod as $k => $item) {
  867. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  868. }
  869. }
  870. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  871. }
  872. }