ShopController.php 37 KB

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