ShopController.php 36 KB

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