ShopController.php 29 KB

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