ShopController.php 37 KB

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