ShopController.php 39 KB

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