ShopController.php 37 KB

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