ShopController.php 36 KB

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