ShopController.php 36 KB

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