ShopController.php 38 KB

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