ShopController.php 32 KB

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