DefaultController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\controllers\purchase;
  8. use app\models\Admin;
  9. use app\models\Option;
  10. use app\models\Order;
  11. use app\models\RechargeReOrder;
  12. use app\models\SaaSLeaguePriceLog;
  13. use app\models\SaasUser;
  14. use app\models\Store;
  15. use app\models\OrderDetail;
  16. use app\models\StoreCloud;
  17. use app\models\Supplier;
  18. use app\modules\alliance\controllers\BaseController;
  19. use app\models\Cat;
  20. use app\modules\admin\models\PlatformForm;
  21. use app\modules\models\GoodsListForm;
  22. use app\modules\admin\models\GoodsForm;
  23. use app\modules\admin\models\MerchantForm;
  24. use app\models\Purchase;
  25. use app\models\PurchaseImportCart;
  26. use app\modules\alliance\models\purchase\FavoriteForm;
  27. use \app\models\PurchaseFavorite;
  28. use app\modules\alliance\models\purchase\BalanceForm;
  29. use app\modules\alliance\models\purchase\order\OrderListForm;
  30. use yii\data\Pagination;
  31. class DefaultController extends BaseController
  32. {
  33. public function actionIndex(){
  34. $merchantForm = new MerchantForm();
  35. $merchantForm->page = 1;
  36. $merchantForm->limit = 1;
  37. $merchantForm->setSaasStoreCloudId();
  38. if (!$merchantForm->token_stroe_cloud_id) {
  39. $this->asJson([
  40. 'code' => 1,
  41. 'msg' => '未查到云仓用户'
  42. ]);
  43. }
  44. $balance = $merchantForm->mchGetBalanceLog();
  45. $order = OrderListForm::getCountData(get_saas_user_id());
  46. $item = get_saas_purchase_store_cloud();
  47. $mch = $item ? $item->name : '';
  48. $access_token = get_params('access_token');
  49. $saas_user_model = SaasUser::findOne(['access_token' => $access_token]);
  50. $admin = Admin::findOne(['saas_user_id' => $saas_user_model->id, 'is_delete' => 0, 'type' => 'store']);
  51. $store = Store::findOne($admin->type_id);
  52. //联盟券部分
  53. $query = SaaSLeaguePriceLog::find()->where(['store_id' => $store->id, 'is_delete' => 0, 'role' => SaaSLeaguePriceLog::ROLE_STORE])
  54. ->andWhere(['AND', ['>=', 'addtime', strtotime(date('Ymd'))], ['<=', 'addtime', time()]]);
  55. //今日收入
  56. $today_price_query = clone $query;
  57. $today_price= $today_price_query->andWhere(['send_or_take_type' => 0])->sum('league_price') ?: 0;
  58. //今日赠送
  59. $today_send_price_query = clone $query;
  60. $today_send_price = $today_send_price_query->andWhere(['type' => 0])->sum('league_price') ?: 0;
  61. //今日支出
  62. $today_out_price_query = clone $query;
  63. $today_out_price = $today_out_price_query->andWhere(['send_or_take_type' => 1])->sum('league_price') ?: 0;
  64. //列表
  65. $price_list = $query->select('id, type, send_or_take_type, league_price, addtime')->orderBy('addtime desc')->asArray()->all();
  66. foreach ($price_list as &$item) {
  67. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  68. $item['type'] = (int)$item['type'];
  69. $item['send_or_take_type'] = (int)$item['send_or_take_type'];
  70. }
  71. $league_price = [
  72. 'price' => $today_price,
  73. 'send_price' => $today_send_price,
  74. 'out_price' => $today_out_price
  75. ];
  76. return $this->asJson([
  77. 'code' => 0,
  78. 'data' => [
  79. 'user' => get_saas_user(),
  80. 'mch' => $mch,
  81. 'balance' => $balance['data']['mch'],
  82. 'league_price' => $store->league_price,
  83. 'order' => $order,
  84. 'today_league_price' => $league_price,
  85. 'price_list' => $price_list
  86. ]
  87. ]);
  88. }
  89. /**
  90. *
  91. */
  92. public function actionBalance()
  93. {
  94. $merchantForm = new MerchantForm();
  95. $merchantForm->attributes = post_params();
  96. $merchantForm->setSaasStoreCloudId();
  97. return $this->asJson($merchantForm->mchGetBalanceLog());
  98. }
  99. public function actionLeague()
  100. {
  101. $page = post_params('page');
  102. $access_token = post_params('access_token');
  103. $saas_user_model = SaasUser::findOne(['access_token' => $access_token]);
  104. $saas_user_id = $saas_user_model->id;
  105. $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']);
  106. $store = Store::findOne($admin->type_id);
  107. $query= RechargeReOrder::find()->where(['store_id' => $store->id,'is_pay' => 1]);
  108. $count = $query->count();
  109. $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => 10]);
  110. $list = $query->limit($pagination->limit)->offset($pagination->offset)->asArray()->orderBy('id DESC')->all();
  111. foreach ($list as & $arr) {
  112. $arr['desc'] = '充值联盟券'. $arr['league_price'] . '元';
  113. $arr['price'] = $arr['pay_price'];
  114. $arr['addtime'] = date('Y-m-d H:i:s' ,$arr['created_at']);
  115. }
  116. return $this->asJson([
  117. 'code' => 0,
  118. 'sql' => $query,
  119. 'msg' => '查找成功',
  120. 'count' => $count,
  121. 'data' => ['list' => $list]
  122. ]);
  123. }
  124. /**
  125. * 充值提交
  126. */
  127. public function actionBalanceSubmit()
  128. {
  129. $form = new \app\modules\alliance\models\purchase\BalanceForm();
  130. $store_id = get_saas_purchase_store_id();
  131. $form->store_id = $store_id;
  132. $form->saas_id = get_saas_user_id();
  133. $form->user = get_saas_user();
  134. $form->attributes = get_params();
  135. return $this->asJson($form->payData());
  136. }
  137. public function actionLeagueSubmit()
  138. {
  139. $form = new \app\modules\alliance\models\purchase\BalanceForm();
  140. $store_id = get_saas_purchase_store_id();
  141. $form->store_id = $store_id;
  142. $form->saas_id = get_saas_user_id();
  143. $form->user = get_saas_user();
  144. $form->attributes = get_params();
  145. return $this->asJson($form->payDataLeague());
  146. }
  147. public function actionBalanceSubmit2()
  148. {
  149. $order = \app\models\PurchaseReOrder::findOne(['order_no' => 'PR20221019154533294742']);
  150. $form = new \app\modules\alliance\models\purchase\BalanceForm();
  151. $form->store_id = $order->store_id;
  152. $form->saas_id = $order->saas_id;
  153. $form->order = $order;
  154. $result = $form->storeSubmitRecharge();
  155. var_dump($result);
  156. }
  157. /**
  158. * 商户商品分类列表
  159. */
  160. public function actionMchCatList()
  161. {
  162. $is_show = get_params('is_show',Cat::IS_SHOW_TRUE);
  163. $store_id = get_saas_purchase_store_id();
  164. $list = Cat::getCatList($store_id, $is_show, 0, 0);
  165. return $this->asJson([
  166. 'code' => 0,
  167. 'data' => [
  168. 'list' => $list
  169. ]
  170. ]);
  171. }
  172. /**
  173. * 云仓商品分类列表
  174. */
  175. public function actionCatList()
  176. {
  177. $form = new PlatformForm();
  178. $form->attributes = get_params();
  179. $form->is_show = get_params('is_show',Cat::IS_SHOW_TRUE);
  180. $this->asJson($form->getGoodsCatList());
  181. }
  182. /**
  183. * 云仓商品分类列表
  184. */
  185. public function actionCatListChild()
  186. {
  187. $form = new PlatformForm();
  188. $form->attributes = get_params();
  189. $this->asJson($form->getCatListChildren());
  190. }
  191. /**
  192. * 商品列表
  193. */
  194. public function actionGoodsInfo()
  195. {
  196. $form = new PlatformForm();
  197. $form->attributes = get_params();
  198. $goods = $form->goodsInfo();
  199. $hasFav = PurchaseFavorite::findOne(['goods_id'=>get_params('id', 0), 'saas_id' => get_saas_user_id(), 'is_delete' => 0]);
  200. $goods['is_favorite'] = empty($hasFav) ? 0 : 1;
  201. // 获取客服id
  202. $goods['kefu_id'] = '';
  203. if (isset($goods['data']['list'][0]['supplier']['id'])) {
  204. $supplier = Supplier::find()->where(['cloud_supplier_id' => $goods['data']['list'][0]['supplier']['id']])->one();
  205. if ($supplier) {
  206. $goods['data']['list'][0] = \app\modules\admin\models\jushuitan\JuShuiTanForm::syncSupplierJstGoodsQty($supplier->id, $goods['data']['list'][0]);
  207. $goods['supplier'] = [
  208. 'kefu_id' => $supplier->kefu_id,
  209. 'name'=> $supplier->supplier_name,
  210. ];
  211. }
  212. }
  213. //修改金额 建议零售价显示问题
  214. $store_cloud = get_saas_purchase_store_cloud();
  215. $store_id = $store_cloud->store_id;
  216. $rate = Store::find()->where(['id' => $store_id])->select('rate')->scalar() ?: 0;
  217. if (isset($goods['data']['list'])) {
  218. foreach ($goods['data']['list'] as &$goods_item) {
  219. $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value'];
  220. $goods_item['original_price'] = intval($sale_price_type) === 0 ? sprintf('%.2f', ($goods_item['platform_negotiated_price'] + ($goods_item['platform_negotiated_price']) * ($rate / 100))) : $goods_item['original_price'];
  221. $attrs = json_decode($goods_item['attrs'], true);
  222. foreach ($attrs as &$attr_item) {
  223. if (!intval($sale_price_type)) {
  224. $attr_item['original_price'] = sprintf('%.2f', ($attr_item['platform_negotiated_price'] + ($attr_item['platform_negotiated_price']) * ($rate / 100)));
  225. }
  226. }
  227. $goods_item['attrs'] = json_encode($attrs, JSON_UNESCAPED_UNICODE);
  228. }
  229. }
  230. return $this->asJson($goods);
  231. }
  232. /**
  233. * 商品列表
  234. */
  235. public function actionGoodsList()
  236. {
  237. $form = new MerchantForm();
  238. $form->attributes = get_params();
  239. $form->setSaasStoreCloudId();
  240. if (!$form->token_stroe_cloud_id) {
  241. $this->asJson([
  242. 'code' => 1,
  243. 'msg' => '未查到云仓用户'
  244. ]);
  245. }
  246. $store_cloud = get_saas_purchase_store_cloud();
  247. if($store_cloud && $store_cloud->cloud_platform_list){
  248. $cloud_platform_list = json_decode($store_cloud->cloud_platform_list, true);
  249. if($cloud_platform_list){
  250. $form->supplier_id = implode(',', $cloud_platform_list);
  251. }
  252. }
  253. if (intval(get_params('type')) === 2) {
  254. $form->is_distribution = 0;
  255. }
  256. $form->store_id = $store_cloud->store_id;
  257. $this->asJson($form->mchGetGoodsList());
  258. }
  259. //导入一个商品
  260. public function actionMchGoodsImport(){
  261. $post = post_params();
  262. if(!is_array($post['id'])){
  263. $post['id'] = [$post['id']];
  264. }
  265. foreach($post['id'] as $id){
  266. $_post = $post;
  267. $_post['id'] = $id;
  268. $form = new GoodsForm();
  269. $form->attributes = $_post;
  270. $form->set_saas_purchase_store_id();
  271. $goodsInfo = $form->saveCloudGoods();
  272. if (isset($goodsInfo['code'])) {
  273. return $this->asJson($goodsInfo);
  274. }
  275. $merchantForm = new MerchantForm();
  276. $merchantForm->setSaasStoreCloudId();
  277. if (!$merchantForm->token_stroe_cloud_id) {
  278. return $this->asJson([
  279. 'code' => 1,
  280. 'msg' => '未查到云仓用户'
  281. ]);
  282. }
  283. $bind = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'],$goodsInfo['goods_id']);
  284. }
  285. return $this->asJson($bind);
  286. }
  287. //导入商品列表
  288. public function actionMchGoodsImports(){
  289. $ids = post_params('ids');
  290. $list = PurchaseImportCart::findAll(['id' => $ids, 'saas_id' => get_saas_user_id()]);
  291. foreach($list as $item){
  292. $form = new GoodsForm();
  293. $form->attributes = [
  294. 'id' => $item['goods_id'],
  295. // 'store_id' => $item['store_id'],
  296. 'cat_id' => explode(',', $item['cat_ids']),
  297. ];
  298. $form->set_saas_purchase_store_id();
  299. $goodsInfo = $form->saveCloudGoods();
  300. $merchantForm = new MerchantForm();
  301. $merchantForm->setSaasStoreCloudId();
  302. if (!$merchantForm->token_stroe_cloud_id) {
  303. $this->asJson([
  304. 'code' => 1,
  305. 'msg' => '未查到云仓用户'
  306. ]);
  307. }
  308. $bind = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'],$goodsInfo['goods_id']);
  309. if($bind['code'] == 0){
  310. PurchaseImportCart::deleteAll(['id' => $item['id']]);
  311. }
  312. }
  313. $this->asJson($bind);
  314. }
  315. //添加铺货单
  316. public function actionAddMchGoodsImport(){
  317. $res = [
  318. 'code' => 1,
  319. 'msg' => '操作失败',
  320. ];
  321. $post = post_params();
  322. if (is_array($post['cat_id'])) {
  323. $post['cat_id'] = implode(',', $post['cat_id']);
  324. }
  325. $exist = PurchaseImportCart::findOne([
  326. 'goods_id' => $post['id'],
  327. 'store_id' => get_saas_purchase_store_id(),
  328. 'cat_ids' => $post['cat_id'],
  329. 'saas_id' => get_saas_user_id(),
  330. ]);
  331. if($exist){
  332. $res = [
  333. 'code' => 0,
  334. 'msg' => '操作成功',
  335. ];
  336. return $this->asJson($res);
  337. }
  338. $cart = new PurchaseImportCart();
  339. $cart->goods_id = $post['id'];
  340. $cart->store_id = get_saas_purchase_store_id();
  341. $cart->cat_ids = $post['cat_id'];
  342. $cart->saas_id = get_saas_user_id();
  343. $save = $cart->save();
  344. if($save){
  345. $res = [
  346. 'code' => 0,
  347. 'msg' => '操作成功',
  348. ];
  349. }
  350. $this->asJson($res);
  351. }
  352. //修改铺货单
  353. public function actionUpdateMchGoodsImport(){
  354. $res = [
  355. 'code' => 1,
  356. 'msg' => '操作失败',
  357. ];
  358. $post = post_params();
  359. $cart = PurchaseImportCart::findOne([
  360. 'id' => $post['id'],
  361. ]);
  362. if(!$cart){
  363. return $this->asJson($res);
  364. }
  365. $cart->cat_ids = implode(',', $post['cat_ids']);
  366. $cart->saas_id = get_saas_user_id();
  367. $save = $cart->save();
  368. if($save){
  369. $res = [
  370. 'code' => 0,
  371. 'msg' => '操作成功',
  372. ];
  373. }
  374. $this->asJson($res);
  375. }
  376. //删除铺货单
  377. public function actionDelMchGoodsImport(){
  378. $res = [
  379. 'code' => 1,
  380. 'msg' => '操作失败',
  381. ];
  382. $ids = post_params('ids');
  383. $del = PurchaseImportCart::deleteAll(['id' => $ids, 'saas_id' => get_saas_user_id()]);
  384. if($del){
  385. $res = [
  386. 'code' => 0,
  387. 'msg' => '操作成功',
  388. ];
  389. }
  390. $this->asJson($res);
  391. }
  392. //获取铺货单
  393. public function actionGetMchGoodsImport(){
  394. $catList = Cat::find()->where([
  395. 'store_id' => get_saas_purchase_store_id(),
  396. ])->all();
  397. $list = PurchaseImportCart::findAll(['saas_id' => get_saas_user_id()]);
  398. foreach ($list as $i => $item) {
  399. $list[$i] = $item->toArray();
  400. $list[$i]['cat_list'] = [];
  401. foreach (explode(',', $item['cat_ids']) as $citem) {
  402. foreach ($catList as $_citem) {
  403. if($citem == $_citem['id']){
  404. $list[$i]['cat_list'][] = [
  405. 'id' => $_citem['id'],
  406. 'name' => $_citem['name'],
  407. ];
  408. }
  409. }
  410. }
  411. $form = new PlatformForm();
  412. $form->id = $item['goods_id'];
  413. $glist = $form->goodsList();
  414. if($glist['code'] == 0 && $glist['data']['count'] == 1){
  415. $list[$i]['goods_info'] = $glist['data']['list'][0];
  416. }else{
  417. unset($list[$i]);
  418. }
  419. }
  420. $newList = array();
  421. foreach ($list as $i => $item) {
  422. $supplier_id = $item['goods_info']['supplier_id'];
  423. $newList[$supplier_id]['supplier'] = $item['goods_info']['supplier'];
  424. $newList[$supplier_id]['goods_list'][] = $item;
  425. }
  426. $res = [
  427. 'code' => 0,
  428. 'msg' => '操作成功',
  429. 'data' => array_values($newList),
  430. ];
  431. $this->asJson($res);
  432. }
  433. /**
  434. * 添加商品或店铺到我的喜欢
  435. */
  436. public function actionFavoriteAdd()
  437. {
  438. $form = new FavoriteForm();
  439. $form->attributes = post_params();
  440. $form->store_id = get_saas_purchase_store_id();
  441. $form->saas_id = get_saas_user_id();
  442. return $this->asJson($form->add());
  443. }
  444. /**
  445. * 喜欢的商品或店铺列表
  446. */
  447. public function actionFavoriteList()
  448. {
  449. $form = new FavoriteForm();
  450. $form->attributes = get_params();
  451. $form->store_id = get_saas_purchase_store_id();
  452. $form->saas_id = get_saas_user_id();
  453. return $this->asJson($form->search());
  454. }
  455. /**
  456. * 取消喜欢的商品或店铺列表
  457. */
  458. public function actionFavoriteRemove()
  459. {
  460. $form = new FavoriteForm();
  461. $form->attributes = post_params();
  462. $form->store_id = get_saas_purchase_store_id();
  463. $form->saas_id = get_saas_user_id();
  464. return $this->asJson($form->remove());
  465. }
  466. /**
  467. * 申请供货商
  468. */
  469. public function actionApplySupplier()
  470. {
  471. $tel = post_params('tel');
  472. $form = new PlatformForm();
  473. $form->attributes = post_params();
  474. if ($tel) {
  475. $admin = Admin::findOne(['mobile' => $tel, 'is_delete' => 0, 'type' => 'supplier']);
  476. if ($admin) {
  477. // if ($admin->type !== 'supplier') {
  478. // return $this->asJson([
  479. // 'code' => 1,
  480. // 'msg' => '当前手机号已经绑定'
  481. // ]);
  482. // }
  483. $supplier = Supplier::findOne($admin->type_id);
  484. if ($supplier) {
  485. if ((int)$supplier->status === 1) {
  486. return $this->asJson([
  487. 'code' => 1,
  488. 'msg' => '当前已经为供货商'
  489. ]);
  490. } elseif ((int)$supplier->status === 2) {
  491. $form->id = $supplier->cloud_supplier_id;
  492. $form->status = 0;
  493. return $this->asJson($form->editSupplier());
  494. } else {
  495. return $this->asJson([
  496. 'code' => 1,
  497. 'msg' => '供货商信息审核中不可编辑'
  498. ]);
  499. }
  500. }
  501. }
  502. }
  503. $form->saas_user_id = get_saas_user_id();
  504. return $this->asJson($form->createSupplier());
  505. }
  506. /**
  507. * 获取供货商信息
  508. */
  509. public function actionGetSupplierApply()
  510. {
  511. $saas_user = get_saas_user();
  512. if ($saas_user->id) {
  513. $suppler = Supplier::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  514. if (!empty($suppler->cloud_supplier_id)) {
  515. $form = new PlatformForm();
  516. $form->ids = $suppler->cloud_supplier_id;
  517. $res = $form->listSupplier();
  518. $res['data'] = $res['data']['list'][0];
  519. $res['data']['url'] = \Yii::$app->request->hostInfo . '/admin/#/login';
  520. $res['data']['password'] = $suppler->password;
  521. } else {
  522. $res = [
  523. 'code' => 0,
  524. 'data' => [
  525. "supplier_name" => "",
  526. "name" => "",
  527. "logo" => "",
  528. "tel" => $saas_user->mobile,
  529. "type" => "",
  530. "certificate" => "",
  531. "id_card_reverse" => "",
  532. "id_card_front" => "",
  533. "sale_day" => "",
  534. "status" => "",
  535. "url" => \Yii::$app->request->hostInfo . '/admin/#/login'
  536. ],
  537. 'msg' => '获取成功'
  538. ];
  539. }
  540. return $this->asJson($res);
  541. } else {
  542. return $this->asJson([
  543. 'code' => 1,
  544. 'data' => '未获取登陆状态'
  545. ]);
  546. }
  547. }
  548. /**
  549. * 创建转单
  550. */
  551. public function actionCreateOrderTrans() {
  552. $order_id = post_params('order_id');
  553. $order = Order::findOne($order_id);
  554. $order_detail = OrderDetail::find()->where(['order_id' => $order_id])->select('goods_id')->asArray()->all();
  555. if (!empty($order) && !empty($order_detail)) {
  556. $form = new MerchantForm();
  557. $form->address = $order->address;
  558. $form->province_id = $order->province_id;
  559. $form->city_id = $order->city_id;
  560. $form->district_id = $order->district_id;
  561. $form->order_id = $order_id;
  562. $form->tel = $order->mobile;
  563. $form->name = $order->name;
  564. $form->store_id = $order->store_id;
  565. $result = $form->mchSetPurchaseOrder();
  566. return $this->asJson($result);
  567. } else {
  568. return $this->asJson([
  569. 'code' => 1,
  570. 'msg' => '订单信息错误'
  571. ]);
  572. }
  573. }
  574. /**
  575. * 设置云仓
  576. */
  577. public function actionStoreRate() {
  578. try {
  579. $saas_user_id = get_saas_user_id();
  580. $store_cloud = StoreCloud::find()
  581. ->where(['AND', ['saas_user_id' => $saas_user_id, 'is_delete' => 0], ['>', 'store_id', 0]])->asArray()->one();
  582. if (!$store_cloud) {
  583. throw new \Exception('当前云仓账户未绑定商城信息');
  584. }
  585. $store_id = $store_cloud['store_id'];
  586. $store = Store::findOne(['id' => $store_id, 'is_delete' => 0]);
  587. if (!$store) {
  588. throw new \Exception('商城信息查找失败');
  589. }
  590. $data = [];
  591. if (\Yii::$app->request->isGet) {
  592. $cloud_is_update = Option::get('cloud_is_update', $store_id, 'store')['value'];
  593. $reduce_type = Option::get('reduce_type', $store_id, 'store')['value'];
  594. $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value'];
  595. $arr = [
  596. 'rate' => $store->rate,
  597. // 'is_auth_trans' => $store->is_auth_trans,
  598. 'cloud_is_update' => (int)$cloud_is_update,
  599. 'reduce_type' => $reduce_type,
  600. 'sale_price_type' => (int)$sale_price_type
  601. ];
  602. //自动优先扣除方式
  603. $form = new MerchantForm();
  604. $result = $form->setCloudMerchantConfig(null, $store_cloud['id']);
  605. if ($result['code'] === 0) {
  606. $arr['reduce_type'] = (int)$result['data']['reduce_type'];
  607. }
  608. $data = [
  609. 'code' => 0,
  610. 'msg' => "获取成功",
  611. 'data' => $arr
  612. ];
  613. } elseif (\Yii::$app->request->isPost) {
  614. $rate = floatval(post_params('rate', 0));
  615. $reduce_type = post_params('reduce_type', 0);
  616. // $is_auth_trans = post_params('is_auth_trans', 0);
  617. $cloud_is_update = post_params('cloud_is_update', 0);
  618. $sale_price_type = post_params('sale_price_type', 0);
  619. Option::set('sale_price_type', $sale_price_type, $store_id, 'store');
  620. Option::set('cloud_is_update', $cloud_is_update, $store_id, 'store');
  621. Option::set('reduce_type', $reduce_type, $store_id, 'store');
  622. $store->rate = $rate;
  623. // $store->is_auth_trans = $is_auth_trans;
  624. if (!$store->save()) {
  625. throw new \Exception(json_encode($store->errors));
  626. }
  627. //自动优先扣除方式
  628. $form = new MerchantForm();
  629. $result = $form->setCloudMerchantConfig($reduce_type, $store_cloud['id']);
  630. $data = [
  631. 'code' => 0,
  632. 'msg' => "操作成功",
  633. ];
  634. }
  635. return $this->asJson($data);
  636. } catch (\Exception $e) {
  637. return $this->asJson([
  638. 'code' => 1,
  639. 'msg' => $e->getMessage(),
  640. ]);
  641. }
  642. }
  643. }