ShopController.php 37 KB

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