ShopController.php 29 KB

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