ShopController.php 27 KB

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