ShopController.php 37 KB

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