DivisionServices.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <?php
  2. namespace app\services\agent;
  3. use app\services\BaseServices;
  4. use app\services\system\admin\SystemAdminServices;
  5. use app\services\system\admin\SystemRoleServices;
  6. use app\services\user\UserServices;
  7. use crmeb\exceptions\AdminException;
  8. use crmeb\services\FormBuilder as Form;
  9. use think\facade\Route;
  10. class DivisionServices extends BaseServices
  11. {
  12. /**
  13. * 获取事业部/代理/员工列表
  14. * @param array $where
  15. * @return array
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\DbException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. */
  20. public function getDivisionList(array $where = [])
  21. {
  22. /** @var UserServices $userServices */
  23. $userServices = app()->make(UserServices::class);
  24. $data = $userServices->getDivisionList($where + ['status' => 1], 'uid,nickname,avatar,division_percent,division_end_time,division_status,division_invite');
  25. foreach ($data['list'] as &$item) {
  26. $item['division_end_time'] = date('Y-m-d', $item['division_end_time']);
  27. $item['agent_count'] = $userServices->count([
  28. $where['division_type'] == 1 ? 'division_id' : 'agent_id' => $item['uid'],
  29. 'division_type' => $where['division_type'] + 1,
  30. 'status' => 1
  31. ]);
  32. unset($item['label']);
  33. }
  34. return $data;
  35. }
  36. /**
  37. * 下级列表
  38. * @param $type
  39. * @param $uid
  40. * @return array
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function divisionDownList($type, $uid)
  46. {
  47. /** @var UserServices $userServices */
  48. $userServices = app()->make(UserServices::class);
  49. $where = [
  50. $type == 2 ? 'division_id' : 'agent_id' => $uid,
  51. 'division_type' => $type
  52. ];
  53. $data = $userServices->getDivisionList($where + ['status' => 1], 'uid,nickname,avatar,division_percent,division_end_time,division_status');
  54. foreach ($data['list'] as &$item) {
  55. // $item['division_end_time'] = date('Y-m-d', $item['division_end_time']);
  56. $item['agent_count'] = $userServices->count([
  57. $type == 2 ? 'division_id' : 'agent_id' => $item['uid'],
  58. 'division_type' => $type + 1,
  59. 'status' => 1
  60. ]);
  61. unset($item['label']);
  62. }
  63. return $data;
  64. }
  65. /**
  66. * 添加编辑事业部表单
  67. * @param $uid
  68. * @return array
  69. * @throws \FormBuilder\Exception\FormBuilderException
  70. */
  71. public function getDivisionForm($uid)
  72. {
  73. /** @var UserServices $userServices */
  74. $userServices = app()->make(UserServices::class);
  75. /** @var SystemAdminServices $adminService */
  76. $adminService = app()->make(SystemAdminServices::class);
  77. $userInfo = $userServices->getUserInfo($uid);
  78. if ($uid && !$userInfo) throw new AdminException(100100);
  79. if ($uid) {
  80. $adminInfo = $adminService->getInfo(['division_id' => $uid])->toArray();
  81. if (isset($adminInfo['roles'])) {
  82. foreach ($adminInfo['roles'] as &$item) {
  83. $item = intval($item);
  84. }
  85. }
  86. }
  87. $field = [];
  88. $title = '事业部';
  89. if ($uid) {
  90. $field[] = Form::number('uid', '用户UID', $userInfo['uid'])->disabled(true)->style(['width' => '173px']);
  91. } else {
  92. $field[] = Form::number('uid', '用户UID')->required('请填写用户UID')->style(['width' => '173px']);
  93. }
  94. $field[] = Form::hidden('aid', $adminInfo['id'] ?? 0);
  95. $field[] = Form::number('division_percent', '佣金比例', $userInfo['division_percent'] ?? '')->placeholder('区域代理佣金比例1-100')->info('填写1-100,如填写50代表返佣50%')->style(['width' => '173px'])->min(0)->max(100)->required();
  96. $field[] = Form::date('division_end_time', '到期时间', ($userInfo['division_end_time'] ?? '') != 0 ? date('Y-m-d H:i:s', $userInfo['division_end_time']) : '')->placeholder('区域代理到期时间');
  97. $field[] = Form::radio('division_status', '代理状态', $userInfo['division_status'] ?? 1)->options([['label' => '开通', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  98. $field[] = Form::input('account', '管理账号', $adminInfo['account'] ?? '')->required('请填写管理员账号');
  99. $field[] = Form::input('pwd', '管理密码')->type('password')->placeholder('请填写管理员密码');
  100. $field[] = Form::input('conf_pwd', '确认密码')->type('password')->placeholder('请输入确认密码');
  101. $field[] = Form::input('real_name', '区域代理姓名', $adminInfo['real_name'] ?? '')->required('请输入管理员姓名');
  102. /** @var SystemRoleServices $service */
  103. $service = app()->make(SystemRoleServices::class);
  104. $options = $service->getRoleFormSelect(1);
  105. $field[] = Form::select('roles', '管理员身份', $adminInfo['roles'] ?? [])->setOptions(Form::setOptions($options))->multiple(true)->required('请选择管理员身份');
  106. return create_form($title, $field, Route::buildUrl('/agent/division/save'), 'POST');
  107. }
  108. /**
  109. * 保存事业部数据
  110. * @param $data
  111. * @return mixed
  112. */
  113. public function divisionSave($data)
  114. {
  115. if ((int)$data['uid'] == 0) throw new AdminException(400450);
  116. $uid = $data['uid'];
  117. $aid = $data['aid'];
  118. $agentData = [
  119. 'division_percent' => $data['division_percent'],
  120. 'division_end_time' => strtotime($data['division_end_time']),
  121. 'division_change_time' => time(),
  122. 'is_division' => 1,
  123. 'is_agent' => 0,
  124. 'is_staff' => 0,
  125. 'division_id' => $uid,
  126. 'agent_id' => 0,
  127. 'staff_id' => 0,
  128. 'division_type' => 1,
  129. 'division_status' => $data['division_status'],
  130. 'spread_uid' => 0,
  131. 'spread_time' => 0
  132. ];
  133. $adminData = [
  134. 'account' => $data['account'],
  135. 'pwd' => $data['pwd'],
  136. 'conf_pwd' => $data['conf_pwd'],
  137. 'real_name' => $data['real_name'],
  138. 'roles' => $data['roles'],
  139. 'status' => 1,
  140. 'level' => 1,
  141. 'division_id' => $uid
  142. ];
  143. return $this->transaction(function () use ($uid, $agentData, $adminData, $aid) {
  144. /** @var UserServices $userServices */
  145. $userServices = app()->make(UserServices::class);
  146. $agentData['division_invite'] = $userServices->value(['uid' => $uid], 'division_invite') ?: rand(10000000, 99999999);
  147. $userServices->update($uid, $agentData);
  148. /** @var SystemAdminServices $adminService */
  149. $adminService = app()->make(SystemAdminServices::class);
  150. if (!$aid) {
  151. if ($adminData['pwd']) {
  152. if (!$adminData['conf_pwd']) throw new AdminException(400263);
  153. if ($adminData['pwd'] != $adminData['conf_pwd']) throw new AdminException(400264);
  154. $adminService->create($adminData);
  155. } else {
  156. throw new AdminException(400263);
  157. }
  158. } else {
  159. $adminInfo = $adminService->get($aid);
  160. if (!$adminInfo)
  161. throw new AdminException(400451);
  162. if ($adminInfo->is_del) {
  163. throw new AdminException(400452);
  164. }
  165. if (!$adminData['real_name'])
  166. throw new AdminException(400453);
  167. if ($adminData['pwd']) {
  168. if (!$adminData['conf_pwd']) throw new AdminException(400263);
  169. if ($adminData['pwd'] != $adminData['conf_pwd']) throw new AdminException(400264);
  170. $adminInfo->pwd = $this->passwordHash($adminData['pwd']);
  171. }
  172. $adminInfo->real_name = $adminData['real_name'];
  173. $adminInfo->account = $adminData['account'];
  174. $adminInfo->roles = implode(',', $adminData['roles']);
  175. if ($adminInfo->save())
  176. return true;
  177. else
  178. return false;
  179. }
  180. return true;
  181. });
  182. }
  183. // /**
  184. // * 生成邀请码
  185. // * @return false|string
  186. // */
  187. // public function getDivisionInvite()
  188. // {
  189. // /** @var UserServices $userServices */
  190. // $userServices = app()->make(UserServices::class);
  191. // list($msec, $sec) = explode(' ', microtime());
  192. // $num = time() + mt_rand(10, 999999) . '' . substr($msec, 2, 3);//生成随机数
  193. // if (strlen($num) < 12)
  194. // $num = str_pad((string)$num, 8, 0, STR_PAD_RIGHT);
  195. // else
  196. // $num = substr($num, 0, 8);
  197. // if ($userServices->count(['division_invite' => $num])) {
  198. // return $this->getDivisionInvite();
  199. // }
  200. // return $num;
  201. // }
  202. /**
  203. * 添加编辑代理商
  204. * @param $uid
  205. * @return array
  206. * @throws \FormBuilder\Exception\FormBuilderException
  207. */
  208. public function getDivisionAgentForm($uid)
  209. {
  210. /** @var UserServices $userService */
  211. $userService = app()->make(UserServices::class);
  212. $userInfo = $userService->get($uid);
  213. if ($uid && !$userInfo) throw new AdminException(400214);
  214. $field = [];
  215. if ($uid) {
  216. $field[] = Form::number('division_id', '事业部UID', $userInfo['division_id'] ?? '')->disabled(true)->style(['width' => '173px']);
  217. $field[] = Form::number('uid', '用户UID', $userInfo['uid'] ?? '')->disabled(true)->style(['width' => '173px']);
  218. $field[] = Form::hidden('edit', 1);
  219. } else {
  220. $field[] = Form::number('division_id', '事业部UID')->style(['width' => '173px']);
  221. $field[] = Form::number('uid', '用户UID')->style(['width' => '173px']);
  222. $field[] = Form::hidden('edit', 0);
  223. }
  224. $field[] = Form::number('division_percent', '佣金比例', $userInfo['division_percent'] ?? '')->placeholder('代理商佣金比例1-100')->info('填写1-100,如填写50代表返佣50%,但是不能高于上级事业部的比例')->style(['width' => '173px'])->min(0)->max(100)->required();
  225. $field[] = Form::date('division_end_time', '到期时间', ($userInfo['division_end_time'] ?? '') != 0 ? date('Y-m-d H:i:s', $userInfo['division_end_time']) : '')->placeholder('代理商代理到期时间');
  226. $field[] = Form::radio('division_status', '代理状态', $userInfo['division_status'] ?? 1)->options([['label' => '开通', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  227. return create_form('代理商', $field, Route::buildUrl('/agent/division/agent/save'), 'POST');
  228. }
  229. /**
  230. * 保存代理商
  231. * @param $data
  232. * @return bool
  233. * @throws \think\db\exception\DataNotFoundException
  234. * @throws \think\db\exception\DbException
  235. * @throws \think\db\exception\ModelNotFoundException
  236. */
  237. public function divisionAgentSave($data)
  238. {
  239. /** @var UserServices $userServices */
  240. $userServices = app()->make(UserServices::class);
  241. $uid = $data['uid'];
  242. $agentData = [
  243. 'division_id' => $data['division_id'],
  244. 'division_status' => $data['division_status'],
  245. 'division_percent' => $data['division_percent'],
  246. 'division_change_time' => time(),
  247. 'division_end_time' => strtotime($data['division_end_time']),
  248. 'division_type' => 2,
  249. 'is_agent' => 1,
  250. 'agent_id' => $uid
  251. ];
  252. $division_info = $userServices->getUserInfo($data['division_id'], 'division_end_time,division_percent');
  253. if ($division_info) {
  254. if ($agentData['division_percent'] > $division_info['division_percent']) throw new AdminException(400448);
  255. if ($agentData['division_end_time'] > $division_info['division_end_time']) throw new AdminException(400449);
  256. }
  257. $res = $userServices->update($uid, $agentData);
  258. if ($res) return true;
  259. throw new AdminException('保存失败');
  260. }
  261. /**
  262. * 修改状态
  263. * @param $status
  264. * @param $uid
  265. * @return bool
  266. */
  267. public function setDivisionStatus($status, $uid)
  268. {
  269. /** @var UserServices $userServices */
  270. $userServices = app()->make(UserServices::class);
  271. /** @var SystemAdminServices $adminServices */
  272. $adminServices = app()->make(SystemAdminServices::class);
  273. $res = $userServices->update($uid, ['division_status' => $status]);
  274. $res = $res && $adminServices->update(['division_id' => $uid], ['status' => $status]);
  275. if ($res) {
  276. return true;
  277. } else {
  278. throw new AdminException(100005);
  279. }
  280. }
  281. /**
  282. * 删除事业部/代理商
  283. * @param $type
  284. * @param $uid
  285. * @return mixed
  286. */
  287. public function delDivision($type, $uid)
  288. {
  289. return $this->transaction(function () use ($type, $uid) {
  290. /** @var UserServices $userServices */
  291. $userServices = app()->make(UserServices::class);
  292. switch ($type) {
  293. case 1:
  294. /** @var SystemAdminServices $adminService */
  295. $adminService = app()->make(SystemAdminServices::class);
  296. $adminService->delete(['division_id' => $uid]);
  297. break;
  298. }
  299. $data = [
  300. 'division_type' => 0,
  301. 'division_status' => 0,
  302. 'is_division' => 0,
  303. 'division_id' => 0,
  304. 'is_agent' => 0,
  305. 'agent_id' => 0,
  306. 'is_staff' => 0,
  307. 'staff_id' => 0,
  308. 'division_change_time' => time()
  309. ];
  310. $userServices->update($uid, $data);
  311. //删除申请代理商记录
  312. /** @var DivisionAgentApplyServices $divisionApply */
  313. $divisionApply = app()->make(DivisionAgentApplyServices::class);
  314. $divisionApply->update(['uid' => $uid], ['is_del' => 1]);
  315. });
  316. }
  317. /**
  318. * 获取返佣比例佣金比例
  319. * 当前方法会将获得的佣金逐步的递减
  320. * @param $uid
  321. * @param $storeBrokerageRatio
  322. * @param $storeBrokerageRatioTwo
  323. * @param $isSelfBrokerage
  324. * @return array
  325. */
  326. public function getDivisionPercent($uid, $storeBrokerageRatio, $storeBrokerageRatioTwo, $isSelfBrokerage)
  327. {
  328. $division_open = (int)sys_config('division_status', 1);
  329. if (!$division_open) {
  330. /** 代理商关闭 */
  331. $storeBrokerageOne = $storeBrokerageRatio;
  332. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  333. $staffPercent = 0;
  334. $agentPercent = 0;
  335. $divisionPercent = 0;
  336. } else {
  337. /** @var UserServices $userServices */
  338. $userServices = app()->make(UserServices::class);
  339. $userInfo = $userServices->get($uid);
  340. if ($userInfo['is_division'] == 1 && $userInfo['division_end_time'] > time()) {
  341. /** 自己是事业部 */
  342. if ($isSelfBrokerage) {
  343. $storeBrokerageOne = $storeBrokerageRatio;
  344. $storeBrokerageTwo = 0;
  345. $staffPercent = 0;
  346. $agentPercent = 0;
  347. $divisionPercent = 0;
  348. } else {
  349. $storeBrokerageOne = 0;
  350. $storeBrokerageTwo = 0;
  351. $staffPercent = 0;
  352. $agentPercent = 0;
  353. $divisionPercent = 0;
  354. }
  355. } elseif ($userInfo['is_agent'] == 1 && $userInfo['division_end_time'] > time()) {
  356. /** 自己是代理商 */
  357. $divisionInfo = $userServices->get($userInfo['division_id']);
  358. if ($isSelfBrokerage) {
  359. $storeBrokerageOne = $storeBrokerageRatio;
  360. $storeBrokerageTwo = 0;
  361. $staffPercent = 0;
  362. $agentPercent = 0;
  363. $divisionPercent = $divisionInfo['division_percent'] - $storeBrokerageOne;
  364. } else {
  365. $storeBrokerageOne = 0;
  366. $storeBrokerageTwo = 0;
  367. $staffPercent = 0;
  368. $agentPercent = 0;
  369. $divisionPercent = $divisionInfo['division_percent'];
  370. }
  371. } elseif ($userInfo['is_staff'] == 1 && $userInfo['division_end_time'] > time()) { // 自己是员工
  372. /** 自己是员工 */
  373. $agentInfo = $userServices->get($userInfo['agent_id']);
  374. $divisionInfo = $userServices->get($userInfo['division_id']);
  375. if ($isSelfBrokerage) {
  376. $storeBrokerageOne = $storeBrokerageRatio;
  377. $storeBrokerageTwo = 0;
  378. $staffPercent = 0;
  379. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne;
  380. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  381. } else {
  382. $storeBrokerageOne = 0;
  383. $storeBrokerageTwo = 0;
  384. $staffPercent = 0;
  385. $agentPercent = $agentInfo['division_percent'];
  386. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  387. }
  388. } else {
  389. /** 自己是普通用户 */
  390. $staffInfo = $userServices->get($userInfo['staff_id']);
  391. $agentInfo = $userServices->get($userInfo['agent_id']);
  392. $divisionInfo = $userServices->get($userInfo['division_id']);
  393. if ($userInfo['staff_id']) {
  394. /** 该用户为员工推广 */
  395. if ($userInfo['staff_id'] == $userInfo['spread_uid']) {
  396. /** 员工直接下级 */
  397. if ($isSelfBrokerage) {
  398. $storeBrokerageOne = $storeBrokerageRatio;
  399. $storeBrokerageTwo = $staffInfo['division_percent'] - $storeBrokerageOne;
  400. $staffPercent = 0;
  401. $agentPercent = $agentInfo['division_percent'] - $staffInfo['division_percent'];
  402. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  403. } else {
  404. $storeBrokerageOne = $staffInfo['division_percent'];
  405. $storeBrokerageTwo = 0;
  406. $staffPercent = 0;
  407. $agentPercent = $agentInfo['division_percent'] - $staffInfo['division_percent'];
  408. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  409. }
  410. } elseif ($userServices->value(['uid' => $userInfo['spread_uid']], 'spread_uid') == $userInfo['staff_id']) {
  411. /** 员工间接下级 */
  412. if ($isSelfBrokerage) {
  413. $storeBrokerageOne = $storeBrokerageRatio;
  414. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  415. $staffPercent = 0;
  416. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne - $storeBrokerageTwo;
  417. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  418. } else {
  419. $storeBrokerageOne = $storeBrokerageRatio;
  420. $storeBrokerageTwo = 0;
  421. $staffPercent = $staffInfo['division_percent'] - $storeBrokerageOne;
  422. $agentPercent = $agentInfo['division_percent'] - $staffInfo['division_percent'];
  423. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  424. }
  425. } else {
  426. /** 和员工的关系超过两级 */
  427. $storeBrokerageOne = $storeBrokerageRatio;
  428. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  429. $staffPercent = 0;
  430. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne - $storeBrokerageTwo;
  431. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  432. }
  433. } elseif ($userInfo['agent_id']) {
  434. /** 该用户为代理商推广 */
  435. if ($userInfo['agent_id'] == $userInfo['spread_uid']) {
  436. /** 代理商直接下级 */
  437. if ($isSelfBrokerage) {
  438. $storeBrokerageOne = $storeBrokerageRatio;
  439. $storeBrokerageTwo = 0;
  440. $staffPercent = 0;
  441. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne;
  442. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  443. } else {
  444. $storeBrokerageOne = 0;
  445. $storeBrokerageTwo = 0;
  446. $staffPercent = 0;
  447. $agentPercent = $agentInfo['division_percent'];
  448. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  449. }
  450. } elseif ($userServices->value(['uid' => $userInfo['spread_uid']], 'spread_uid') == $userInfo['agent_id']) {
  451. /** 代理商间接下级 */
  452. if ($isSelfBrokerage) {
  453. $storeBrokerageOne = $storeBrokerageRatio;
  454. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  455. $staffPercent = 0;
  456. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne - $storeBrokerageTwo;
  457. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  458. } else {
  459. $storeBrokerageOne = $storeBrokerageRatio;
  460. $storeBrokerageTwo = 0;
  461. $staffPercent = 0;
  462. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageOne;
  463. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  464. }
  465. } else {
  466. /** 和代理商的关系超过两级 */
  467. $storeBrokerageOne = $storeBrokerageRatio;
  468. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  469. $staffPercent = 0;
  470. $agentPercent = $agentInfo['division_percent'] - $storeBrokerageRatio - $storeBrokerageTwo;
  471. $divisionPercent = $divisionInfo['division_percent'] - $agentInfo['division_percent'];
  472. }
  473. } elseif ($userInfo['division_id']) {
  474. /** 该用户为事业部推广 */
  475. if ($userInfo['division_id'] == $userInfo['spread_uid']) {
  476. /** 事业部直接下级 */
  477. if ($isSelfBrokerage) {
  478. $storeBrokerageOne = $storeBrokerageRatio;
  479. $storeBrokerageTwo = 0;
  480. $staffPercent = 0;
  481. $agentPercent = 0;
  482. $divisionPercent = $divisionInfo['division_percent'] - $storeBrokerageOne;
  483. } else {
  484. $storeBrokerageOne = 0;
  485. $storeBrokerageTwo = 0;
  486. $staffPercent = 0;
  487. $agentPercent = 0;
  488. $divisionPercent = $divisionInfo['division_percent'];
  489. }
  490. } elseif ($userServices->value(['uid' => $userInfo['spread_uid']], 'spread_uid') == $userInfo['division_id']) {
  491. /** 事业部间接下级 */
  492. if ($isSelfBrokerage) {
  493. $storeBrokerageOne = $storeBrokerageRatio;
  494. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  495. $staffPercent = 0;
  496. $agentPercent = 0;
  497. $divisionPercent = $divisionInfo['division_percent'] - $storeBrokerageOne - $storeBrokerageTwo;
  498. } else {
  499. $storeBrokerageOne = $storeBrokerageRatio;
  500. $storeBrokerageTwo = 0;
  501. $staffPercent = 0;
  502. $agentPercent = 0;
  503. $divisionPercent = $divisionInfo['division_percent'] - $storeBrokerageOne;
  504. }
  505. } else {
  506. /** 和事业部的关系超过两级 */
  507. $storeBrokerageOne = $storeBrokerageRatio;
  508. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  509. $staffPercent = 0;
  510. $agentPercent = 0;
  511. $divisionPercent = $divisionInfo['division_percent'] - $storeBrokerageOne - $storeBrokerageTwo;
  512. }
  513. } else {
  514. /** 没有任何代理商关系 */
  515. $storeBrokerageOne = $storeBrokerageRatio;
  516. $storeBrokerageTwo = $storeBrokerageRatioTwo;
  517. $staffPercent = 0;
  518. $agentPercent = 0;
  519. $divisionPercent = 0;
  520. }
  521. }
  522. }
  523. return [max($storeBrokerageOne, 0), max($storeBrokerageTwo, 0), max($staffPercent, 0), max($agentPercent, 0), max($divisionPercent, 0)];
  524. }
  525. }