ShopController.php 28 KB

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