ShopController.php 36 KB

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