ShopController.php 44 KB

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