ShopController.php 37 KB

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