StoreController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. namespace addons\Mch\backend\controllers;
  3. use addons\Agent\common\models\AgentLevel;
  4. use addons\Distribution\common\models\DistributionLevel;
  5. use addons\Mch\common\enums\MchEnum;
  6. use addons\Mch\common\models\Mch;
  7. use addons\Mch\common\models\MchAdmin;
  8. use addons\Mch\common\models\MchCate;
  9. use addons\Mch\common\models\MchSettings;
  10. use common\enums\AddonsEnum;
  11. use common\enums\ApiStatusEnum;
  12. use common\enums\StatusEnum;
  13. use common\helpers\RegularHelper;
  14. use common\models\common\Region;
  15. use common\models\goods\Goods;
  16. use common\models\mall\MallAddons;
  17. use common\models\mall\MallHost;
  18. use common\models\user\User;
  19. use common\models\user\UserLevel;
  20. class StoreController extends BaseController
  21. {
  22. public function actionIndex()
  23. {
  24. if (!\Yii::$app->request->isAjax) {
  25. return $this->render('/store/index');
  26. }
  27. if (\Yii::$app->request->isGet) {
  28. $page = \Yii::$app->request->get('page', 1);
  29. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  30. $store_name = \Yii::$app->request->get('store_name');
  31. $cate_id = \Yii::$app->request->get('cate_id');
  32. $storeowner = \Yii::$app->request->get('storeowner');
  33. $nickname = \Yii::$app->request->get('nickname');
  34. // 门店状态,1:正常;2:过期;3:禁用
  35. $status = \Yii::$app->request->get('status');
  36. $time = time();
  37. $wheres[] = ['mall_id' => $this->mall_id, 'check_status' => MchEnum::CHECK_ADOPT];
  38. if (empty($status)) {
  39. $wheres[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  40. } else {
  41. if (1 == $status) {
  42. $wheres[] = ['status' => StatusEnum::ENABLED];
  43. $wheres[] = ['or', ['>=', 'expire_time', $time], ['expire_time' => 0]];
  44. } elseif (2 == $status) {
  45. $wheres[] = ['status' => StatusEnum::ENABLED];
  46. $wheres[] = ['<=', 'expire_time', $time];
  47. } elseif (3 == $status) {
  48. $wheres[] = ['status' => StatusEnum::DISABLED];
  49. } else {
  50. return $this->error('参数错误');
  51. }
  52. }
  53. if (!empty($cate_id)) {
  54. $wheres[] = ['c_id' => $cate_id];
  55. }
  56. if (!empty($store_name)) {
  57. $wheres[] = ['like', 'store_name', $store_name];
  58. }
  59. if (!empty($storeowner)) {
  60. $wheres[] = ['like', 'shop_owner', $storeowner];
  61. }
  62. if (!empty($nickname)) {
  63. $users = User::find()
  64. ->select('id,nickname,mobile,avatar_url')
  65. ->where(['like', 'nickname', $nickname])
  66. ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  67. ->asArray()
  68. ->indexBy('id')
  69. ->all();
  70. $user_ids = array_column($users, 'id');
  71. $wheres[] = ['user_id' => $user_ids];
  72. }
  73. $params = [
  74. 'select' => 'id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,province_id,city_id,district_id,check_status,address,logo_img,total_money,balance,expire_time,user_nums,status,created_at',
  75. 'where' => $wheres,
  76. 'order' => 'created_at desc',
  77. 'page' => $page,
  78. 'limit' => $limit,
  79. ];
  80. $store_list = Mch::listPage($params);
  81. if (false === $store_list) {
  82. return $this->error(Mch::getStaticError());
  83. }
  84. if (!empty($store_list['list'])) {
  85. if (empty($users)) {
  86. $user_ids = array_unique(array_column($store_list['list'], 'user_id'));
  87. $users = User::find()
  88. ->select('id,nickname,mobile,avatar_url')
  89. ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  90. ->asArray()
  91. ->indexBy('id')
  92. ->all();
  93. }
  94. $H5Url = MallHost::getHost($this->mall_id,'h5_url');
  95. foreach ($store_list['list'] as &$list) {
  96. $user = $users[$list['user_id']] ?? [];
  97. $list['nickname'] = $user['nickname'] ?? '';
  98. $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  99. // 门店状态,1:正常;2:过期;3:禁用
  100. if ($list['status'] == StatusEnum::ENABLED && $list['check_status'] == MchEnum::CHECK_ADOPT && ($list['expire_time'] > $time || $list['expire_time'] == 0)) {
  101. $list['store_status'] = 1;
  102. } elseif ($list['status'] == StatusEnum::ENABLED && $list['check_status'] == MchEnum::CHECK_ADOPT && $list['expire_time'] <= $time) {
  103. $list['store_status'] = 2;
  104. } elseif ($list['status'] == StatusEnum::DISABLED) {
  105. $list['store_status'] = 3;
  106. } else {
  107. $list['store_status'] = 1;
  108. }
  109. $list['promotion_code'] = $H5Url . '/#/plugins/Mch/store/index?mch_id='.$list['id'] . '&sign=' . $this->mall['mall_sign'];
  110. }
  111. }
  112. $store_list['store_login_url'] = \Yii::$app->request->hostInfo . '?r=mch/client/auth/login&sign=' . $this->mall['mall_sign'];
  113. return $this->success('success', $store_list);
  114. }
  115. }
  116. /**
  117. * @name:
  118. * @msg: 切换门店状态
  119. * @param {*}
  120. * @return {*}
  121. */
  122. public function actionSwitchStatus()
  123. {
  124. if (!\Yii::$app->request->isPost) {
  125. return $this->error('请求方式错误');
  126. }
  127. $post = \Yii::$app->request->post();
  128. $rules = [
  129. [['mch_id', 'status'], 'required'],
  130. [['mch_id', 'status'], 'integer'],
  131. ['status', 'in', 'range' => [1, 3]],
  132. ];
  133. $res = \Yii::$app->services->validate->validate($post, $rules);
  134. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  135. if (1 == $post['status']) {
  136. $status = StatusEnum::ENABLED;
  137. } else {
  138. $status = StatusEnum::DISABLED;
  139. }
  140. $params = [
  141. 'id' => $post['mch_id'],
  142. 'status' => $status,
  143. 'mall_id' => $this->mall_id,
  144. ];
  145. $res = Mch::setData($params);
  146. if (false === $res) {
  147. return $this->error(Mch::getStaticError());
  148. }
  149. return $this->success('操作成功');
  150. }
  151. /**
  152. * @name:
  153. * @msg: 根据地区id获取第一层子级地区信息列表
  154. * @param {*}
  155. * @return {*}
  156. */
  157. public function actionGetRegions()
  158. {
  159. if (!\Yii::$app->request->isGet) {
  160. return $this->error('请求方式错误');
  161. }
  162. $region_id = \Yii::$app->request->get('region_id');
  163. if (empty($region_id)) {
  164. return $this->error('参数错误');
  165. }
  166. $region = Region::findOne($region_id);
  167. if (empty($region)) {
  168. return $this->error('地区信息未找到');
  169. }
  170. $region_list = Region::find()
  171. ->select('id,name,lng,lat')
  172. ->where(['parent_id' => $region->id])
  173. ->asArray()
  174. ->all();
  175. return $this->success('success', $region_list);
  176. }
  177. /**
  178. * @name:
  179. * @msg: 获取会员列表
  180. * @param {*}
  181. * @return {*}
  182. */
  183. public function actionGetUsers()
  184. {
  185. if (!\Yii::$app->request->isGet) {
  186. return $this->error('请求方式错误');
  187. }
  188. $user_id = \Yii::$app->request->get('user_id');
  189. $keyword = \Yii::$app->request->get('keyword');
  190. $page = \Yii::$app->request->get('page', 1);
  191. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  192. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  193. if (!empty($user_id)) {
  194. $wheres[] = ['id' => $user_id];
  195. }
  196. if (!empty($keyword)) {
  197. $wheres[] = ['or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]];
  198. }
  199. $params = [
  200. 'select' => 'id,nickname,avatar_url,mobile,level,parent_id',
  201. 'where' => $wheres,
  202. 'order' => 'created_at desc',
  203. 'page' => $page,
  204. 'limit' => $limit,
  205. ];
  206. $user_list = User::listPage($params);
  207. if (empty($user_list['list'])) {
  208. if (false === $user_list['list']) {
  209. return $this->error(User::getStaticError());
  210. }
  211. } else {
  212. $levels = UserLevel::find()
  213. ->select('id,level,name')
  214. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  215. ->asArray()
  216. ->indexBy('level')
  217. ->all();
  218. $parent_ids = array_column($user_list['list'], 'parent_id');
  219. $parent_users = User::find()
  220. ->select('id,nickname,avatar_url,mobile,level,parent_id')
  221. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $parent_ids])
  222. ->asArray()
  223. ->indexBy('id')
  224. ->all();
  225. foreach ($user_list['list'] as &$user) {
  226. if (empty($user['avatar_url'])) {
  227. $user['avatar_url'] = \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  228. }
  229. $level = $levels[$user['level']] ?? [];
  230. $parent_user = $parent_users[$user['parent_id']] ?? [];
  231. $user['level_name'] = $level['name'] ?? '';
  232. $user['parent_nickname'] = $parent_user['nickname'] ?? '';
  233. }
  234. }
  235. return $this->success('success', $user_list);
  236. }
  237. /**
  238. * @name:
  239. * @msg: 门店添加/编辑
  240. * @param {*}
  241. * @return {*}
  242. */
  243. public function actionStorage()
  244. {
  245. if (!\Yii::$app->request->isAjax) {
  246. return $this->render('/store/add-edit');
  247. }
  248. if (\Yii::$app->request->isGet) {
  249. $cate_list = MchCate::find()
  250. ->select('id,name')
  251. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  252. ->asArray()
  253. ->all();
  254. return $this->success('success', ['list' => $cate_list]);
  255. } else {
  256. $post = \Yii::$app->request->post();
  257. // dd($post);
  258. $rules = [
  259. [['user_id', 'shop_mobile', 'shop_owner', 'store_name', 'c_id','logo_img', 'license_img'], 'required'],
  260. [['user_id', 'shop_mobile'], 'integer'],
  261. [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img'], 'string', 'max' => 255],
  262. [['logo_img', 'license_img'], 'url'],
  263. ['shop_mobile', function ($attribute, $params) {
  264. if (!RegularHelper::verify('mobile', $this->$attribute)) {
  265. $this->addError($attribute, '手机号格式错误');
  266. }
  267. }],
  268. ['store_desc', 'safe']
  269. ];
  270. $res = \Yii::$app->services->validate->validate($post, $rules);
  271. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  272. if(empty($post['store_desc']))$post['store_desc'] = '';
  273. $post['mall_id'] = $this->mall_id;
  274. $config_enter = \Yii::$app->services->setting->addons->get($this->mall_id, MchEnum::ADDONS_NAME, 'enter');
  275. if (1 == $config_enter['time_status']) {
  276. $days = $config_enter['expired_days'];
  277. $post['expire_time'] = time() + $days * 24 * 60 * 60;
  278. } else {
  279. $post['expire_time'] = 0;
  280. }
  281. $post['check_status'] = MchEnum::CHECK_ADOPT;
  282. $rr = Mch::addStore($post);
  283. if (false === $rr) {
  284. return $this->error(Mch::getStaticError());
  285. }
  286. return $this->success('添加成功');
  287. }
  288. }
  289. /**
  290. * @name:
  291. * @msg: 门店详情
  292. * @param {*}
  293. * @return {*}
  294. */
  295. public function actionDetail()
  296. {
  297. if (!\Yii::$app->request->isAjax) {
  298. return $this->render('/store/detail');
  299. }
  300. if (\Yii::$app->request->isGet) {
  301. $mch_id = \Yii::$app->request->get('mch_id');
  302. if (empty($mch_id)) {
  303. return $this->error('参数错误');
  304. }
  305. $store = Mch::find()
  306. ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'id' => $mch_id])
  307. ->asArray()
  308. ->one();
  309. if (empty($store)) {
  310. return $this->error('门店不存在');
  311. }
  312. $categorys = MchCate::find()
  313. ->select('id,name')
  314. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  315. ->asArray()
  316. ->all();
  317. $good_counts = Goods::find()
  318. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'mch_id' => $mch_id])
  319. ->count();
  320. $cate_id_name_map = array_column($categorys, 'name', 'id');
  321. $store['cate_name'] = $cate_id_name_map[$store['c_id']] ?? '';
  322. $store['good_counts'] = $good_counts;
  323. $store['total_order_number'] = $store['total_num'];
  324. $store['unsettled_amount'] = $store['total_expenses'];
  325. $store['customer_service'] = empty($store['customer_service']) ? ['web_service_url' => ''] : json_decode($store['customer_service'], true);
  326. $basic_setting = $store;
  327. $store_admin = MchAdmin::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'mch_id' => $store['id']]);
  328. $settings = MchSettings::find()
  329. ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'mch_id' => $mch_id])
  330. ->asArray()
  331. ->one();
  332. $store_setting = [
  333. 'shop_status' => $store['shop_status'] ?? 0,
  334. 'business_time_start' => $store['business_time_start'] ?? '',
  335. 'business_time_end' => $store['business_time_end'] ?? '',
  336. 'store_background' => $store['store_background'] ?? '',
  337. 'username' => $store_admin->username,
  338. 'individual_fee_setting' => $settings['individual_fee_setting'] ?? 0,
  339. 'store_service_fee' => $settings['store_service_fee'] ?? 0,
  340. 'store_service_ratio' => $settings['store_service_ratio'] ?? 10,
  341. 'store_settle_type' => $settings['store_settle_type'] ?? 1,
  342. 'store_settle_scene' => $settings['store_settle_scene'] ?? 1,
  343. 'is_balance_cash_service_fee' => $settings['is_balance_cash_service_fee'] ?? 0,
  344. 'balance_cash_service_fee' => $settings['balance_cash_service_fee'] ?? 0,
  345. 'store_commission_authority' => json_decode($settings['store_commission_authority'], true) ?? ['agent'=> 0, 'area'=> 0, 'boss'=>0, 'distribution'=> 0],
  346. ];
  347. /* ---------- 会员等级相关配置处理 start ------ */
  348. $cashier_setting = [
  349. 'cachier_service_ratio' => $settings['cachier_service_ratio'] ?? 10,
  350. 'cashier_member_status' => $settings['cashier_member_status'] ?? 0,
  351. 'cashier_member_settings' => $settings['cashier_member_settings'],
  352. 'cashier_distribution_is_enable' => $settings['cashier_distribution_is_enable'] ?? 0,
  353. 'cashier_distribution_settings' => $settings['cashier_distribution_settings'],
  354. 'cashier_agent_is_enable' => $settings['cashier_agent_is_enable'] ?? 0,
  355. 'cashier_agent_settings' => $settings['cashier_agent_settings'],
  356. 'deepNames' => ['一级分销', '二级分销'],
  357. ];
  358. $member_levels = UserLevel::find()
  359. ->select('level,name as level_name')
  360. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  361. ->asArray()
  362. ->all();
  363. if (empty($member_levels)) {
  364. $member_levels = [
  365. ['level' => 0, 'level_name' => '默认等级'],
  366. ];
  367. }
  368. if (!empty($cashier_setting['cashier_member_settings'])) {
  369. $setting_members = json_decode($cashier_setting['cashier_member_settings'], true);
  370. $mem_levels = array_column($setting_members, 'level');
  371. $mem_level_discount_map = array_column($setting_members, 'discount', 'level');
  372. } else {
  373. $mem_levels = [];
  374. $mem_level_discount_map = [];
  375. }
  376. foreach ($member_levels as &$mlevel) {
  377. if (!in_array($mlevel['level'], $mem_levels)) {
  378. $mlevel['discount'] = 0;
  379. } else {
  380. $mlevel['discount'] = floatval($mem_level_discount_map[$mlevel['level']] ?? 0);
  381. }
  382. }
  383. // dd($member_levels);
  384. $cashier_setting['cashier_member_settings'] = $member_levels;
  385. /* ---------- 会员等级相关配置处理 end ------ */
  386. /* ---------- 分销等级相关配置处理 start ------ */
  387. $is_install_distribution = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION);
  388. if (!$is_install_distribution) {
  389. $distribution_settings = [];
  390. $is_distribution_enable = 0;
  391. } else {
  392. $is_distribution_enable = 1;
  393. $distribution_levels = DistributionLevel::find()
  394. ->select('level,name as level_name')
  395. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  396. ->asArray()
  397. ->all();
  398. if (empty($distribution_levels)) {
  399. $distribution_levels = [
  400. ['level' => 0, 'level_name' => '默认等级'],
  401. ];
  402. }
  403. if (!empty($cashier_setting['cashier_distribution_settings'])) {
  404. $distribution_settings = json_decode($cashier_setting['cashier_distribution_settings'], true);
  405. $distr_levels = array_column($distribution_settings, 'level');
  406. $distr_level_discount_map = array_column($distribution_settings, 'commission_rate', 'level');
  407. } else {
  408. $distr_levels = $distr_level_discount_map = [];
  409. }
  410. foreach ($distribution_levels as &$dlevel) {
  411. if (!in_array($dlevel['level'], $distr_levels)) {
  412. $dlevel['commission_rate'] = [0, 0];
  413. } else {
  414. $dlevel['commission_rate'] = $distr_level_discount_map[$dlevel['level']] ?? [0, 0];
  415. }
  416. }
  417. $cashier_setting['cashier_distribution_settings'] = $distribution_levels;
  418. $cashier_setting['is_distribution_enable'] = $is_distribution_enable;
  419. }
  420. /* ---------- 分销等级相关配置处理 end ------ */
  421. /* ---------- 经销等级相关配置处理 start ------ */
  422. $is_install_agent = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AGENT);
  423. if (!$is_install_agent) {
  424. $agent_settings = [
  425. 'team_rewards' => [
  426. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  427. ],
  428. 'equal_rewards' => [
  429. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  430. ],
  431. 'over_rewards' => [
  432. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  433. ],
  434. ];
  435. $is_agent_enable = 0;
  436. } else {
  437. $is_agent_enable = 1;
  438. $agent_levels = AgentLevel::find()
  439. ->select('level,name as level_name')
  440. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  441. ->asArray()
  442. ->all();
  443. if (empty($agent_levels)) {
  444. $agent_levels = [
  445. ['level' => 0, 'level_name' => '默认等级'],
  446. ];
  447. }
  448. if (!empty($cashier_setting['cashier_agent_settings'])) {
  449. $agent_settings = json_decode($cashier_setting['cashier_agent_settings'], true);
  450. } else {
  451. $agent_settings = [
  452. 'team_rewards' => [
  453. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  454. ],
  455. 'equal_rewards' => [
  456. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  457. ],
  458. 'over_rewards' => [
  459. ['level' => 0, 'level_name' => '默认等级', 'commission_rate' => 0],
  460. ],
  461. ];
  462. }
  463. foreach ($agent_settings as $reward_name => $setting) {
  464. foreach ($setting as $val) {
  465. $agent_settings[$reward_name][$val['level']] = $val;
  466. }
  467. }
  468. $ag_levels = array_column($agent_settings['team_rewards'], 'level');
  469. $agent_level_settings = [];
  470. foreach ($agent_levels as $alevel) {
  471. if (!in_array($alevel['level'], $ag_levels)) {
  472. $arr = $alevel;
  473. $arr['commission_rate'] = 0;
  474. $agent_level_settings['team_rewards'][] = $arr;
  475. $agent_level_settings['equal_rewards'][] = $arr;
  476. $agent_level_settings['over_rewards'][] = $arr;
  477. } else {
  478. $arr = [
  479. 'level' => $alevel['level'],
  480. 'level_name' => $alevel['level_name'],
  481. 'commission_rate' => $agent_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0,
  482. ];
  483. $agent_level_settings['team_rewards'][] = $arr;
  484. $arr['commission_rate'] = $agent_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  485. $agent_level_settings['equal_rewards'][] = $arr;
  486. $arr['commission_rate'] = $agent_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  487. $agent_level_settings['over_rewards'][] = $arr;
  488. }
  489. }
  490. $cashier_setting['cashier_agent_settings'] = $agent_level_settings;
  491. $cashier_setting['is_agent_enable'] = $is_agent_enable;
  492. /* ---------- 经销等级相关配置处理 end ------ */
  493. }
  494. return $this->success('success', ['basic_setting' => $basic_setting, 'store_setting' => $store_setting, 'cashier_setting' => $cashier_setting, 'categorys' => $categorys]);
  495. } else {
  496. $post = \Yii::$app->request->post();
  497. $group = $post['group'];
  498. $mch_id = $post['mch_id'];
  499. if (empty($group) || !in_array($group, ['store_setting', 'cashier_setting', 'basic_setting']) || empty($mch_id)) {
  500. return $this->error('参数错误');
  501. }
  502. $rules = [
  503. 'basic_setting' => [
  504. [['store_name', 'logo_img', 'license_img', 'share_title', 'share_desc', 'share_pic', 'longitude', 'latitude', 'address', 'share_title', 'share_desc', 'share_pic'], 'string', 'max' => 255],
  505. [['shop_mobile', 'c_id','expire_time'], 'integer'],
  506. [['customer_service'], 'safe'],
  507. ],
  508. 'store_setting' => [
  509. [['shop_status', 'username', 'store_service_fee', 'store_service_ratio', 'store_settle_type', 'store_settle_scene','store_commission_authority', 'individual_fee_setting'], 'required'],
  510. [['shop_status', 'store_service_fee', 'store_settle_type', 'store_settle_scene','is_balance_cash_service_fee', 'individual_fee_setting'], 'integer'],
  511. [['store_service_ratio','balance_cash_service_fee'], 'number'],
  512. ['password', 'safe'],
  513. ],
  514. ];
  515. $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
  516. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  517. $post[$group]['mch_id'] = $mch_id;
  518. // dd($post);
  519. if ('store_setting' == $group) {
  520. $res = MchSettings::saveStoreSetting($this->mall_id, $post[$group]);
  521. if (false === $res) {
  522. return $this->error(MchSettings::getStaticError());
  523. }
  524. return $this->success('保存成功');
  525. } elseif ('cashier_setting' == $group) {
  526. $res = MchSettings::setData($this->mall_id, $post[$group]);
  527. if (false === $res) {
  528. return $this->error(MchSettings::getStaticError());
  529. }
  530. return $this->success('保存成功');
  531. } elseif ('basic_setting' == $group) {
  532. $post[$group]['mall_id'] = $this->mall_id;
  533. $post[$group]['id'] = $mch_id;
  534. unset($post[$group]['mch_id']);
  535. $res = Mch::setData($post[$group]);
  536. if (false === $res) {
  537. return $this->error(Mch::getStaticError());
  538. }
  539. return $this->success('保存成功');
  540. }
  541. }
  542. }
  543. /**
  544. * 选择门店接口,外部调用
  545. * @return mixed|void
  546. */
  547. public function actionSelectMch(){
  548. if (\Yii::$app->request->isAjax && \Yii::$app->request->isGet) {
  549. $params = \Yii::$app->request->get();
  550. $params['where'][] = ['mall_id' => $this->mall_id];
  551. $params['where'][] = ['status' => [StatusEnum::ENABLED]];
  552. if (!empty($params['keyword'])) $params['where'][] = ['like', 'store_name', $params['keyword']];
  553. $params['order'] = 'id desc';
  554. $params['select'] = 'id,store_name,shop_owner,shop_mobile,logo_img,store_desc,shop_status,status';
  555. $list = Mch::listPage($params);
  556. return $this->success('操作成功', $list);
  557. }
  558. }
  559. //门店删除
  560. public function actionDel(){
  561. try {
  562. $params = \Yii::$app->request->post();
  563. Mch::delStore($this->mall_id,$params['id']);
  564. return $this->success();
  565. }catch (\Exception $e){
  566. return $this->error($e->getMessage());
  567. }
  568. }
  569. }