ShopController.php 32 KB

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