ShopController.php 41 KB

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