ShopController.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. /**
  760. * 报单表导出
  761. * @return mixed
  762. * @throws \yii\db\Exception
  763. * @throws HttpException
  764. */
  765. public function actionDecOrderListExportPdf()
  766. {
  767. $orderSn = \Yii::$app->request->get('orderSn');
  768. $filter = $this->filterCondition([
  769. 'SN'=> 'O.SN',
  770. 'USER_NAME'=> 'U.USER_NAME',
  771. 'MOBILE'=> 'O.MOBILE',
  772. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  773. 'CREATED_AT'=> 'O.CREATED_AT',
  774. ]);
  775. $filter['condition'] = ' 1=1 AND O.IS_DELETE=0 AND O.SN=:SN';
  776. $filter['params'] = [':SN' => $orderSn];
  777. $form = new ShopExportForm();
  778. $result = $form->run($filter, \Yii::t('ctx', 'shopOrderListExportPdf'));
  779. if (!$result) {
  780. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  781. }
  782. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  783. }
  784. /**
  785. * 管理员订单退款
  786. * @return mixed
  787. * @throws HttpException
  788. */
  789. public function actionOrderRefund()
  790. {
  791. if(\Yii::$app->request->isPost) {
  792. return parent::edit(OrderForm::class, \Yii::t('ctx', 'shopadminRefund'), 'adminRefund', ['adminRefund']);
  793. }
  794. return static::notice(\Yii::t('ctx', 'illegalRequest'), 400); // 非法请求
  795. }
  796. /*
  797. * 剩余BV页
  798. *
  799. */
  800. public function actionRemainPv()
  801. {
  802. $filter = $this->filterCondition([
  803. 'USER_NAME' => 'U.USER_NAME',
  804. ]);
  805. $condition = $filter['condition'];
  806. $params = $filter['params'];
  807. $listObj = new RemainPvList();
  808. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  809. return static::notice($data);
  810. }
  811. /*
  812. * 剩余BV流水
  813. *
  814. */
  815. public function actionFlowRemainPv()
  816. {
  817. $filter = $this->filterCondition([
  818. 'USER_NAME' => 'U.USER_NAME',
  819. ]);
  820. $condition = $filter['condition'];
  821. $params = $filter['params'];
  822. $listObj = new FlowRemainPvList();
  823. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  824. return static::notice($data);
  825. }
  826. /**
  827. * BA订单表
  828. * @return mixed
  829. * @throws Exception
  830. * @throws HttpException
  831. */
  832. public function actionBaOrderList() {
  833. $filter = $this->filterCondition([
  834. 'SN'=> 'O.SN',
  835. 'USER_NAME'=> 'U.USER_NAME',
  836. 'MOBILE'=> 'O.MOBILE',
  837. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  838. 'CREATED_AT'=> 'O.CREATED_AT',
  839. 'ORDER_TYPE'=> 'O.ORDER_TYPE',
  840. 'STATUS' => 'O.STATUS',
  841. ]);
  842. $condition = ' 1=1 ' . $filter['condition'];
  843. $params = $filter['params'];
  844. $condition .= $condition ? ' AND O.IS_DELETE=0' : ' O.IS_DELETE=0';
  845. $listObj = new BaOrderList();
  846. $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
  847. return static::notice($data);
  848. }
  849. /**
  850. * BA订单表导出
  851. * @return mixed
  852. * @throws \yii\db\Exception
  853. * @throws HttpException
  854. */
  855. public function actionBaOrderListExport()
  856. {
  857. $filter = $this->filterCondition([
  858. 'SN'=> 'O.SN',
  859. 'USER_NAME'=> 'U.USER_NAME',
  860. 'MOBILE'=> 'O.MOBILE',
  861. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  862. 'CREATED_AT'=> 'O.CREATED_AT',
  863. 'STATUS' => 'O.STATUS',
  864. ]);
  865. $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
  866. $form = new BaShopExportForm();
  867. $result = $form->run($filter, \Yii::t('ctx', 'shopBaOrderListExport')); // 订单列表
  868. if (!$result) {
  869. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  870. }
  871. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  872. }
  873. /**
  874. * 报单表导出
  875. * @return mixed
  876. * @throws \yii\db\Exception
  877. * @throws HttpException
  878. */
  879. public function actionBaOrderListExportPdf()
  880. {
  881. $orderSn = \Yii::$app->request->get('orderSn');
  882. $filter = $this->filterCondition([
  883. 'SN'=> 'O.SN',
  884. 'USER_NAME'=> 'U.USER_NAME',
  885. 'MOBILE'=> 'O.MOBILE',
  886. 'PERIOD_NUM'=> 'O.PERIOD_NUM',
  887. 'CREATED_AT'=> 'O.CREATED_AT',
  888. ]);
  889. $filter['condition'] = ' O.IS_DELETE=0 AND O.SN=:SN';
  890. $filter['params'] = [':SN' => $orderSn];
  891. $form = new BaShopExportForm();
  892. $result = $form->run($filter, \Yii::t('ctx', 'shopBrandAmbassadorOrderExport'));
  893. if (!$result) {
  894. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  895. }
  896. return static::notice(\Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  897. }
  898. /**
  899. * 调整订单期数
  900. * @return mixed
  901. * @throws Exception
  902. * @throws \yii\db\Exception
  903. * @throws \yii\web\HttpException
  904. */
  905. public function actionOrderPeriodAdjust()
  906. {
  907. if (\Yii::$app->request->isPost) {
  908. $formModel = new OrderPeriodAdjustForm();
  909. $formModel->scenario = 'orderPeriodAdjust';
  910. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->periodAdjust()) {
  911. return static::notice(Yii::t('ctx', 'successfully'));
  912. } else {
  913. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  914. }
  915. } else {
  916. $filter = $this->filterCondition([
  917. 'ORDER_SN' => 'P.ORDER_SN',
  918. 'ORIGIN_PERIOD'=> 'P.ORIGIN_PERIOD',
  919. 'MODERN_PERIOD'=> 'P.MODERN_PERIOD',
  920. 'CREATED_AT'=> 'P.CREATED_AT',
  921. ]);
  922. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  923. if (!$isSuper) {
  924. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  925. $adminCountry = AdminCountry::getCountry($adminId);
  926. $quotedAdminCountry = array_map(function($item) {
  927. return "'" . addslashes($item) . "'";
  928. }, $adminCountry);
  929. $filter['condition'] .= ' AND O.COUNTRY_ID IN (' . implode(',', $quotedAdminCountry) . ')';
  930. }
  931. $listObj = new OrderPeriodAdjustList();
  932. $data = $listObj->getList(['condition' => $filter['condition'], 'params' => $filter['params']]);
  933. return static::notice($data);
  934. }
  935. }
  936. /**
  937. * 订单详情
  938. * @return mixed
  939. * @throws \yii\web\HttpException
  940. */
  941. public function actionOrderDetail()
  942. {
  943. $orderSn = \Yii::$app->request->get('orderSn');
  944. $isSuper = AdminRole::isSuperAdmin(\Yii::$app->getUser()->getUserInfo()['roleId']);
  945. if (!$isSuper) {
  946. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  947. $adminCountry = AdminCountry::getCountry($adminId);
  948. $quotedAdminCountry = array_map(function ($item) {
  949. return "'" . addslashes($item) . "'";
  950. }, $adminCountry);
  951. $order = Order::findOneAsArray('SN=:SN AND COUNTRY_ID IN (' . implode(',', $quotedAdminCountry) . ')', [':SN' => $orderSn]);
  952. } else {
  953. $order = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  954. }
  955. if (!$order) {
  956. return static::notice(Yii::t('ctx', 'orderNotExist'), 400);
  957. }
  958. $order['ORDER_TYPE'] = $order['ORDER_TYPE'] === 'ZC' ? Yii::t('ctx', 'shopOrderListOrderTypeZc') : Yii::t('ctx', 'shopOrderListOrderTypeFx');
  959. $order['COUNTRY'] = Countries::getById($order['COUNTRY_ID'])['NAME'] ?? '';
  960. // 已挂网,不可调整
  961. $period = Period::getInfoByPeriodNum($order['PERIOD_NUM']);
  962. if (!$period) {
  963. return static::notice(Yii::t('ctx', 'invalidPcNo'), 400);
  964. }
  965. if ($period['IS_SENT'] > 0) {
  966. return static::notice(Yii::t('ctx', 'orderHasBeenConnected'), 400);
  967. }
  968. // 可调整期数
  969. $availablePeriod = [];
  970. if ($order['PERIOD_NUM']) {
  971. $availablePeriod = Period::getPeriodList(+$order['PERIOD_NUM'] - 1);
  972. foreach ($availablePeriod as $k => $item) {
  973. $availablePeriod[$k]['disabled'] = (+$item['IS_SENT'] > 0) || ($order['PERIOD_NUM'] == $item['PERIOD_NUM']);
  974. }
  975. }
  976. return static::notice(['order' => $order, 'availablePeriod' => $availablePeriod]);
  977. }
  978. public function actionOrderPeriodAdjustBatch()
  979. {
  980. $db = \Yii::$app->db;
  981. $transaction = $db->beginTransaction();
  982. $orderList = [];
  983. $orderErr = [];
  984. try {
  985. $modernPeriod = 150; // todo: 修改后期数
  986. $oldPeriod = 151; // todo: 修改前期数
  987. foreach ($orderList as $orderSn) {
  988. $orderObj = Order::findOneAsArray('SN=:SN', [':SN' => $orderSn]);
  989. if (!$orderObj) {
  990. $orderErr[] = $orderSn;
  991. continue;
  992. }
  993. // 调整订单期数
  994. Order::updateAll(['PERIOD_NUM' => $modernPeriod], 'SN = :SN', [':SN' => $orderSn]);
  995. if ($orderObj['ORDER_TYPE'] === 'ZC') {
  996. // 调整报单期数
  997. DecOrder::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  998. // 调整会员的期数
  999. User::updateAll(['PERIOD_AT' => $modernPeriod], 'ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
  1000. UserInfo::updateAll(['HIGHEST_EMP_LV_PERIOD' => $modernPeriod], 'USER_ID = :USER_ID', ['USER_ID' => $orderObj['USER_ID']]);
  1001. }
  1002. // 调整流水的期数
  1003. switch ($orderObj['PAY_TYPE']){
  1004. case 'cash':
  1005. FlowWallet::updateAll(['PERIOD_NUM' => $modernPeriod], 'ORDER_SN = :ORDER_SN', ['ORDER_SN' => $orderSn]);
  1006. break;
  1007. default:
  1008. break;
  1009. }
  1010. // 写入调整记录
  1011. $orderModel = new OrderPeriodAdjust();
  1012. $orderModel->ORDER_SN = $orderSn;
  1013. $orderModel->ORIGIN_PERIOD = $oldPeriod;
  1014. $orderModel->MODERN_PERIOD = $modernPeriod;
  1015. $orderModel->ADMIN_ID = 'admin';
  1016. $orderModel->CREATED_AT = Date::nowTime();
  1017. if (!$orderModel->save()) {
  1018. return static::notice($orderModel->getErrors(), 400);
  1019. }
  1020. }
  1021. $transaction->commit();
  1022. } catch(\Exception $e) {
  1023. $transaction->rollBack();
  1024. return static::notice($e->getMessage(), 400);
  1025. }
  1026. return static::notice('成功. ' . json_encode($orderErr));
  1027. }
  1028. }