ShopController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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\OrderExportForm;
  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\OrderShopList;
  16. use backendApi\modules\v1\models\lists\shop\OrderStandardList;
  17. use backendApi\modules\v1\models\lists\shop\PackageList;
  18. use common\helpers\Cache;
  19. use common\helpers\Date;
  20. use common\helpers\Form;
  21. use common\helpers\Log;
  22. use common\helpers\snowflake\SnowFake;
  23. use common\libs\export\module\ShopExport;
  24. use common\models\DeclarationPackage;
  25. use common\models\DecOrder;
  26. use common\models\ExcelOrderShop;
  27. use common\models\forms\DecPackageForm;
  28. use common\models\forms\ExcelOrderDecForm;
  29. use common\models\forms\ExcelOrderShopForm;
  30. use common\models\forms\ExcelOrderStandardForm;
  31. use common\models\forms\OrderDeleteForm;
  32. use common\models\forms\OrderForm;
  33. use common\models\forms\ShopGoodsForm;
  34. use common\models\forms\UploadForm;
  35. use common\models\ShopGoods;
  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 \yii\web\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 \yii\web\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('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  95. }
  96. /**
  97. * 添加商品
  98. * @return mixed
  99. * @throws Exception
  100. * @throws \yii\web\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 \yii\web\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 \yii\web\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 \yii\base\Exception
  180. * @throws \yii\db\Exception
  181. * @throws \yii\web\HttpException
  182. */
  183. public function actionOrderUpload(){
  184. if(\Yii::$app->request->isPost){
  185. $formModel = new UploadForm();
  186. $formModel->scenario = 'order';
  187. $formModel->file = UploadedFile::getInstanceByName('file');
  188. $formModel->token = \Yii::$app->request->request('uploadToken');
  189. if($formModel->file && $uploader = $formModel->upload()){
  190. return static::notice($uploader);
  191. } else {
  192. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  193. }
  194. } else {
  195. $token = Cache::setUploadToken();
  196. return static::notice($token);
  197. }
  198. }
  199. /**
  200. * 商品上下架
  201. * @return mixed
  202. * @throws Exception
  203. */
  204. public function actionGoodsStatus() {
  205. $id = \Yii::$app->request->get('id');
  206. if (\Yii::$app->request->isPost) {
  207. $formModel = new ShopGoodsForm();
  208. $formModel->scenario = 'changeStatus';
  209. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  210. // foreach ($result['logs'] as $k => $value) {
  211. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  212. // }
  213. return static::notice('Status setting succeeded'); // 状态设置成功
  214. } else {
  215. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  216. }
  217. }
  218. }
  219. /**
  220. * 删除商品
  221. * @return mixed
  222. * @throws \yii\db\Exception
  223. * @throws \yii\web\HttpException
  224. */
  225. public function actionGoodsDelete(){
  226. $result = static::delete(ShopGoods::class);
  227. return $result;
  228. }
  229. /**
  230. * 套餐列表
  231. * @return mixed
  232. * @throws Exception
  233. * @throws \yii\web\HttpException
  234. */
  235. public function actionPackage() {
  236. $filter = $this->filterCondition([
  237. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  238. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  239. 'AMOUNT'=> 'DP.AMOUNT',
  240. 'PV'=> 'DP.PV',
  241. 'STATUS'=> 'DP.STATUS',
  242. 'STORE_NUMS'=>'DP.STORE_NUMS',
  243. ]);
  244. $condition = $filter['condition'];
  245. $params = $filter['params'];
  246. $condition .= ' AND DP.IS_DEL=0';
  247. $listObj = new PackageList();
  248. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  249. return static::notice($data);
  250. }
  251. /**
  252. * 添加报单套餐
  253. * @return mixed
  254. * @throws \yii\web\HttpException
  255. */
  256. public function actionPackageAdd() {
  257. if (\Yii::$app->request->isPost) {
  258. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  259. // Log::adminHandle('添加报单套餐', 1);
  260. });
  261. }
  262. return static::notice('非发请求', 405);
  263. }
  264. /**
  265. * 报单套餐获取
  266. * @return mixed
  267. * @throws \yii\web\HttpException
  268. */
  269. public function actionPackageGet() {
  270. $id = \Yii::$app->request->get('id');
  271. if (\Yii::$app->request->isPost) {
  272. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  273. // Log::adminHandle('编辑报单套餐', 1);
  274. });
  275. }
  276. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  277. 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']]);
  278. }
  279. /**
  280. * 套餐上下架
  281. * @return mixed
  282. * @throws Exception
  283. */
  284. public function actionPackageStatus() {
  285. $id = \Yii::$app->request->get('id');
  286. if (\Yii::$app->request->isPost) {
  287. $formModel = new DecPackageForm();
  288. $formModel->scenario = 'changeStatus';
  289. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  290. return static::notice('Status setting succeeded'); // 状态设置成功
  291. } else {
  292. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  293. }
  294. }
  295. }
  296. /**
  297. * 删除套餐
  298. * @return mixed
  299. * @throws \yii\db\Exception
  300. * @throws \yii\web\HttpException
  301. */
  302. public function actionPackageDelete(){
  303. $result = static::delete(DeclarationPackage::class);
  304. return $result;
  305. }
  306. /**
  307. * 报单表
  308. * @return mixed
  309. * @throws Exception
  310. * @throws \yii\web\HttpException
  311. */
  312. public function actionDecOrderList() {
  313. $filter = $this->filterCondition([
  314. 'DEC_SN'=> 'DO.DEC_SN',
  315. 'ORDER_SN'=> 'DO.ORDER_SN',
  316. 'USER_NAME'=> 'U.USER_NAME',
  317. 'TO_USER_NAME'=> 'TU.USER_NAME',
  318. 'REAL_NAME'=> 'TU.REAL_NAME',
  319. 'ID_CARD'=> 'TU.ID_CARD',
  320. 'MOBILE'=> 'TU.MOBILE',
  321. 'DEC_LV_NAME' => 'TU.DEC_LV',
  322. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  323. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  324. 'DEC_PV'=> 'DO.DEC_PV',
  325. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  326. 'REC_USER_NAME'=> 'RU.USER_NAME',
  327. 'CREATED_AT'=> 'DO.CREATED_AT',
  328. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  329. ]);
  330. $condition = $filter['condition'];
  331. $params = $filter['params'];
  332. $condition .= ' AND DO.IS_DEL=0';
  333. $listObj = new DecOrderList();
  334. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  335. return static::notice($data);
  336. }
  337. /**
  338. * 报单表导出
  339. * @return mixed
  340. * @throws \yii\db\Exception
  341. * @throws \yii\web\HttpException
  342. */
  343. public function actionDecOrderListExport()
  344. {
  345. $filter = $this->filterCondition([
  346. 'DEC_SN'=> 'DO.DEC_SN',
  347. 'ORDER_SN'=> 'DO.ORDER_SN',
  348. 'USER_NAME'=> 'U.USER_NAME',
  349. 'TO_USER_NAME'=> 'TU.USER_NAME',
  350. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  351. 'DEC_PV'=> 'DO.DEC_PV',
  352. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  353. 'CREATED_AT'=> 'DO.CREATED_AT',
  354. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  355. ]);
  356. $filter['condition'] .= ' AND DO.IS_DEL=0';
  357. $form = new ShopExportForm();
  358. $result = $form->run($filter, '报单列表');
  359. if (!$result) {
  360. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  361. }
  362. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  363. }
  364. // 删除订单
  365. public function actionDeleteOrder() {
  366. if (\Yii::$app->request->isPost) {
  367. $formModel = new OrderDeleteForm();
  368. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  369. return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
  370. } else {
  371. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  372. }
  373. }
  374. }
  375. /**
  376. * 订单表
  377. * @return mixed
  378. * @throws Exception
  379. * @throws \yii\web\HttpException
  380. */
  381. public function actionOrderList() {
  382. $filter = $this->filterCondition([
  383. 'SN'=> 'O.SN',
  384. 'USER_NAME'=> 'U.USER_NAME',
  385. 'MOBILE'=> 'O.MOBILE',
  386. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  387. 'CREATED_AT'=> 'O.CREATED_AT',
  388. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  389. 'STATUS' => 'O.STATUS',
  390. 'IS_AUTO' => 'O.IS_AUTO'
  391. ]);
  392. $condition = ' 1=1 ' . $filter['condition'];
  393. $params = $filter['params'];
  394. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  395. $listObj = new OrderList();
  396. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  397. return static::notice($data);
  398. }
  399. /**
  400. * 订单表导出
  401. * @return mixed
  402. * @throws \yii\db\Exception
  403. * @throws \yii\web\HttpException
  404. */
  405. public function actionOrderListExport()
  406. {
  407. $filter = $this->filterCondition([
  408. 'SN'=> 'O.SN',
  409. 'USER_NAME'=> 'U.USER_NAME',
  410. 'MOBILE'=> 'O.MOBILE',
  411. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  412. 'CREATED_AT'=> 'O.CREATED_AT',
  413. ]);
  414. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  415. $form = new ShopExportForm();
  416. $result = $form->run($filter, 'Order_List'); // 订单列表
  417. if (!$result) {
  418. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  419. }
  420. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  421. }
  422. /**
  423. * 外部商城订单列表
  424. * @return mixed
  425. * @throws Exception
  426. * @throws \yii\web\HttpException
  427. */
  428. public function actionOrderShopList() {
  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 OrderShopList();
  439. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  440. return static::notice($data);
  441. }
  442. /**
  443. * 外部商城报单列表
  444. * @return mixed
  445. * @throws Exception
  446. * @throws \yii\web\HttpException
  447. */
  448. public function actionOrderDecList() {
  449. $filter = $this->filterCondition([
  450. 'SN'=> 'O.SN',
  451. 'USER_NAME'=> 'U.USER_NAME',
  452. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  453. 'CREATED_AT'=> 'O.CREATED_AT',
  454. ]);
  455. $condition = $filter['condition'];
  456. $params = $filter['params'];
  457. $condition .= ' 1=1 AND O.IS_DELETE=0';
  458. $listObj = new OrderDecList();
  459. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  460. return static::notice($data);
  461. }
  462. /**
  463. * 分页导入excel文件到待导入数据的表中
  464. * @return mixed
  465. */
  466. public function actionImportOrderShopToExcelTable()
  467. {
  468. // 先上传到服务器文件
  469. if (\Yii::$app->request->isPost) {
  470. $excelImportId = \Yii::$app->request->post('excelImportId');
  471. $rowCount = \Yii::$app->request->post('rowCount');
  472. //$periodNum = \Yii::$app->request->post('periodNum');
  473. $orderDay = \Yii::$app->request->post('orderDay');
  474. $orderType = \Yii::$app->request->post('orderType');
  475. $startRow = \Yii::$app->request->post('startRow');
  476. $limit = \Yii::$app->request->post('limit', 1000);
  477. $errorMsg = '';
  478. try {
  479. if( $startRow == 1 ) {
  480. $excelOrderShop = new ExcelOrderShopForm();
  481. $excelOrderShop->checkStatus($orderDay,$orderType);
  482. }
  483. $excel = new \common\helpers\Excel();
  484. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  485. } catch (\Exception $e) {
  486. $result = false;
  487. $errorMsg = $e->getMessage();
  488. }
  489. // 还有数据
  490. if ($result === 1) {
  491. return static::notice(['finish' => false]);
  492. } elseif ($result === 0) {
  493. return static::notice(['finish' => true]);
  494. } else {
  495. return static::notice('发生错误:' . $errorMsg, 400);
  496. }
  497. }
  498. }
  499. /**
  500. * 导入完成标记
  501. * @return mixed
  502. * @throws \yii\web\HttpException
  503. */
  504. public function actionImportOrderShop() {
  505. //$periodNum = \Yii::$app->request->post('periodNum');
  506. $orderDay = \Yii::$app->request->post('orderDay');
  507. $orderType = \Yii::$app->request->post('orderType');
  508. $excelOrderShop = new ExcelOrderShopForm();
  509. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  510. if ($finishStatus) {
  511. return static::notice(['finish' => true]);
  512. } else {
  513. return static::notice('状态更新错误', 400);
  514. }
  515. }
  516. /**
  517. * 报单订单——分页导入excel文件到待导入数据的表中
  518. * @return mixed
  519. */
  520. public function actionImportOrderDecToExcelTable()
  521. {
  522. // 先上传到服务器文件
  523. if (\Yii::$app->request->isPost) {
  524. $excelImportId = \Yii::$app->request->post('excelImportId');
  525. $rowCount = \Yii::$app->request->post('rowCount');
  526. //$periodNum = \Yii::$app->request->post('periodNum');
  527. $orderDay = \Yii::$app->request->post('orderDay');
  528. $startRow = \Yii::$app->request->post('startRow');
  529. $limit = \Yii::$app->request->post('limit', 1000);
  530. $errorMsg = '';
  531. try {
  532. if( $startRow == 1 ) {
  533. $excelOrderShop = new ExcelOrderDecForm();
  534. $excelOrderShop->checkStatus($orderDay);
  535. }
  536. $excel = new \common\helpers\Excel();
  537. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  538. } catch (\Exception $e) {
  539. $result = false;
  540. $errorMsg = $e->getMessage();
  541. }
  542. // 还有数据
  543. if ($result === 1) {
  544. return static::notice(['finish' => false]);
  545. } elseif ($result === 0) {
  546. return static::notice(['finish' => true]);
  547. } else {
  548. return static::notice('发生错误:' . $errorMsg, 400);
  549. }
  550. }
  551. }
  552. /**
  553. * 报单订单导入完成标记
  554. * @return mixed
  555. * @throws \yii\web\HttpException
  556. */
  557. public function actionImportOrderDec() {
  558. //$periodNum = \Yii::$app->request->post('periodNum');
  559. $orderDay = \Yii::$app->request->post('orderDay');
  560. $excelOrderShop = new ExcelOrderDecForm();
  561. $finishStatus = $excelOrderShop->finished($orderDay);
  562. if ($finishStatus) {
  563. return static::notice(['finish' => true]);
  564. } else {
  565. return static::notice('状态更新错误', 400);
  566. }
  567. }
  568. /**
  569. * 见习达标订单列表
  570. * @return mixed
  571. * @throws Exception
  572. * @throws \yii\web\HttpException
  573. */
  574. public function actionOrderStandardList() {
  575. $filter = $this->filterCondition([
  576. 'SN'=> 'O.SN',
  577. 'USER_NAME'=> 'U.USER_NAME',
  578. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  579. 'CREATED_AT'=> 'O.CREATED_AT',
  580. ]);
  581. $condition = $filter['condition'];
  582. $params = $filter['params'];
  583. $condition .= ' AND O.IS_DELETE=0';
  584. $listObj = new OrderStandardList();
  585. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  586. return static::notice($data);
  587. }
  588. /**
  589. * 分页导入excel文件到待导入数据的表中
  590. * @return mixed
  591. * @throws \yii\web\HttpException
  592. */
  593. public function actionImportOrderStandardToExcelTable()
  594. {
  595. // 先上传到服务器文件
  596. if (\Yii::$app->request->isPost) {
  597. $excelImportId = \Yii::$app->request->post('excelImportId');
  598. $rowCount = \Yii::$app->request->post('rowCount');
  599. //$periodNum = \Yii::$app->request->post('periodNum');
  600. $orderMonth = \Yii::$app->request->post('orderMonth');
  601. // $orderType = \Yii::$app->request->post('orderType');
  602. $orderType = 'cash';
  603. $startRow = \Yii::$app->request->post('startRow');
  604. $limit = \Yii::$app->request->post('limit', 1000);
  605. $errorMsg = '';
  606. try {
  607. if( $startRow == 1 ) {
  608. //清空已经导入的表数据
  609. $excelOrderStandard = new ExcelOrderStandardForm();
  610. $excelOrderStandard->checkStatus($orderMonth);
  611. }
  612. $excel = new \common\helpers\Excel();
  613. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  614. } catch (Exception $e) {
  615. $result = false;
  616. $errorMsg = $e->getMessage();
  617. }
  618. // 还有数据
  619. if ($result === 1) {
  620. return static::notice(['finish' => false]);
  621. } elseif ($result === 0) {
  622. return static::notice(['finish' => true]);
  623. } else {
  624. return static::notice('发生错误:' . $errorMsg, 400);
  625. }
  626. }
  627. }
  628. /**
  629. * 达标订单导入完成标记
  630. * @return mixed
  631. * @throws \yii\web\HttpException
  632. */
  633. public function actionImportOrderStandard() {
  634. $orderMonth = \Yii::$app->request->post('orderMonth');
  635. $excelOrderStandard = new ExcelOrderStandardForm();
  636. $finishStatus = $excelOrderStandard->finished($orderMonth);
  637. if ($finishStatus) {
  638. return static::notice(['finish' => true]);
  639. } else {
  640. return static::notice('状态更新错误', 400);
  641. }
  642. }
  643. /**
  644. * 管理员发货
  645. * @return mixed
  646. * @throws \yii\web\HttpException
  647. */
  648. public function actionOrderDelivery() {
  649. if(\Yii::$app->request->isPost) {
  650. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  651. }
  652. return static::notice('Illegal request', 400); // 非法请求
  653. }
  654. /**
  655. * 报单表导出
  656. * @return mixed
  657. * @throws \yii\db\Exception
  658. * @throws \yii\web\HttpException
  659. */
  660. public function actionOrderListExportPdf()
  661. {
  662. $orderSn = \Yii::$app->request->get('orderSn');
  663. $filter = $this->filterCondition([
  664. 'SN'=> 'O.SN',
  665. 'USER_NAME'=> 'U.USER_NAME',
  666. 'MOBILE'=> 'O.MOBILE',
  667. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  668. 'CREATED_AT'=> 'O.CREATED_AT',
  669. ]);
  670. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  671. $filter['params'] = [':SN' => $orderSn];
  672. $form = new ShopExportForm();
  673. $result = $form->run($filter, '订单列表');
  674. if (!$result) {
  675. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  676. }
  677. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  678. }
  679. /**
  680. * 报单表导出
  681. * @return mixed
  682. * @throws \yii\db\Exception
  683. * @throws \yii\web\HttpException
  684. */
  685. public function actionDecOrderListExportPdf()
  686. {
  687. $orderSn = \Yii::$app->request->get('orderSn');
  688. $filter = $this->filterCondition([
  689. 'SN'=> 'O.SN',
  690. 'USER_NAME'=> 'U.USER_NAME',
  691. 'MOBILE'=> 'O.MOBILE',
  692. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  693. 'CREATED_AT'=> 'O.CREATED_AT',
  694. ]);
  695. $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
  696. $filter['params'] = [':SN' => $orderSn];
  697. $form = new ShopExportForm();
  698. $result = $form->run($filter, '订单列表');
  699. if (!$result) {
  700. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  701. }
  702. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  703. }
  704. /**
  705. * 管理员订单退款
  706. * @return mixed
  707. * @throws \yii\web\HttpException
  708. */
  709. public function actionOrderRefund()
  710. {
  711. if(\Yii::$app->request->isPost) {
  712. return parent::edit(OrderForm::class, '退款成功', 'adminRefund', ['adminRefund']);
  713. }
  714. return static::notice('Illegal request', 400); // 非法请求
  715. }
  716. }