ShopController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  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\exportForms\BaUserExportForm;
  12. use backendApi\modules\v1\models\lists\shop\DecOrderList;
  13. use backendApi\modules\v1\models\lists\shop\GoodsList;
  14. use backendApi\modules\v1\models\lists\shop\OrderDecList;
  15. use backendApi\modules\v1\models\lists\shop\OrderList;
  16. use backendApi\modules\v1\models\lists\shop\BaOrderList;
  17. use backendApi\modules\v1\models\lists\shop\BaUserList;
  18. use backendApi\modules\v1\models\lists\shop\OrderShopList;
  19. use backendApi\modules\v1\models\lists\shop\OrderStandardList;
  20. use backendApi\modules\v1\models\lists\shop\PackageList;
  21. use backendApi\modules\v1\models\lists\shop\RemainPvList;
  22. use backendApi\modules\v1\models\lists\shop\FlowRemainPvList;
  23. use common\helpers\Cache;
  24. use common\helpers\Date;
  25. use common\helpers\Form;
  26. use common\helpers\Log;
  27. use common\helpers\snowflake\SnowFake;
  28. use common\libs\export\module\ShopExport;
  29. use common\models\DeclarationPackage;
  30. use common\models\DecOrder;
  31. use common\models\ExcelOrderShop;
  32. use common\models\forms\DecPackageForm;
  33. use common\models\forms\ExcelOrderDecForm;
  34. use common\models\forms\ExcelOrderShopForm;
  35. use common\models\forms\ExcelOrderStandardForm;
  36. use common\models\forms\OrderDeleteForm;
  37. use common\models\forms\OrderForm;
  38. use common\models\forms\ShopGoodsForm;
  39. use common\models\forms\UploadForm;
  40. use common\models\ShopGoods;
  41. use yii\web\UploadedFile;
  42. use yii\base\Exception;
  43. class ShopController extends BaseController {
  44. public $modelClass = DecOrder::class;
  45. public function behaviors() {
  46. $behaviors = parent::behaviors();
  47. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  48. return $behaviors;
  49. }
  50. /**
  51. * 商品列表
  52. * @return mixed
  53. * @throws Exception
  54. * @throws \yii\web\HttpException
  55. */
  56. public function actionIndex() {
  57. $filter = $this->filterCondition([
  58. 'TYPE'=> 'TYPE',
  59. 'GIFT_TYPE'=> 'GIFT_TYPE',
  60. 'STATUS'=> 'STATUS',
  61. 'GOODS_NAME'=> 'GOODS_NAME',
  62. 'GOODS_NO'=> 'GOODS_NO',
  63. 'SELL_TYPE'=> 'SELL_TYPE',
  64. 'SELL_PRICE'=> 'SELL_PRICE',
  65. 'PRICE_PV'=> 'PRICE_PV',
  66. 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
  67. ]);
  68. $condition = $filter['condition'];
  69. $params = $filter['params'];
  70. $condition .= ' ';
  71. $listObj = new GoodsList();
  72. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  73. return static::notice($data);
  74. }
  75. /**
  76. * 商品列表导出
  77. * @return mixed
  78. * @throws \yii\db\Exception
  79. * @throws \yii\web\HttpException
  80. */
  81. public function actionGoodsListExport()
  82. {
  83. $filter = $this->filterCondition([
  84. 'TYPE'=> 'TYPE',
  85. 'GIFT_TYPE'=> 'GIFT_TYPE',
  86. 'STATUS'=> 'STATUS',
  87. 'GOODS_NAME'=> 'GOODS_NAME',
  88. 'GOODS_NO'=> 'GOODS_NO',
  89. 'SELL_TYPE'=> 'SELL_TYPE',
  90. 'SELL_PRICE'=> 'SELL_PRICE',
  91. 'PRICE_PV'=> 'PRICE_PV',
  92. 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
  93. ]);
  94. $form = new ShopExportForm();
  95. $result = $form->run($filter, 'Goods_List'); // 商品列表
  96. if (!$result) {
  97. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  98. }
  99. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  100. }
  101. /**
  102. * 添加商品
  103. * @return mixed
  104. * @throws Exception
  105. * @throws \yii\web\HttpException
  106. */
  107. public function actionGoodsAdd() {
  108. if (\Yii::$app->request->isPost) {
  109. $formModel = new ShopGoodsForm();
  110. $formModel->scenario = 'add';
  111. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  112. return static::notice('Product add succeeded.');
  113. } else {
  114. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  115. }
  116. }
  117. return static::notice([
  118. 'sellType' => ShopGoods::SALE_TYPE,
  119. 'goodsType' => ShopGoods::GOODS_TYPE,
  120. 'giftType' => ShopGoods::GIFT_TYPE,
  121. 'categoryType' => ShopGoods::CATEGORY_TYPE,
  122. ]);
  123. }
  124. /**
  125. * 编辑商品
  126. * @return mixed
  127. * @throws Exception
  128. * @throws \yii\web\HttpException
  129. */
  130. public function actionGoodsEdit() {
  131. $id = \Yii::$app->request->get('id');
  132. if (\Yii::$app->request->isPost) {
  133. $formModel = new ShopGoodsForm();
  134. $formModel->scenario = 'edit';
  135. $formModel->id = $id;
  136. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  137. return static::notice('Product editing succeeded.');
  138. } else {
  139. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  140. }
  141. }
  142. $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
  143. $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
  144. $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
  145. if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
  146. $data['SELL_DISCOUNT'] = ShopGoods::GOODS_TYPE[$data['TYPE']]['discount']/100;
  147. }
  148. return static::notice(
  149. [
  150. 'goodsInfo'=>$data,
  151. 'sellType' => ShopGoods::SALE_TYPE,
  152. 'goodsType' => ShopGoods::GOODS_TYPE,
  153. 'giftType' => ShopGoods::GIFT_TYPE,
  154. 'categoryType' => ShopGoods::CATEGORY_TYPE,
  155. ]
  156. );
  157. }
  158. /**
  159. * 上传图片
  160. * @return mixed
  161. * @throws \yii\base\Exception
  162. * @throws \yii\db\Exception
  163. * @throws \yii\web\HttpException
  164. */
  165. public function actionUpload(){
  166. if(\Yii::$app->request->isPost){
  167. $formModel = new UploadForm();
  168. $formModel->scenario = 'goodsImg';
  169. $formModel->file = UploadedFile::getInstanceByName('file');
  170. $formModel->token = \Yii::$app->request->request('uploadToken');
  171. if($formModel->file && $uploader = $formModel->upload()){
  172. return static::notice($uploader->URL);
  173. } else {
  174. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  175. }
  176. } else {
  177. $token = Cache::setUploadToken();
  178. return static::notice($token);
  179. }
  180. }
  181. /**
  182. * 商品上下架
  183. * @return mixed
  184. * @throws Exception
  185. */
  186. public function actionGoodsStatus() {
  187. $id = \Yii::$app->request->get('id');
  188. if (\Yii::$app->request->isPost) {
  189. $formModel = new ShopGoodsForm();
  190. $formModel->scenario = 'changeStatus';
  191. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  192. // foreach ($result['logs'] as $k => $value) {
  193. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  194. // }
  195. return static::notice('Status setting succeeded'); // 状态设置成功
  196. } else {
  197. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  198. }
  199. }
  200. }
  201. /**
  202. * 删除商品
  203. * @return mixed
  204. * @throws \yii\db\Exception
  205. * @throws \yii\web\HttpException
  206. */
  207. public function actionGoodsDelete(){
  208. $result = static::delete(ShopGoods::class);
  209. return $result;
  210. }
  211. /**
  212. * 套餐列表
  213. * @return mixed
  214. * @throws Exception
  215. * @throws \yii\web\HttpException
  216. */
  217. public function actionPackage() {
  218. $filter = $this->filterCondition([
  219. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  220. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  221. 'AMOUNT'=> 'DP.AMOUNT',
  222. 'PV'=> 'DP.PV',
  223. 'STATUS'=> 'DP.STATUS',
  224. 'STORE_NUMS'=>'DP.STORE_NUMS',
  225. ]);
  226. $condition = $filter['condition'];
  227. $params = $filter['params'];
  228. $condition .= ' AND DP.IS_DEL=0';
  229. $listObj = new PackageList();
  230. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  231. return static::notice($data);
  232. }
  233. /**
  234. * 添加报单套餐
  235. * @return mixed
  236. * @throws \yii\web\HttpException
  237. */
  238. public function actionPackageAdd() {
  239. if (\Yii::$app->request->isPost) {
  240. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  241. // Log::adminHandle('添加报单套餐', 1);
  242. });
  243. }
  244. return static::notice('非发请求', 405);
  245. }
  246. /**
  247. * 报单套餐获取
  248. * @return mixed
  249. * @throws \yii\web\HttpException
  250. */
  251. public function actionPackageGet() {
  252. $id = \Yii::$app->request->get('id');
  253. if (\Yii::$app->request->isPost) {
  254. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  255. // Log::adminHandle('编辑报单套餐', 1);
  256. });
  257. }
  258. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  259. 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']]);
  260. }
  261. /**
  262. * 套餐上下架
  263. * @return mixed
  264. * @throws Exception
  265. */
  266. public function actionPackageStatus() {
  267. $id = \Yii::$app->request->get('id');
  268. if (\Yii::$app->request->isPost) {
  269. $formModel = new DecPackageForm();
  270. $formModel->scenario = 'changeStatus';
  271. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  272. return static::notice('Status setting succeeded'); // 状态设置成功
  273. } else {
  274. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  275. }
  276. }
  277. }
  278. /**
  279. * 删除套餐
  280. * @return mixed
  281. * @throws \yii\db\Exception
  282. * @throws \yii\web\HttpException
  283. */
  284. public function actionPackageDelete(){
  285. $result = static::delete(DeclarationPackage::class);
  286. return $result;
  287. }
  288. /**
  289. * 报单表
  290. * @return mixed
  291. * @throws Exception
  292. * @throws \yii\web\HttpException
  293. */
  294. public function actionDecOrderList() {
  295. $filter = $this->filterCondition([
  296. 'DEC_SN'=> 'DO.DEC_SN',
  297. 'ORDER_SN'=> 'DO.ORDER_SN',
  298. 'USER_NAME'=> 'U.USER_NAME',
  299. 'TO_USER_NAME'=> 'TU.USER_NAME',
  300. 'REAL_NAME'=> 'TU.REAL_NAME',
  301. 'ID_CARD'=> 'TU.ID_CARD',
  302. 'MOBILE'=> 'TU.MOBILE',
  303. 'DEC_LV_NAME' => 'TU.DEC_LV',
  304. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  305. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  306. 'DEC_PV'=> 'DO.DEC_PV',
  307. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  308. 'REC_USER_NAME'=> 'RU.USER_NAME',
  309. 'CREATED_AT'=> 'DO.CREATED_AT',
  310. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  311. ]);
  312. $condition = $filter['condition'];
  313. $params = $filter['params'];
  314. $condition .= ' AND DO.IS_DEL=0';
  315. $listObj = new DecOrderList();
  316. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  317. return static::notice($data);
  318. }
  319. /**
  320. * 报单表导出
  321. * @return mixed
  322. * @throws \yii\db\Exception
  323. * @throws \yii\web\HttpException
  324. */
  325. public function actionDecOrderListExport()
  326. {
  327. $filter = $this->filterCondition([
  328. 'DEC_SN'=> 'DO.DEC_SN',
  329. 'ORDER_SN'=> 'DO.ORDER_SN',
  330. 'USER_NAME'=> 'U.USER_NAME',
  331. 'TO_USER_NAME'=> 'TU.USER_NAME',
  332. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  333. 'DEC_PV'=> 'DO.DEC_PV',
  334. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  335. 'CREATED_AT'=> 'DO.CREATED_AT',
  336. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  337. ]);
  338. $filter['condition'] .= ' AND DO.IS_DEL=0';
  339. $form = new ShopExportForm();
  340. $result = $form->run($filter, '报单列表');
  341. if (!$result) {
  342. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  343. }
  344. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  345. }
  346. // 删除订单
  347. public function actionDeleteOrder() {
  348. if (\Yii::$app->request->isPost) {
  349. $formModel = new OrderDeleteForm();
  350. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  351. return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
  352. } else {
  353. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  354. }
  355. }
  356. }
  357. /**
  358. * 订单表
  359. * @return mixed
  360. * @throws Exception
  361. * @throws \yii\web\HttpException
  362. */
  363. public function actionOrderList() {
  364. $filter = $this->filterCondition([
  365. 'SN'=> 'O.SN',
  366. 'USER_NAME'=> 'U.USER_NAME',
  367. 'MOBILE'=> 'O.MOBILE',
  368. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  369. 'CREATED_AT'=> 'O.CREATED_AT',
  370. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  371. 'STATUS' => 'O.STATUS',
  372. 'IS_AUTO' => 'O.IS_AUTO'
  373. ]);
  374. $condition = ' 1=1 ' . $filter['condition'];
  375. $params = $filter['params'];
  376. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  377. $listObj = new OrderList();
  378. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  379. return static::notice($data);
  380. }
  381. /**
  382. * 订单表导出
  383. * @return mixed
  384. * @throws \yii\db\Exception
  385. * @throws \yii\web\HttpException
  386. */
  387. public function actionOrderListExport()
  388. {
  389. $filter = $this->filterCondition([
  390. 'SN'=> 'O.SN',
  391. 'USER_NAME'=> 'U.USER_NAME',
  392. 'MOBILE'=> 'O.MOBILE',
  393. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  394. 'CREATED_AT'=> 'O.CREATED_AT',
  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. /**
  729. * BA订单表
  730. * @return mixed
  731. * @throws Exception
  732. * @throws \yii\web\HttpException
  733. */
  734. public function actionBaOrderList() {
  735. $filter = $this->filterCondition([
  736. 'SN'=> 'O.SN',
  737. 'USER_NAME'=> 'U.USER_NAME',
  738. 'MOBILE'=> 'O.MOBILE',
  739. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  740. 'CREATED_AT'=> 'O.CREATED_AT',
  741. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  742. 'STATUS' => 'O.STATUS',
  743. 'IS_AUTO' => 'O.IS_AUTO'
  744. ]);
  745. $condition = ' 1=1 ' . $filter['condition'];
  746. $params = $filter['params'];
  747. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  748. $listObj = new BaOrderList();
  749. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  750. return static::notice($data);
  751. }
  752. /**
  753. * BA订单表导出
  754. * @return mixed
  755. * @throws \yii\db\Exception
  756. * @throws \yii\web\HttpException
  757. */
  758. public function actionBaOrderListExport()
  759. {
  760. $filter = $this->filterCondition([
  761. 'SN'=> 'O.SN',
  762. 'USER_NAME'=> 'U.USER_NAME',
  763. 'MOBILE'=> 'O.MOBILE',
  764. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  765. 'CREATED_AT'=> 'O.CREATED_AT',
  766. ]);
  767. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  768. $form = new ShopExportForm();
  769. $result = $form->run($filter, 'Ba_Order_List'); // 订单列表
  770. if (!$result) {
  771. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  772. }
  773. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  774. }
  775. /**
  776. * BA会员列表
  777. * @return mixed
  778. * @throws Exception
  779. * @throws \yii\web\HttpException
  780. */
  781. public function actionBaUserList() {
  782. $filter = $this->filterCondition([
  783. 'USER_NAME' => 'U.USER_NAME',
  784. 'REAL_NAME' => 'U.REAL_NAME',
  785. 'STATUS' => 'U.STATUS',
  786. 'ALLOW_LOGIN' => 'U.ALLOW_LOGIN',
  787. 'CREATED_AT' => 'U.CREATED_AT',
  788. 'PERIOD_AT' => 'U.PERIOD_AT',
  789. // 'DEC_LV_NAME' => 'U.DEC_LV',
  790. // 'DEC_LV_UPDATED_AT' => 'U.DEC_LV_UPDATED_AT',
  791. // 'LAST_DEC_LV_NAME' => 'U.LAST_DEC_LV',
  792. // 'EMP_LV_NAME' => 'U.EMP_LV',
  793. 'REC_USER_NAME' => 'RU.USER_NAME',
  794. 'CON_USER_NAME' => 'CU.USER_NAME',
  795. 'ID_CARD' => 'U.ID_CARD',
  796. 'SPOUSE_NAME' => 'U.SPOUSE_NAME',
  797. // 'SPOUSE_IDCARD' => 'U.SPOUSE_IDCARD',
  798. 'SYSTEM_NAME' => 'U.SYSTEM_ID',
  799. 'MOBILE' => 'U.MOBILE',
  800. 'TEL' => 'U.TEL',
  801. 'DEC_USER_NAME' => 'DU.USER_NAME',
  802. // 'IS_DEC' => 'U.IS_DEC',
  803. // 'IS_STUDIO' => 'U.IS_STUDIO',
  804. // 'DEC_ROLE_NAME' => 'U.DEC_ROLE_ID',
  805. 'OPEN_BANK_NAME' => 'U.OPEN_BANK',
  806. 'BANK_AREA' => [
  807. 'FIELD' => ['U.BANK_PROVINCE', 'U.BANK_CITY', 'U.BANK_COUNTY'],
  808. 'BIND' => ['BANK_PROVINCE', 'BANK_CITY', 'BANK_COUNTY'],
  809. ],
  810. 'BANK_ADDRESS' => 'U.BANK_ADDRESS',
  811. 'BANK_NO' => 'U.BANK_NO',
  812. 'SEX' => 'U.SEX',
  813. 'NATION_NAME' => 'U.NATION',
  814. 'AREA' => [
  815. 'FIELD' => ['U.PROVINCE', 'U.CITY', 'U.COUNTY'],
  816. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  817. ],
  818. 'ADDRESS' => 'U.ADDRESS',
  819. 'VERIFIED' => 'U.VERIFIED',
  820. 'VERIFIED_AT' => 'U.VERIFIED_AT',
  821. 'ALLOW_TRANSFER' => 'UI.ALLOW_TRANSFER',
  822. ]);
  823. $condition = $filter['condition'];
  824. $params = $filter['params'];
  825. $condition .= ' AND UI.DELETED=0 ';
  826. $listObj = new BaUserList();
  827. $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
  828. return static::notice($data);
  829. }
  830. public function actionBaUserListExport() {
  831. $filter = $this->filterCondition([
  832. 'USER_NAME' => 'U.USER_NAME',
  833. 'REAL_NAME' => 'U.REAL_NAME',
  834. 'STATUS' => 'U.STATUS',
  835. 'ALLOW_LOGIN' => 'U.ALLOW_LOGIN',
  836. 'CREATED_AT' => 'U.CREATED_AT',
  837. 'PERIOD_AT' => 'U.PERIOD_AT',
  838. 'DEC_LV_NAME' => 'U.DEC_LV',
  839. 'DEC_LV_UPDATED_AT' => 'U.DEC_LV_UPDATED_AT',
  840. 'LAST_DEC_LV_NAME' => 'U.LAST_DEC_LV',
  841. 'EMP_LV_NAME' => 'U.EMP_LV',
  842. 'REC_USER_NAME' => 'RU.USER_NAME',
  843. 'CON_USER_NAME' => 'CU.USER_NAME',
  844. 'ID_CARD' => 'U.ID_CARD',
  845. 'SPOUSE_NAME' => 'U.SPOUSE_NAME',
  846. 'SPOUSE_IDCARD' => 'U.SPOUSE_IDCARD',
  847. 'SYSTEM_NAME' => 'U.SYSTEM_ID',
  848. 'MOBILE' => 'U.MOBILE',
  849. 'TEL' => 'U.TEL',
  850. 'DEC_USER_NAME' => 'DU.USER_NAME',
  851. 'IS_DEC' => 'U.IS_DEC',
  852. 'IS_STUDIO' => 'U.IS_STUDIO',
  853. 'DEC_ROLE_NAME' => 'U.DEC_ROLE_ID',
  854. 'OPEN_BANK_NAME' => 'U.OPEN_BANK',
  855. 'BANK_AREA' => [
  856. 'FIELD' => ['U.BANK_PROVINCE', 'U.BANK_CITY', 'U.BANK_COUNTY'],
  857. 'BIND' => ['BANK_PROVINCE', 'BANK_CITY', 'BANK_COUNTY'],
  858. ],
  859. 'BANK_ADDRESS' => 'U.BANK_ADDRESS',
  860. 'BANK_NO' => 'U.BANK_NO',
  861. 'SEX' => 'U.SEX',
  862. 'NATION_NAME' => 'U.NATION',
  863. 'AREA' => [
  864. 'FIELD' => ['U.PROVINCE', 'U.CITY', 'U.COUNTY'],
  865. 'BIND' => ['PROVINCE', 'CITY', 'COUNTY'],
  866. ],
  867. 'ADDRESS' => 'U.ADDRESS',
  868. 'VERIFIED' => 'U.VERIFIED',
  869. 'VERIFIED_AT' => 'U.VERIFIED_AT',
  870. 'ALLOW_TRANSFER' => 'UI.ALLOW_TRANSFER',
  871. ]);
  872. $form = new BaUserExportForm();
  873. $result = $form->run($filter, 'Ba_User_List');
  874. if (!$result) {
  875. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  876. }
  877. return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
  878. }
  879. }