VideoShopForm.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?php
  2. namespace app\modules\admin\models;
  3. use app\models\Option;
  4. use app\models\SaasUser;
  5. use app\models\Share;
  6. use app\models\ShareLevel;
  7. use app\models\StoreMini;
  8. use app\models\User;
  9. use app\models\VideoShopSharer;
  10. use app\utils\Wechat\WechatMini;
  11. use EasyWeChat\Factory;
  12. use EasyWeChat\Kernel\BaseClient;
  13. use yii\base\Model;
  14. class VideoShopForm extends Model
  15. {
  16. public $params;
  17. public $store_id;
  18. public $mini_id;
  19. public $miniProgram;
  20. public $ids;
  21. public $nickname;
  22. public $username;
  23. public $start_time;
  24. public $end_time;
  25. public $status;
  26. public $sharer_type;
  27. public function rules()
  28. {
  29. return [
  30. [['ids', 'nickname', 'username', 'start_time', 'end_time'], 'string'],
  31. [['status', 'sharer_type', 'mini_id'], 'integer'],
  32. [['params'], 'safe']
  33. ];
  34. }
  35. public function addShop() {
  36. try {
  37. $params = $this->params;
  38. $appid = $params['app_id'];
  39. $id = $params['id'];
  40. $store_id = $this->store_id;
  41. $app_secret = $params['app_secret'];
  42. $token = $params['token'];
  43. $encodingAesKey = $params['encodingAesKey'];
  44. $finderUserName = $params['finderUserName'];
  45. if ($appid && $app_secret) {
  46. try {
  47. $config = [];
  48. $config['app_id'] = $appid;
  49. $config['secret'] = $app_secret;
  50. $config['response_type'] = 'array';
  51. $miniProgram = Factory::miniProgram($config);
  52. $client = new BaseClient($miniProgram);
  53. $client->httpGet('channels/ec/basics/info/get');
  54. } catch (\Exception $e) {
  55. throw new \Exception('App Id或 App Secret(小店密钥)错误');
  56. }
  57. }
  58. $where = [
  59. 'is_self' => 1,
  60. 'is_cancle' => 0
  61. ];
  62. if ($id) {
  63. $where = array_merge($where, [
  64. 'id' => $id
  65. ]);
  66. } elseif ($appid) {
  67. $where = array_merge($where, [
  68. 'appid' => $appid,
  69. 'store_id' => $store_id,
  70. ]);
  71. }
  72. $store_mini = StoreMini::findOne($where);
  73. if (!$store_mini) {
  74. $store_mini = new StoreMini();
  75. }
  76. $store_mini->appid = $appid;
  77. if ($app_secret) {
  78. $store_mini->app_secret = $app_secret;
  79. } else {
  80. if (empty($store_mini->id)) {
  81. throw new \Exception('添加需要填写app_secret');
  82. }
  83. }
  84. $store_mini->is_self = 1;
  85. $store_mini->store_id = $store_id;
  86. $store_mini->fuwu_type = 1;
  87. if (!$store_mini->save()) {
  88. throw new \Exception(json_encode($store_mini->errors, JSON_UNESCAPED_UNICODE));
  89. }
  90. if ($token) {
  91. Option::set('token', $token, $store_id, 'video_shop_config_' . $store_mini->id);
  92. }
  93. if ($encodingAesKey) {
  94. Option::set('encodingAesKey', $encodingAesKey, $store_id, 'video_shop_config_' . $store_mini->id);
  95. }
  96. if ($finderUserName) {
  97. Option::set('finderUserName', $finderUserName, $store_id, 'video_shop_config_' . $store_mini->id);
  98. }
  99. return [
  100. 'code' => 0,
  101. 'msg' => '保存成功',
  102. 'data' => $store_mini,
  103. ];
  104. } catch (\Exception $e) {
  105. return [
  106. 'code' => 1,
  107. 'msg' => $e->getMessage()
  108. ];
  109. }
  110. }
  111. public function delShop() {
  112. try {
  113. $params = $this->params;
  114. $ids = $this->ids;
  115. $store_id = $this->store_id;
  116. $ids = explode(',', $ids);
  117. StoreMini::updateAll(['is_cancle' => 1], ['id' => $ids, 'store_id' => $store_id]);
  118. return [
  119. 'code' => 0,
  120. 'msg' => '操作成功'
  121. ];
  122. } catch (\Exception $e) {
  123. return [
  124. 'code' => 1,
  125. 'msg' => $e->getMessage()
  126. ];
  127. }
  128. }
  129. //邀请
  130. public function inviteSharer() {
  131. $t = \Yii::$app->db->beginTransaction();
  132. try {
  133. $store_id = $this->store_id;
  134. $mini_id = $this->mini_id;
  135. $params = $this->params;
  136. $result = $this->checkSave();
  137. if ($result['code'] === 1) {
  138. return $result;
  139. }
  140. $client = new BaseClient($this->miniProgram);
  141. $data = [
  142. 'username' => $params['username'],
  143. ];
  144. $res = $client->httpPostJson('channels/ec/sharer/bind', $data);
  145. $file_name = md5(date('YmdHis') .'sharer_bind_'. $params['username'] ) . '.jpg';
  146. if (!$res['errcode'] && !empty($res)) {
  147. if (!is_dir(\Yii::$app->runtimePath . '/image')) {
  148. mkdir(\Yii::$app->runtimePath . '/image');
  149. }
  150. file_put_contents(\Yii::$app->runtimePath . '/image/' . $file_name, base64_decode($res['qrcode_img_base64']));
  151. $sharer = VideoShopSharer::findOne(['store_id' => $store_id, 'username' => $params['username'], 'is_delete' => 0, 'action_id' => $mini_id]);
  152. // $image = imagecreatefromstring($res['qrcode_img']); //将二进制流转换成图片资源
  153. // imagepng($image, \Yii::$app->runtimePath . '/image/' . $file_name); //保存PNG格式的图片
  154. if (!$sharer) {
  155. $sharer = new VideoShopSharer();
  156. $sharer->username = $data['username'];
  157. $sharer->store_id = $store_id;
  158. $sharer->action_id = $mini_id;
  159. $sharer->is_share = 1;
  160. }
  161. $sharer->is_use = 0;
  162. $sharer->is_bind = 1;
  163. $sharer->invite_image = \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name;
  164. $sharer->share_level = $params['level'];
  165. $sharer->user_id = $params['user_id'];
  166. if (!$sharer->save()) {
  167. throw new \Exception(json_encode($sharer->errors, JSON_UNESCAPED_UNICODE));
  168. }
  169. $share = Share::findOne(['store_id' => $store_id, 'user_id' => $params['user_id'], 'is_delete' => 0, 'status' => 1]);
  170. if (!$share) {
  171. $share = new Share();
  172. $share->user_id = $params['user_id'];
  173. $share->mobile = '';
  174. $share->name = '';
  175. $share->is_delete = 0;
  176. $share->store_id = $store_id;
  177. $share->status = 1;
  178. $share->created_at = time();
  179. $share->level = $params['level'];
  180. if (!$share->save()) {
  181. throw new \Exception(json_encode($share->errors, JSON_UNESCAPED_UNICODE));
  182. }
  183. $user = User::findOne($params['user_id']);
  184. $user->time = time();
  185. $user->is_distributor = 1;
  186. if (!$user->save()) {
  187. throw new \Exception(json_encode($user->errors, JSON_UNESCAPED_UNICODE));
  188. }
  189. }
  190. if (!$share->level) {
  191. $share->level = $params['level'];
  192. if (!$share->save()) {
  193. throw new \Exception(json_encode($share->errors, JSON_UNESCAPED_UNICODE));
  194. }
  195. }
  196. } else {
  197. throw new \Exception($res['errmsg'], $res['errcode']);
  198. }
  199. $t->commit();
  200. return [
  201. 'code' => 0,
  202. 'msg' => '获取成功',
  203. 'data' => [
  204. 'invite_image' => \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name
  205. ]
  206. ];
  207. } catch (\Exception $e) {
  208. $t->rollBack();
  209. return [
  210. 'code' => $e->getCode() ?: 1,
  211. 'msg' => $e->getMessage()
  212. ];
  213. }
  214. }
  215. //同步通过申请员信息
  216. public function getApplySharerInfo() {
  217. try {
  218. $store_id = $this->store_id;
  219. $mini_id = $this->mini_id;
  220. // $mini = StoreMini::findOne($this->mini_id);
  221. // if (empty($mini->appid)) {
  222. // throw new \Exception("当前没有绑定小程序信息");
  223. // }
  224. // if (!$this->openPlatform) {
  225. // throw new \Exception("参数配置错误");
  226. // }
  227. $client = new BaseClient($this->miniProgram);
  228. $sharer_list = VideoShopSharer::find()->where(['AND', ['store_id' => $store_id, 'action_id' => $mini_id], ["OR", ['openid' => ''], ['IS', 'openid', NULL]]])->all();
  229. foreach ($sharer_list as $sharer) {
  230. $data = [
  231. 'username' => $sharer['username'],
  232. ];
  233. $res = $client->httpPostJson('channels/ec/sharer/search_sharer', $data);
  234. if (!$res['errcode'] && !empty($res)) {
  235. if ($res['openid']) {
  236. $sharer->openid = $res['openid'];
  237. $sharer->nickname = $res['nickname'];
  238. $sharer->bind_time = $res['bind_time'];
  239. $sharer->sharer_type = $res['sharer_type'];
  240. $sharer->unionid = $res['unionid'];
  241. $sharer->is_use = 1;
  242. if (!$sharer->save()) {
  243. throw new \Exception(json_encode($sharer->errors,JSON_UNESCAPED_UNICODE));
  244. }
  245. }
  246. } else {
  247. throw new \Exception($res['errmsg'], $res['errcode']);
  248. }
  249. }
  250. return [
  251. 'code' => 0,
  252. 'msg' => '同步成功'
  253. ];
  254. } catch (\Exception $e) {
  255. return [
  256. 'code' => $e->getCode() ?: 1,
  257. 'msg' => $e->getMessage()
  258. ];
  259. }
  260. }
  261. /**
  262. * @param int $page 页码
  263. * @param int $page_size 每页数据
  264. * @param int $sharer_type 0普通分享员 1店铺分享员
  265. * @return array
  266. * @throws \GuzzleHttp\Exception\GuzzleException
  267. * 同步店铺分享员数据
  268. */
  269. public function syncSharerList($page = 1, $page_size = 100, $sharer_type = 0) {
  270. try {
  271. $store_id = $this->store_id;
  272. $mini_id = $this->mini_id;
  273. // $mini = StoreMini::findOne($this->mini_id);
  274. // if (empty($mini->appid)) {
  275. // throw new \Exception("当前没有绑定小程序信息");
  276. // }
  277. if (!$this->miniProgram) {
  278. throw new \Exception("请检查小店状态");
  279. }
  280. $client = new BaseClient($this->miniProgram);
  281. $data = [
  282. 'page' => $page,
  283. 'page_size' => $page_size,
  284. 'sharer_type' => $sharer_type
  285. ];
  286. $res = $client->httpPostJson('channels/ec/sharer/get_sharer_list', $data);
  287. // \Yii::error($res);
  288. if (!$res['errcode'] && !empty($res)) {
  289. // if (intval($page) === 1) {
  290. // VideoShopSharer::updateAll(['is_delete' => 1], ['AND', ['store_id' => $store_id, 'sharer_type' => $sharer_type, 'action_id' => $mini_id], ['<>', 'openid', '']]);
  291. // }
  292. foreach ($res['sharer_info_list'] as $item) {
  293. $sharer = VideoShopSharer::findOne(['openid' => $item['openid'], 'store_id' => $store_id, 'action_id' => $mini_id]);
  294. if (!$sharer) {
  295. $sharer = new VideoShopSharer();
  296. $sharer->store_id = $store_id;
  297. $sharer->openid = $item['openid'];
  298. }
  299. $sharer->action_id = $mini_id;
  300. $sharer->nickname = $item['nickname'];
  301. $sharer->bind_time = $item['bind_time'];
  302. $sharer->sharer_type = $item['sharer_type'];
  303. $sharer->unionid = $item['unionid'];
  304. $sharer->is_use = 1;
  305. $sharer->is_delete = 0;
  306. $sharer->save();
  307. }
  308. if (count($res['sharer_info_list']) === intval($page_size) || (count($res['sharer_info_list']) < intval($page_size) && $sharer_type === 0)) {
  309. ++$page;
  310. if (count($res['sharer_info_list']) < intval($page_size) && $sharer_type === 0) {
  311. $sharer_type = 1;
  312. $page = 1;
  313. }
  314. $this->syncSharerList($page, $page_size, $sharer_type);
  315. }
  316. return [
  317. 'code' => 0,
  318. 'msg' => "成功",
  319. 'data' => $res['sharer_info_list']
  320. ];
  321. }
  322. return [
  323. 'code' => 0,
  324. 'data' => []
  325. ];
  326. } catch (\Exception $e) {
  327. return [
  328. 'code' => 1,
  329. 'msg' => $e->getMessage()
  330. ];
  331. }
  332. }
  333. //获取分享员列表
  334. public function getSharerList() {
  335. try {
  336. $store_id = $this->store_id;
  337. $mini_id = $this->mini_id;
  338. $nickname = $this->nickname;
  339. $username = $this->username;
  340. $start_time = $this->start_time;
  341. $end_time = $this->end_time;
  342. $status = $this->status;
  343. $sharer_type = $this->sharer_type;
  344. $query = VideoShopSharer::find()->alias('v')->where(['v.store_id' => $this->store_id, 'v.is_delete' => 0, 's.is_cancle' => 0])
  345. ->leftJoin(['s' => StoreMini::tableName()], 'v.action_id = s.id')
  346. ->leftJoin(['u' => User::tableName()], 'u.id = v.user_id');
  347. if ($mini_id) {
  348. $query->andWhere(['v.action_id' => $mini_id]);
  349. }
  350. if ($sharer_type !== null &&$sharer_type !== '' && in_array($sharer_type, [0, 1])) {
  351. $query->andWhere(['v.sharer_type' => $sharer_type]);
  352. }
  353. if ($nickname) {
  354. $query->andWhere(['OR', ['LIKE', 'v.nickname', $nickname], ['LIKE', 'u.nickname', $nickname]]);
  355. }
  356. if ($username) {
  357. $query->andWhere(['LIKE', 'v.username', $username]);
  358. }
  359. if ($start_time) {
  360. $start_time = strtotime($start_time);
  361. $query->andWhere(['>=', 'v.created_at', $start_time]);
  362. }
  363. if ($end_time) {
  364. $end_time = strtotime($end_time);
  365. $query->andWhere(['<=', 'v.created_at', $end_time]);
  366. }
  367. if ($status !== null && intval($status) !== -1) {
  368. $query->andWhere(['v.is_bind' => $status]);
  369. }
  370. $query->select('v.id, v.action_id, v.nickname, v.username, v.is_bind, v.created_at, v.sharer_type, v.share_level, v.is_use, v.invite_image, v.user_id')->orderBy('v.id desc');
  371. $pagination = pagination_make($query);
  372. foreach ($pagination['list'] as &$item) {
  373. $store_mini = StoreMini::findOne($item['action_id']);
  374. $item['store_mini_name'] = $store_mini->mini_nickname;
  375. $item['is_use'] = (int)$item['is_use'];
  376. $item['is_bind'] = (int)$item['is_bind'];
  377. $item['sharer_type'] = (int)$item['sharer_type'];
  378. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  379. $item['share_level_name'] = ShareLevel::findOne(['level' => $item['share_level'], 'is_delete' => 0 , 'store_id' => $store_id])->name ?: '普通分销';
  380. $user = User::findOne($item['user_id']);
  381. $item['user_name'] = '';
  382. if ($user) {
  383. $saas_user = SaasUser::findOne(['mobile' => $user->binding, 'is_delete' => 0]);
  384. $item['user_name'] = $saas_user->name;
  385. }
  386. }
  387. // 获取小店列表(id 名称)
  388. $store_mini = StoreMini::find()->where(['store_id' => $store_id, 'fuwu_type' => 1, 'is_cancle' => 0])
  389. ->select('id, mini_nickname')->asArray()->all(); //
  390. // 获取分销商等级
  391. $share_level = ShareLevel::find()->where(['is_delete' => 0, 'store_id' => $store_id])
  392. ->select('level, name')->asArray()->all();
  393. return [
  394. 'code' => 0,
  395. 'msg' => 'success',
  396. 'data' => [
  397. 'data' => $pagination['list'],
  398. 'pageNo' => $pagination['pageNo'],
  399. 'totalCount' => $pagination['totalCount'],
  400. 'store_mini' => $store_mini,
  401. 'share_level' => $share_level
  402. ]
  403. ];
  404. } catch (\Exception $e) {
  405. return [
  406. 'code' => 1,
  407. 'msg' => $e->getMessage()
  408. ];
  409. }
  410. }
  411. //解绑
  412. public function unbindSharer() {
  413. try {
  414. $ids = $this->ids;
  415. if ($ids) {
  416. $ids = explode(',', $ids);
  417. } else {
  418. throw new \Exception('参数错误');
  419. }
  420. $sharer_openid_array = VideoShopSharer::find()->where(['id' => $ids, 'is_delete' => 0])->select('id, openid, action_id')->asArray()
  421. ->all();
  422. foreach ($sharer_openid_array as $item) {
  423. $miniProgram = (new WechatMini())::getWechatConfig(get_store_id(), $item['action_id'], 1);
  424. $client = new BaseClient($miniProgram);
  425. $data = [
  426. 'openid_list' => $item['openid']
  427. ];
  428. $res = $client->httpPostJson('channels/ec/sharer/unbind', $data);
  429. if (!$res['errcode'] && !empty($res)) {
  430. if ($res['refuse_openid']) {
  431. $fail_sharer = VideoShopSharer::find()->where(['openid' => $res['refuse_openid'], 'is_delete' => 0, 'id' => $item['id']])
  432. ->select('nickname')->column();
  433. if ($fail_sharer) {
  434. $fail_sharer = implode(',', $fail_sharer);
  435. throw new \Exception('解绑失败用户:' . $fail_sharer . '。原因可能为openid错误,解绑时间距离绑定成功时间不足1天等');
  436. }
  437. }
  438. } else {
  439. throw new \Exception($res['errmsg'], $res['errcode']);
  440. }
  441. }
  442. return [
  443. 'code' => 0,
  444. 'msg' => '操作成功'
  445. ];
  446. } catch (\Exception $e) {
  447. return [
  448. 'code' => 1,
  449. 'msg' => $e->getMessage()
  450. ];
  451. }
  452. }
  453. //编辑
  454. public function editSharerInfo() {
  455. $t = \Yii::$app->db->beginTransaction();
  456. try {
  457. $params = $this->params;
  458. $store_id = $this->store_id;
  459. $sharer = VideoShopSharer::findOne(['store_id' => $store_id, 'id' => $params['id'], 'is_delete' => 0]);
  460. if (!$sharer) {
  461. throw new \Exception('信息不存在');
  462. }
  463. $this->mini_id = $sharer->action_id;
  464. $this->miniProgram = true;
  465. $result = $this->checkSave();
  466. if ($result['code'] === 1) {
  467. return $result;
  468. }
  469. if ($params['level']) {
  470. $sharer->share_level = $params['level'];
  471. if (!$sharer->save()) {
  472. throw new \Exception(json_encode($sharer->errors, JSON_UNESCAPED_UNICODE));
  473. }
  474. }
  475. if (intval($params['user_id']) !== intval($sharer->user_id)) {
  476. //将老用户分销商身份删除
  477. $user_id = $sharer->user_id;
  478. $share = Share::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0, 'status' => 1]);
  479. if ($share) {
  480. $share->is_delete = 1;
  481. if (!$share->save()) {
  482. throw new \Exception(json_encode($share->errors, JSON_UNESCAPED_UNICODE));
  483. }
  484. }
  485. $user = User::findOne($user_id);
  486. if ($user) {
  487. $user->time = time();
  488. $user->is_distributor = 0;
  489. if (!$user->save()) {
  490. throw new \Exception(json_encode($user->errors, JSON_UNESCAPED_UNICODE));
  491. }
  492. }
  493. // 将新用户修改为分销商
  494. if ($params['user_id']) {
  495. $sharer->user_id = $params['user_id'];
  496. }
  497. $sharer->is_bind = 1;
  498. if (!$sharer->save()) {
  499. throw new \Exception(json_encode($sharer->errors, JSON_UNESCAPED_UNICODE));
  500. }
  501. $share = Share::findOne(['store_id' => $store_id, 'user_id' => $params['user_id'], 'is_delete' => 0, 'status' => 1]);
  502. if (!$share) {
  503. $share = new Share();
  504. $share->user_id = $params['user_id'];
  505. $share->mobile = '';
  506. $share->name = '';
  507. $share->is_delete = 0;
  508. $share->store_id = $store_id;
  509. $share->status = 1;
  510. $share->created_at = time();
  511. $share->level = $params['level'];
  512. if (!$share->save()) {
  513. throw new \Exception(json_encode($share->errors, JSON_UNESCAPED_UNICODE));
  514. }
  515. $user = User::findOne($params['user_id']);
  516. $user->time = time();
  517. $user->is_distributor = 1;
  518. if (!$user->save()) {
  519. throw new \Exception(json_encode($user->errors, JSON_UNESCAPED_UNICODE));
  520. }
  521. }
  522. if (!$share->level && $params['level']) {
  523. $share->level = $params['level'];
  524. if (!$share->save()) {
  525. throw new \Exception(json_encode($share->errors, JSON_UNESCAPED_UNICODE));
  526. }
  527. }
  528. }
  529. $t->commit();
  530. return [
  531. 'code' => 0,
  532. 'msg' => '修改完成'
  533. ];
  534. } catch (\Exception $e) {
  535. $t->rollBack();
  536. return [
  537. 'code' => 1,
  538. 'msg' => $e->getMessage()
  539. ];
  540. }
  541. }
  542. public function checkSave() {
  543. try {
  544. $params = $this->params;
  545. $store_id = $this->store_id;
  546. $mini_id = $this->mini_id;
  547. if (!$this->miniProgram) {
  548. throw new \Exception("参数配置错误,请检查小店状态");
  549. }
  550. $user = User::findOne(['id' => $params['user_id'], 'is_delete' => 0, 'store_id' => $store_id]);
  551. if (!$user) {
  552. throw new \Exception("用户不存在");
  553. }
  554. $where = ['store_id' => $store_id, 'user_id' => $params['user_id'], 'is_delete' => 0, 'action_id' => $mini_id];
  555. if ($params['id']) {
  556. $where = ['AND',
  557. [
  558. 'store_id' => $store_id,
  559. 'user_id' => $params['user_id'],
  560. 'is_delete' => 0,
  561. 'action_id' => $mini_id
  562. ], [
  563. '<>', 'id', $params['id']
  564. ]
  565. ];
  566. }
  567. $sharer = VideoShopSharer::findOne($where);
  568. if ($sharer) {
  569. throw new \Exception("商城用户已经被绑定为分享员");
  570. }
  571. if (!$params['id']) {
  572. $share_level = ShareLevel::findOne(['level' => $params['level'], 'is_delete' => 0, 'store_id' => $store_id]);
  573. if (!$share_level) {
  574. throw new \Exception("分销商等级不存在");
  575. }
  576. $share = Share::findOne(['store_id' => $store_id, 'user_id' => $params['user_id'], 'is_delete' => 0]);
  577. if ($share && $share->level && intval($share->level) !== intval($params['level'])) {
  578. throw new \Exception("分销商等级不匹配");
  579. }
  580. }
  581. return [
  582. 'code' => 0,
  583. 'msg' => '检测完成'
  584. ];
  585. } catch (\Exception $e) {
  586. return [
  587. 'code' => 1,
  588. 'msg' => $e->getMessage()
  589. ];
  590. }
  591. }
  592. }