ShopController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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\OrderPeriodAdjustList;
  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\Form;
  24. use common\models\DeclarationPackage;
  25. use common\models\DecOrder;
  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\OrderPeriodAdjustForm;
  33. use common\models\forms\ShopGoodsForm;
  34. use common\models\forms\UploadForm;
  35. use common\models\Order;
  36. use common\models\Period;
  37. use common\models\ShopGoods;
  38. use common\models\ShopGoodsNature;
  39. use Yii;
  40. use yii\web\HttpException;
  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 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. '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 Exception
  78. * @throws HttpException
  79. */
  80. public function actionGoodsNature() {
  81. $data = ShopGoodsNature::findAllAsArray('GOODS_ID=:GOODS_ID', [':GOODS_ID' => \Yii::$app->request->get('GOOD_ID')]);
  82. return static::notice($data);
  83. }
  84. /**
  85. * 商品列表导出
  86. * @return mixed
  87. * @throws \yii\db\Exception
  88. * @throws HttpException
  89. */
  90. public function actionGoodsListExport()
  91. {
  92. $filter = $this->filterCondition([
  93. 'TYPE'=> 'TYPE',
  94. 'GIFT_TYPE'=> 'GIFT_TYPE',
  95. 'STATUS'=> 'STATUS',
  96. 'GOODS_NAME'=> 'GOODS_NAME',
  97. 'GOODS_NO'=> 'GOODS_NO',
  98. 'SELL_TYPE'=> 'SELL_TYPE',
  99. 'PRICE_PV'=> 'PRICE_PV',
  100. 'CATEGORY_TYPE' => 'CATEGORY_TYPE',
  101. ]);
  102. $form = new ShopExportForm();
  103. $result = $form->run($filter, \Yii::t('ctx', 'shopExportListName')); // 商品列表
  104. if (!$result) {
  105. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  106. }
  107. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  108. }
  109. /**
  110. * 添加商品
  111. * @return mixed
  112. * @throws Exception
  113. * @throws HttpException
  114. */
  115. public function actionGoodsAdd() {
  116. if (\Yii::$app->request->isPost) {
  117. $formModel = new ShopGoodsForm();
  118. $formModel->scenario = 'add';
  119. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->add()) {
  120. return static::notice(\Yii::t('ctx', 'shopProductAddSucceededNotice'));
  121. } else {
  122. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  123. }
  124. }
  125. return static::notice([
  126. 'sellType' => ShopGoods::getSaleType(),
  127. 'goodsType' => ShopGoods::getGoodType(),
  128. 'giftType' => ShopGoods::getGiftType(),
  129. 'categoryType' => ShopGoods::getCategoryType(),
  130. ]);
  131. }
  132. /**
  133. * 编辑商品
  134. * @return mixed
  135. * @throws Exception
  136. * @throws HttpException
  137. */
  138. public function actionGoodsEdit() {
  139. $id = \Yii::$app->request->get('id');
  140. if (\Yii::$app->request->isPost) {
  141. $formModel = new ShopGoodsForm();
  142. $formModel->scenario = 'edit';
  143. $formModel->id = $id;
  144. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->edit()) {
  145. return static::notice(\Yii::t('ctx', 'shopProductEditSucceed'));
  146. } else {
  147. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  148. }
  149. }
  150. $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
  151. $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
  152. $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
  153. if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
  154. $data['SELL_DISCOUNT'] = ShopGoods::getGoodType()[$data['TYPE']]['discount']/100;
  155. }
  156. // 国家
  157. $countries = Cache::getCountries();
  158. // 货币
  159. $currencies = Cache::getCurrencies();
  160. $currencies = array_column($currencies, NULL, 'ID');
  161. foreach ($countries as &$country) {
  162. // 货币
  163. $country['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
  164. // 商品属性
  165. $country['SHOP_GOODS_NATURE'] = ShopGoodsNature::findAllAsArray('GOODS_ID=:GOODS_ID AND COUNTRY_ID=:COUNTRY_ID', [':GOODS_ID' => $id, ':COUNTRY_ID' => $country['ID']]);
  166. }
  167. $data['SHOP_GOODS_NATURE'] = $countries;
  168. return static::notice(
  169. [
  170. 'goodsInfo'=>$data,
  171. 'sellType' => ShopGoods::getSaleType(),
  172. 'goodsType' => ShopGoods::getGoodType(),
  173. 'giftType' => ShopGoods::getGiftType(),//ShopGoods::GIFT_TYPE,
  174. 'categoryType' => ShopGoods::getCategoryType(),//ShopGoods::CATEGORY_TYPE,
  175. ]
  176. );
  177. }
  178. /**
  179. * 上传图片
  180. * @return mixed
  181. * @throws \yii\base\Exception
  182. * @throws \yii\db\Exception
  183. * @throws HttpException
  184. */
  185. public function actionUpload(){
  186. if(\Yii::$app->request->isPost){
  187. $formModel = new UploadForm();
  188. $formModel->scenario = 'goodsImg';
  189. $formModel->file = UploadedFile::getInstanceByName('file');
  190. $formModel->token = \Yii::$app->request->request('uploadToken');
  191. if($formModel->file && $uploader = $formModel->upload()){
  192. return static::notice($uploader->URL);
  193. } else {
  194. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  195. }
  196. } else {
  197. $token = Cache::setUploadToken();
  198. return static::notice($token);
  199. }
  200. }
  201. /**
  202. * 商品上下架
  203. * @return mixed
  204. * @throws Exception
  205. */
  206. public function actionGoodsStatus() {
  207. $id = \Yii::$app->request->get('id');
  208. if (\Yii::$app->request->isPost) {
  209. $formModel = new ShopGoodsForm();
  210. $formModel->scenario = 'changeStatus';
  211. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  212. // foreach ($result['logs'] as $k => $value) {
  213. // Log::adminHandle('改变商品状态至' . ShopGoods::STATUS_NAME[$result['status']], 1, $k);
  214. // }
  215. return static::notice(\Yii::t('ctx', 'shopStatusSetSucceedNotice')); // 状态设置成功
  216. } else {
  217. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  218. }
  219. }
  220. }
  221. /**
  222. * 删除商品
  223. * @return mixed
  224. * @throws \yii\db\Exception
  225. * @throws HttpException
  226. */
  227. public function actionGoodsDelete(){
  228. $result = static::delete(ShopGoods::class);
  229. return $result;
  230. }
  231. /**
  232. * 套餐列表
  233. * @return mixed
  234. * @throws Exception
  235. * @throws HttpException
  236. */
  237. public function actionPackage() {
  238. $filter = $this->filterCondition([
  239. 'LEVEL_NAME'=> 'DP.LEVEL_ID',
  240. 'PACKAGE_NAME'=> 'DP.PACKAGE_NAME',
  241. 'AMOUNT'=> 'DP.AMOUNT',
  242. 'PV'=> 'DP.PV',
  243. 'STATUS'=> 'DP.STATUS',
  244. 'STORE_NUMS'=>'DP.STORE_NUMS',
  245. ]);
  246. $condition = $filter['condition'];
  247. $params = $filter['params'];
  248. $condition .= ' AND DP.IS_DEL=0';
  249. $listObj = new PackageList();
  250. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  251. return static::notice($data);
  252. }
  253. /**
  254. * 添加报单套餐
  255. * @return mixed
  256. * @throws HttpException
  257. */
  258. public function actionPackageAdd() {
  259. if (\Yii::$app->request->isPost) {
  260. return static::edit(DecPackageForm::class, '报单套餐添加成功', 'add', null, null, function () {
  261. // Log::adminHandle('添加报单套餐', 1);
  262. });
  263. }
  264. return static::notice('非法请求', 405);
  265. }
  266. /**
  267. * 报单套餐获取
  268. * @return mixed
  269. * @throws HttpException
  270. */
  271. public function actionPackageGet() {
  272. $id = \Yii::$app->request->get('id');
  273. if (\Yii::$app->request->isPost) {
  274. return static::edit(DecPackageForm::class, '套餐编辑成功', 'edit', null, null, function () {
  275. // Log::adminHandle('编辑报单套餐', 1);
  276. });
  277. }
  278. $package = DeclarationPackage::findOneAsArray('ID=:ID', [':ID' => $id]);
  279. 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']]);
  280. }
  281. /**
  282. * 套餐上下架
  283. * @return mixed
  284. * @throws Exception
  285. */
  286. public function actionPackageStatus() {
  287. $id = \Yii::$app->request->get('id');
  288. if (\Yii::$app->request->isPost) {
  289. $formModel = new DecPackageForm();
  290. $formModel->scenario = 'changeStatus';
  291. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->changeStatus()) {
  292. return static::notice('Status setting succeeded'); // 状态设置成功
  293. } else {
  294. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  295. }
  296. }
  297. }
  298. /**
  299. * 删除套餐
  300. * @return mixed
  301. * @throws \yii\db\Exception
  302. * @throws HttpException
  303. */
  304. public function actionPackageDelete(){
  305. $result = static::delete(DeclarationPackage::class);
  306. return $result;
  307. }
  308. /**
  309. * 报单表
  310. * @return mixed
  311. * @throws Exception
  312. * @throws HttpException
  313. */
  314. public function actionDecOrderList() {
  315. $filter = $this->filterCondition([
  316. 'DEC_SN'=> 'DO.DEC_SN',
  317. 'ORDER_SN'=> 'DO.ORDER_SN',
  318. 'USER_NAME'=> 'U.USER_NAME',
  319. 'TO_USER_NAME'=> 'TU.USER_NAME',
  320. 'REAL_NAME'=> 'TU.REAL_NAME',
  321. 'ID_CARD'=> 'TU.ID_CARD',
  322. 'MOBILE'=> 'TU.MOBILE',
  323. 'DEC_LV_NAME' => 'TU.DEC_LV',
  324. 'DEC_REAL_NAME'=> 'DU.REAL_NAME',
  325. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  326. 'DEC_PV'=> 'DO.DEC_PV',
  327. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  328. 'REC_USER_NAME'=> 'RU.USER_NAME',
  329. 'CREATED_AT'=> 'DO.CREATED_AT',
  330. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  331. ]);
  332. $condition = $filter['condition'];
  333. $params = $filter['params'];
  334. $condition .= ' AND DO.IS_DEL=0';
  335. $listObj = new DecOrderList();
  336. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  337. return static::notice($data);
  338. }
  339. /**
  340. * 报单表导出
  341. * @return mixed
  342. * @throws \yii\db\Exception
  343. * @throws HttpException
  344. */
  345. public function actionDecOrderListExport()
  346. {
  347. $filter = $this->filterCondition([
  348. 'DEC_SN'=> 'DO.DEC_SN',
  349. 'ORDER_SN'=> 'DO.ORDER_SN',
  350. 'USER_NAME'=> 'U.USER_NAME',
  351. 'TO_USER_NAME'=> 'TU.USER_NAME',
  352. 'DEC_AMOUNT'=> 'DO.DEC_AMOUNT',
  353. 'DEC_PV'=> 'DO.DEC_PV',
  354. 'PERIOD_NUM'=> 'DO.PERIOD_NUM',
  355. 'CREATED_AT'=> 'DO.CREATED_AT',
  356. 'UPDATED_AT'=> 'DO.UPDATED_AT',
  357. ]);
  358. $filter['condition'] .= ' AND DO.IS_DEL=0';
  359. $form = new ShopExportForm();
  360. $result = $form->run($filter, \Yii::t('ctx', 'shopDecOrderListExport'));
  361. if (!$result) {
  362. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  363. }
  364. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  365. }
  366. // 删除订单
  367. public function actionDeleteOrder() {
  368. if (\Yii::$app->request->isPost) {
  369. $formModel = new OrderDeleteForm();
  370. if ($formModel->load(\Yii::$app->request->post(), '') && $result = $formModel->returnOrder()) {
  371. return static::notice(\Yii::t('ctx', 'shopDelOrderSuccedNotice'));
  372. } else {
  373. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  374. }
  375. }
  376. }
  377. /**
  378. * 订单表
  379. * @return mixed
  380. * @throws Exception
  381. * @throws HttpException
  382. */
  383. public function actionOrderList() {
  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. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  391. 'STATUS' => 'O.STATUS',
  392. 'COUNTRY' => 'O.COUNTRY_ID',
  393. 'IS_AUTO' => 'O.IS_AUTO'
  394. ]);
  395. $condition = ' 1=1 ' . $filter['condition'];
  396. $params = $filter['params'];
  397. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  398. $listObj = new OrderList();
  399. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  400. return static::notice($data);
  401. }
  402. /**
  403. * 订单表导出
  404. * @return mixed
  405. * @throws \yii\db\Exception
  406. * @throws HttpException
  407. */
  408. public function actionOrderListExport()
  409. {
  410. $filter = $this->filterCondition([
  411. 'SN'=> 'O.SN',
  412. 'USER_NAME'=> 'U.USER_NAME',
  413. 'MOBILE'=> 'O.MOBILE',
  414. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  415. 'CREATED_AT'=> 'O.CREATED_AT',
  416. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  417. 'STATUS' => 'O.STATUS',
  418. 'IS_AUTO' => 'O.IS_AUTO'
  419. ]);
  420. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  421. $form = new ShopExportForm();
  422. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExport')); // 订单列表
  423. if (!$result) {
  424. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  425. }
  426. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  427. }
  428. /**
  429. * 外部商城订单列表
  430. * @return mixed
  431. * @throws Exception
  432. * @throws HttpException
  433. */
  434. public function actionOrderShopList() {
  435. $filter = $this->filterCondition([
  436. 'SN'=> 'O.SN',
  437. 'USER_NAME'=> 'U.USER_NAME',
  438. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  439. 'CREATED_AT'=> 'O.CREATED_AT',
  440. ]);
  441. $condition = $filter['condition'];
  442. $params = $filter['params'];
  443. $condition .= ' AND O.IS_DELETE=0';
  444. $listObj = new OrderShopList();
  445. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  446. return static::notice($data);
  447. }
  448. /**
  449. * 外部商城报单列表
  450. * @return mixed
  451. * @throws Exception
  452. * @throws HttpException
  453. */
  454. public function actionOrderDecList() {
  455. $filter = $this->filterCondition([
  456. 'SN'=> 'O.SN',
  457. 'USER_NAME'=> 'U.USER_NAME',
  458. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  459. 'CREATED_AT'=> 'O.CREATED_AT',
  460. ]);
  461. $condition = $filter['condition'];
  462. $params = $filter['params'];
  463. $condition .= ' AND O.IS_DELETE=0';
  464. $listObj = new OrderDecList();
  465. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  466. return static::notice($data);
  467. }
  468. /**
  469. * 分页导入excel文件到待导入数据的表中
  470. * @return mixed
  471. */
  472. public function actionImportOrderShopToExcelTable()
  473. {
  474. // 先上传到服务器文件
  475. if (\Yii::$app->request->isPost) {
  476. $excelImportId = \Yii::$app->request->post('excelImportId');
  477. $rowCount = \Yii::$app->request->post('rowCount');
  478. //$periodNum = \Yii::$app->request->post('periodNum');
  479. $orderDay = \Yii::$app->request->post('orderDay');
  480. $orderType = \Yii::$app->request->post('orderType');
  481. $startRow = \Yii::$app->request->post('startRow');
  482. $limit = \Yii::$app->request->post('limit', 1000);
  483. $errorMsg = '';
  484. try {
  485. if( $startRow == 1 ) {
  486. $excelOrderShop = new ExcelOrderShopForm();
  487. $excelOrderShop->checkStatus($orderDay,$orderType);
  488. }
  489. $excel = new \common\helpers\Excel();
  490. $result = $excel->pageImportCustomDataFromExcel('orderShop', $excelImportId, $rowCount, $startRow, $limit,$orderDay,$orderType);
  491. } catch (\Exception $e) {
  492. $result = false;
  493. $errorMsg = $e->getMessage();
  494. }
  495. // 还有数据
  496. if ($result === 1) {
  497. return static::notice(['finish' => false]);
  498. } elseif ($result === 0) {
  499. return static::notice(['finish' => true]);
  500. } else {
  501. return static::notice('Error:' . $errorMsg, 400);
  502. }
  503. }
  504. }
  505. /**
  506. * 导入完成标记
  507. * @return mixed
  508. * @throws HttpException
  509. */
  510. public function actionImportOrderShop() {
  511. //$periodNum = \Yii::$app->request->post('periodNum');
  512. $orderDay = \Yii::$app->request->post('orderDay');
  513. $orderType = \Yii::$app->request->post('orderType');
  514. $excelOrderShop = new ExcelOrderShopForm();
  515. $finishStatus = $excelOrderShop->finished($orderDay,$orderType);
  516. if ($finishStatus) {
  517. return static::notice(['finish' => true]);
  518. } else {
  519. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  520. }
  521. }
  522. /**
  523. * 报单订单——分页导入excel文件到待导入数据的表中
  524. * @return mixed
  525. */
  526. public function actionImportOrderDecToExcelTable()
  527. {
  528. // 先上传到服务器文件
  529. if (\Yii::$app->request->isPost) {
  530. $excelImportId = \Yii::$app->request->post('excelImportId');
  531. $rowCount = \Yii::$app->request->post('rowCount');
  532. //$periodNum = \Yii::$app->request->post('periodNum');
  533. $orderDay = \Yii::$app->request->post('orderDay');
  534. $startRow = \Yii::$app->request->post('startRow');
  535. $limit = \Yii::$app->request->post('limit', 1000);
  536. $errorMsg = '';
  537. try {
  538. if( $startRow == 1 ) {
  539. $excelOrderShop = new ExcelOrderDecForm();
  540. $excelOrderShop->checkStatus($orderDay);
  541. }
  542. $excel = new \common\helpers\Excel();
  543. $result = $excel->pageImportCustomDataFromExcel('orderDec', $excelImportId, $rowCount, $startRow, $limit,$orderDay);
  544. } catch (\Exception $e) {
  545. $result = false;
  546. $errorMsg = $e->getMessage();
  547. }
  548. // 还有数据
  549. if ($result === 1) {
  550. return static::notice(['finish' => false]);
  551. } elseif ($result === 0) {
  552. return static::notice(['finish' => true]);
  553. } else {
  554. return static::notice('Error:' . $errorMsg, 400);
  555. }
  556. }
  557. }
  558. /**
  559. * 报单订单导入完成标记
  560. * @return mixed
  561. * @throws HttpException
  562. */
  563. public function actionImportOrderDec() {
  564. //$periodNum = \Yii::$app->request->post('periodNum');
  565. $orderDay = \Yii::$app->request->post('orderDay');
  566. $excelOrderShop = new ExcelOrderDecForm();
  567. $finishStatus = $excelOrderShop->finished($orderDay);
  568. if ($finishStatus) {
  569. return static::notice(['finish' => true]);
  570. } else {
  571. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  572. }
  573. }
  574. /**
  575. * 见习达标订单列表
  576. * @return mixed
  577. * @throws Exception
  578. * @throws HttpException
  579. */
  580. public function actionOrderStandardList() {
  581. $filter = $this->filterCondition([
  582. 'SN'=> 'O.SN',
  583. 'USER_NAME'=> 'U.USER_NAME',
  584. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  585. 'CREATED_AT'=> 'O.CREATED_AT',
  586. ]);
  587. $condition = $filter['condition'];
  588. $params = $filter['params'];
  589. $condition .= ' AND O.IS_DELETE=0';
  590. $listObj = new OrderStandardList();
  591. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  592. return static::notice($data);
  593. }
  594. /**
  595. * 分页导入excel文件到待导入数据的表中
  596. * @return mixed
  597. * @throws HttpException
  598. */
  599. public function actionImportOrderStandardToExcelTable()
  600. {
  601. // 先上传到服务器文件
  602. if (\Yii::$app->request->isPost) {
  603. $excelImportId = \Yii::$app->request->post('excelImportId');
  604. $rowCount = \Yii::$app->request->post('rowCount');
  605. //$periodNum = \Yii::$app->request->post('periodNum');
  606. $orderMonth = \Yii::$app->request->post('orderMonth');
  607. // $orderType = \Yii::$app->request->post('orderType');
  608. $orderType = 'cash';
  609. $startRow = \Yii::$app->request->post('startRow');
  610. $limit = \Yii::$app->request->post('limit', 1000);
  611. $errorMsg = '';
  612. try {
  613. if( $startRow == 1 ) {
  614. //清空已经导入的表数据
  615. $excelOrderStandard = new ExcelOrderStandardForm();
  616. $excelOrderStandard->checkStatus($orderMonth);
  617. }
  618. $excel = new \common\helpers\Excel();
  619. $result = $excel->pageImportCustomDataFromExcel('orderShopStandard', $excelImportId, $rowCount, $startRow, $limit,$orderMonth,$orderType);
  620. } catch (Exception $e) {
  621. $result = false;
  622. $errorMsg = $e->getMessage();
  623. }
  624. // 还有数据
  625. if ($result === 1) {
  626. return static::notice(['finish' => false]);
  627. } elseif ($result === 0) {
  628. return static::notice(['finish' => true]);
  629. } else {
  630. return static::notice('Error:' . $errorMsg, 400);
  631. }
  632. }
  633. }
  634. /**
  635. * 达标订单导入完成标记
  636. * @return mixed
  637. * @throws HttpException
  638. */
  639. public function actionImportOrderStandard() {
  640. $orderMonth = \Yii::$app->request->post('orderMonth');
  641. $excelOrderStandard = new ExcelOrderStandardForm();
  642. $finishStatus = $excelOrderStandard->finished($orderMonth);
  643. if ($finishStatus) {
  644. return static::notice(['finish' => true]);
  645. } else {
  646. return static::notice(\Yii::t('ctx', 'shopStatusUpdateErrorNotice'), 400);
  647. }
  648. }
  649. /**
  650. * 管理员发货
  651. * @return mixed
  652. * @throws HttpException
  653. */
  654. public function actionOrderDelivery() {
  655. if(\Yii::$app->request->isPost) {
  656. return parent::edit(OrderForm::class, '发货成功', 'adminDelivery', ['adminDelivery']);
  657. }
  658. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  659. }
  660. /**
  661. * 报单表导出
  662. * @return mixed
  663. * @throws \yii\db\Exception
  664. * @throws HttpException
  665. */
  666. public function actionOrderListExportPdf()
  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'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  677. $filter['params'] = [':SN' => $orderSn];
  678. $form = new ShopExportForm();
  679. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  680. if (!$result) {
  681. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  682. }
  683. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  684. }
  685. /**
  686. * 报单表导出
  687. * @return mixed
  688. * @throws \yii\db\Exception
  689. * @throws HttpException
  690. */
  691. public function actionDecOrderListExportPdf()
  692. {
  693. $orderSn = \Yii::$app->request->get('orderSn');
  694. $filter = $this->filterCondition([
  695. 'SN'=> 'O.SN',
  696. 'USER_NAME'=> 'U.USER_NAME',
  697. 'MOBILE'=> 'O.MOBILE',
  698. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  699. 'CREATED_AT'=> 'O.CREATED_AT',
  700. ]);
  701. $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
  702. $filter['params'] = [':SN' => $orderSn];
  703. $form = new ShopExportForm();
  704. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  705. if (!$result) {
  706. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  707. }
  708. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  709. }
  710. /**
  711. * 管理员订单退款
  712. * @return mixed
  713. * @throws HttpException
  714. */
  715. public function actionOrderRefund()
  716. {
  717. if(\Yii::$app->request->isPost) {
  718. return parent::edit(OrderForm::class, \Yii::t('ctx', 'shopadminRefund'), 'adminRefund', ['adminRefund']);
  719. }
  720. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  721. }
  722. /*
  723. * 剩余BV页
  724. *
  725. */
  726. public function actionRemainPv()
  727. {
  728. $filter = $this->filterCondition([
  729. 'USER_NAME' => 'U.USER_NAME',
  730. ]);
  731. $condition = $filter['condition'];
  732. $params = $filter['params'];
  733. $listObj = new RemainPvList();
  734. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  735. return static::notice($data);
  736. }
  737. /*
  738. * 剩余BV流水
  739. *
  740. */
  741. public function actionFlowRemainPv()
  742. {
  743. $filter = $this->filterCondition([
  744. 'USER_NAME' => 'U.USER_NAME',
  745. ]);
  746. $condition = $filter['condition'];
  747. $params = $filter['params'];
  748. $listObj = new FlowRemainPvList();
  749. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  750. return static::notice($data);
  751. }
  752. /**
  753. * BA订单表
  754. * @return mixed
  755. * @throws Exception
  756. * @throws HttpException
  757. */
  758. public function actionBaOrderList() {
  759. $filter = $this->filterCondition([
  760. 'SN'=> 'O.SN',
  761. 'USER_NAME'=> 'U.USER_NAME',
  762. 'MOBILE'=> 'O.MOBILE',
  763. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  764. 'CREATED_AT'=> 'O.CREATED_AT',
  765. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  766. 'STATUS' => 'O.STATUS',
  767. ]);
  768. $condition = ' 1=1 ' . $filter['condition'];
  769. $params = $filter['params'];
  770. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  771. $listObj = new BaOrderList();
  772. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  773. return static::notice($data);
  774. }
  775. /**
  776. * BA订单表导出
  777. * @return mixed
  778. * @throws \yii\db\Exception
  779. * @throws HttpException
  780. */
  781. public function actionBaOrderListExport()
  782. {
  783. $filter = $this->filterCondition([
  784. 'SN'=> 'O.SN',
  785. 'USER_NAME'=> 'U.USER_NAME',
  786. 'MOBILE'=> 'O.MOBILE',
  787. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  788. 'CREATED_AT'=> 'O.CREATED_AT',
  789. 'STATUS' => 'O.STATUS',
  790. ]);
  791. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  792. $form = new BaShopExportForm();
  793. $result = $form->run($filter, \Yii::t('ctx', 'shopBaOrderListExport')); // 订单列表
  794. if (!$result) {
  795. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  796. }
  797. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  798. }
  799. /**
  800. * 报单表导出
  801. * @return mixed
  802. * @throws \yii\db\Exception
  803. * @throws HttpException
  804. */
  805. public function actionBaOrderListExportPdf()
  806. {
  807. $orderSn = \Yii::$app->request->get('orderSn');
  808. $filter = $this->filterCondition([
  809. 'SN'=> 'O.SN',
  810. 'USER_NAME'=> 'U.USER_NAME',
  811. 'MOBILE'=> 'O.MOBILE',
  812. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  813. 'CREATED_AT'=> 'O.CREATED_AT',
  814. ]);
  815. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  816. $filter['params'] = [':SN' => $orderSn];
  817. $form = new BaShopExportForm();
  818. $result = $form->run($filter, \Yii::t('ctx', 'shopBrandAmbassadorOrderExport'));
  819. if (!$result) {
  820. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  821. }
  822. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  823. }
  824. /**
  825. * 调整订单期数
  826. * @return mixed
  827. * @throws Exception
  828. * @throws \yii\db\Exception
  829. * @throws \yii\web\HttpException
  830. */
  831. public function actionOrderPeriodAdjust()
  832. {
  833. if (\Yii::$app->request->isPost) {
  834. $formModel = new OrderPeriodAdjustForm();
  835. $formModel->scenario = 'orderPeriodAdjust';
  836. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  837. return static::notice(Yii::t('ctx', 'successfully'));
  838. } else {
  839. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  840. }
  841. } else {
  842. $filter = $this->filterCondition([
  843. 'ORDER_SN' => 'P.ORDER_SN',
  844. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  845. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  846. 'CREATED_AT'=> 'P.CREATED_AT',
  847. ]);
  848. $listObj = new OrderPeriodAdjustList();
  849. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  850. return static::notice($data);
  851. }
  852. }
  853. /**
  854. * 订单详情
  855. * @return mixed
  856. * @throws \yii\web\HttpException
  857. */
  858. public function actionOrderDetail()
  859. {
  860. $orderSn = \Yii::$app->request->get('orderSn');
  861. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  862. if (!$order) {
  863. return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
  864. }
  865. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? Yii::t('ctx', 'shopOrderListOrderTypeZc') : Yii::t('ctx', 'shopOrderListOrderTypeFx');
  866. // 如果当前订单所在期数已挂网,则不可调整
  867. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  868. if (!$period) {
  869. return static::notice(Yii::t('ctx', 'invalidPcNo'), 400);
  870. }
  871. if ($period['IS_SENT'] > 0) {
  872. return static::notice(Yii::t('ctx', 'orderHasBeenConnected'), 400);
  873. }
  874. // 根据订单期数查询可调整期数
  875. $availablePeriod = [];
  876. if ($order['PERIOD_NUM']) {
  877. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  878. foreach ($availablePeriod as $k => $item) {
  879. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  880. }
  881. }
  882. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  883. }
  884. }