ShopController.php 37 KB

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