ShopController.php 38 KB

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