ShopController.php 37 KB

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