ShopController.php 29 KB

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