ShopController.php 33 KB

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