User.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. <?php
  2. namespace app\models\user;
  3. use app\models\store\StoreOrder;
  4. use app\models\store\StoreOrderCartInfo;
  5. use app\models\store\StoreProduct;
  6. use crmeb\services\SystemConfigService;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use think\Exception;
  11. use think\facade\Session;
  12. use crmeb\traits\ModelTrait;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\JwtAuthModelTrait;
  15. /**
  16. * TODO 用户Model
  17. * Class User
  18. * @package app\models\user
  19. */
  20. class User extends BaseModel
  21. {
  22. use JwtAuthModelTrait;
  23. use ModelTrait;
  24. protected $pk = 'uid';
  25. protected $name = 'user';
  26. protected $insert = ['add_time', 'add_ip', 'last_time', 'last_ip'];
  27. protected $hidden = [
  28. 'add_ip', 'add_time', 'account', 'clean_time', 'last_ip', 'last_time', 'pwd', 'status', 'mark', 'pwd'
  29. ];
  30. protected function setAddTimeAttr($value)
  31. {
  32. return time();
  33. }
  34. protected function setAddIpAttr($value)
  35. {
  36. return app('request')->ip();
  37. }
  38. protected function setLastTimeAttr($value)
  39. {
  40. return time();
  41. }
  42. protected function setLastIpAttr($value)
  43. {
  44. return app('request')->ip();
  45. }
  46. /**
  47. * @param $wechatUser
  48. * @param int $spread_uid
  49. * @return bool
  50. * @throws DataNotFoundException
  51. * @throws DbException
  52. * @throws ModelNotFoundException
  53. */
  54. public static function setWechatUser($wechatUser, $spread_uid = 0)
  55. {
  56. $storeBrokerageStatu = sys_config('store_brokerage_statu') ?: 1;//获取后台分销类型
  57. $res = self::create([
  58. 'account' => 'wx' . $wechatUser['uid'] . time(),
  59. 'pwd' => md5(123456),
  60. 'nickname' => $wechatUser['nickname'] ?: '',
  61. 'avatar' => $wechatUser['headimgurl'] ?: '',
  62. 'add_time' => time(),
  63. 'add_ip' => app('request')->ip(),
  64. 'last_time' => time(),
  65. 'last_ip' => app('request')->ip(),
  66. 'uid' => $wechatUser['uid'],
  67. 'is_promoter' => $storeBrokerageStatu != 1 ? 1 : 0,
  68. 'user_type' => 'wechat'
  69. ]);
  70. return $res && UserSpread::setSpread($wechatUser['uid'], $spread_uid);
  71. }
  72. /**
  73. * TODO 获取会员是否被清除过的时间
  74. * @param $uid
  75. * @return int|mixed
  76. * @throws DataNotFoundException
  77. * @throws ModelNotFoundException
  78. * @throws DbException
  79. */
  80. public static function getCleanTime($uid)
  81. {
  82. $user = self::where('uid', $uid)->field(['add_time', 'clean_time'])->find();
  83. if (!$user) return 0;
  84. return $user['clean_time'] ? $user['clean_time'] : $user['add_time'];
  85. }
  86. /**
  87. * 更新用户信息
  88. * @param array $wechatUser 用户信息
  89. * @param int $uid 用户uid
  90. * @return bool|void
  91. * @throws DataNotFoundException
  92. * @throws ModelNotFoundException
  93. * @throws DbException
  94. */
  95. public static function updateWechatUser($wechatUser, $uid)
  96. {
  97. $userInfo = self::where('uid', $uid)->find();
  98. if (!$userInfo) return;
  99. //增加成为分销权限
  100. if (!$userInfo->is_promoter) {
  101. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $uid])->sum('pay_price');
  102. $status = is_brokerage_statu($price);
  103. } else {
  104. $status = false;
  105. }
  106. if ($userInfo->spread_uid) {
  107. return self::edit([
  108. 'nickname' => $wechatUser['nickname'] ?: '',
  109. 'avatar' => $wechatUser['headimgurl'] ?: '',
  110. 'is_promoter' => $status ? 1 : $userInfo->is_promoter,
  111. 'login_type' => isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
  112. ], $uid, 'uid');
  113. } else {
  114. $data = [
  115. 'nickname' => $wechatUser['nickname'] ?: '',
  116. 'avatar' => $wechatUser['headimgurl'] ?: '',
  117. 'is_promoter' => $status ? 1 : $userInfo->is_promoter,
  118. 'login_type' => isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
  119. // 'spread_uid' => 0,
  120. // 'spread_time' => 0,
  121. 'last_time' => time(),
  122. 'last_ip' => request()->ip(),
  123. ];
  124. //TODO 获取后台分销类型
  125. // $storeBrokerageStatus = sys_config('store_brokerage_statu');
  126. // $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  127. // if (isset($wechatUser['code']) && $wechatUser['code'] && $wechatUser['code'] != $uid && $uid != self::where('uid', $wechatUser['code'])->value('spread_uid')) {
  128. // if ($storeBrokerageStatus == 1) {
  129. // $spreadCount = self::where('uid', $wechatUser['code'])->count();
  130. // if ($spreadCount) {
  131. // $spreadInfo = self::where('uid', $wechatUser['code'])->find();
  132. // if ($spreadInfo->is_promoter) {
  133. // //TODO 只有扫码才可以获得推广权限
  134. //// if(isset($wechatUser['isPromoter'])) $data['is_promoter'] = $wechatUser['isPromoter'] ? 1 : 0;
  135. // }
  136. // }
  137. // }
  138. // $data['spread_uid'] = $wechatUser['code'];
  139. // $data['spread_time'] = time();
  140. // }
  141. return self::edit($data, $uid, 'uid') && UserSpread::setSpread($uid, $wechatUser['code'] ?? 0);
  142. }
  143. }
  144. /**
  145. * 设置推广关系
  146. * @param $spread
  147. * @param $uid
  148. * @return bool
  149. * @throws DataNotFoundException
  150. * @throws ModelNotFoundException
  151. * @throws DbException
  152. */
  153. public static function setSpread($spread, $uid)
  154. {
  155. return UserSpread::setSpread($uid, $spread);
  156. //当前用户信息
  157. // $userInfo = self::where('uid', $uid)->find();
  158. // if (!$userInfo) return true;
  159. // //当前用户有上级直接返回
  160. // if ($userInfo->spread_uid) return true;
  161. // //没有推广编号直接返回
  162. // if (!$spread) return true;
  163. // if ($spread == $uid) return true;
  164. // if ($uid == self::where('uid', $spread)->value('spread_uid')) return true;
  165. // //TODO 获取后台分销类型
  166. // $storeBrokerageStatus = sys_config('store_brokerage_statu');
  167. // $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  168. // if ($storeBrokerageStatus == 1) {
  169. // $spreadCount = self::where('uid', $spread)->count();
  170. // if ($spreadCount) {
  171. // $spreadInfo = self::where('uid', $spread)->find();
  172. // if ($spreadInfo->is_promoter) {
  173. // //TODO 只有扫码才可以获得推广权限
  174. //// if(isset($wechatUser['isPromoter'])) $data['is_promoter'] = $wechatUser['isPromoter'] ? 1 : 0;
  175. // }
  176. // }
  177. // }
  178. // $data['spread_uid'] = $spread;
  179. // $data['spread_time'] = time();
  180. // return self::edit($data, $uid, 'uid');
  181. }
  182. /**
  183. * 小程序用户添加
  184. * @param $routineUser
  185. * @param int $spread_uid
  186. * @return object
  187. * @throws DataNotFoundException
  188. * @throws DbException
  189. * @throws ModelNotFoundException
  190. */
  191. public static function setRoutineUser($routineUser, $spread_uid = 0)
  192. {
  193. self::beginTrans();
  194. $res1 = true;
  195. if ($spread_uid) $res1 = self::where('uid', $spread_uid)->inc('spread_count', 1)->update();
  196. $storeBrokerageStatu = sys_config('store_brokerage_statu') ?: 1;//获取后台分销类型
  197. $res2 = self::create([
  198. 'account' => 'rt' . $routineUser['uid'] . time(),
  199. 'pwd' => md5(123456),
  200. 'nickname' => $routineUser['nickname'] ?: '',
  201. 'avatar' => $routineUser['headimgurl'] ?: '',
  202. // 'spread_uid' => $spread_uid,
  203. 'is_promoter' => $storeBrokerageStatu != 1 ? 1 : 0,
  204. // 'spread_time' => $spread_uid ? time() : 0,
  205. 'uid' => $routineUser['uid'],
  206. 'add_time' => $routineUser['add_time'],
  207. 'add_ip' => request()->ip(),
  208. 'last_time' => time(),
  209. 'last_ip' => request()->ip(),
  210. 'user_type' => $routineUser['user_type']
  211. ]);
  212. $res = $res1 && $res2 && UserSpread::setSpread($routineUser['uid'], $spread_uid);
  213. self::checkTrans($res);
  214. return $res2;
  215. }
  216. /**
  217. * 获得当前登陆用户UID
  218. * @return int $uid
  219. */
  220. public static function getActiveUid()
  221. {
  222. $uid = null;
  223. $uid = Session::get('LoginUid');
  224. if ($uid) return $uid;
  225. else return 0;
  226. }
  227. /**
  228. * TODO 查询当前用户信息
  229. * @param $uid $uid 用户编号
  230. * @param string $field $field 查询的字段
  231. * @return array
  232. * @throws DataNotFoundException
  233. * @throws ModelNotFoundException
  234. * @throws DbException
  235. */
  236. public static function getUserInfo($uid, $field = '')
  237. {
  238. if (strlen(trim($field))) $userInfo = self::where('uid', $uid)->field($field)->find();
  239. else $userInfo = self::where('uid', $uid)->find();
  240. if (!$userInfo) return [];
  241. return $userInfo->toArray();
  242. }
  243. /**
  244. * 判断当前用户是否推广员
  245. * @param int $uid
  246. * @return bool
  247. */
  248. public static function isUserSpread($uid = 0)
  249. {
  250. if (!$uid) return false;
  251. $status = (int)sys_config('store_brokerage_statu');
  252. $isPromoter = true;
  253. if ($status == 1) $isPromoter = self::where('uid', $uid)->value('is_promoter');
  254. if ($isPromoter) return true;
  255. else return false;
  256. }
  257. /**
  258. * TODO 一级返佣
  259. * @param $orderInfo
  260. * @return bool
  261. * @throws DataNotFoundException
  262. * @throws ModelNotFoundException
  263. * @throws DbException
  264. */
  265. public static function backOrderBrokerage($orderInfo, bool $open = true)
  266. {
  267. //TODO 营销产品不返佣金
  268. if (isset($orderInfo['combination_id']) && $orderInfo['combination_id']) return true;
  269. if (isset($orderInfo['seckill_id']) && $orderInfo['seckill_id']) return true;
  270. if (isset($orderInfo['bargain_id']) && $orderInfo['bargain_id']) return true;
  271. $userInfo = User::getUserInfo($orderInfo['uid']);
  272. //TODO 当前用户不存在 没有上级 或者 当用用户上级时自己 直接返回
  273. if (!$userInfo || !$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid']) return true;
  274. if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return self::backOrderBrokerageTwo($orderInfo, $open);
  275. $cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
  276. list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($userInfo['uid'], $userInfo['spread_uid'], $cartId);
  277. //TODO 返佣金额小于等于0 直接返回不返佣金
  278. if ($realBrokeragePrice <= 0 && $virtualBrokeragePrice <= 0) return true;
  279. //TODO 获取上级推广员信息
  280. // $open && self::beginTrans();
  281. $res = true;
  282. if ($virtualBrokeragePrice > 0) {
  283. $spreadUserInfo = User::getUserInfo($userInfo['spread_uid']);
  284. //TODO 上级推广员返佣之后的金额
  285. $balance = bcadd($spreadUserInfo['brokerage_price'], $virtualBrokeragePrice, 2);
  286. $mark = $userInfo['nickname'] . '成功消费[虚拟产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($virtualBrokeragePrice);
  287. //TODO 添加推广记录
  288. $res1 = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $virtualBrokeragePrice, $orderInfo['id'], $balance, $mark);
  289. //TODO 添加用户余额
  290. $res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $virtualBrokeragePrice, 'uid');
  291. //TODO 一级返佣成功 跳转二级返佣
  292. $res = $res1 && $res2;
  293. }
  294. if ($realBrokeragePrice > 0) {
  295. $spreadUserInfo = User::getUserInfo($userInfo['spread_uid']);
  296. $order_count = StoreOrder::where('uid', $userInfo['uid'])->where('paid', 1)->count();
  297. $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $cartId)->column('cart_info');
  298. $repurchase = 0;
  299. foreach ($cartInfo as $value) {
  300. $product = json_decode($value, true);
  301. $product_fg = StoreProduct::where('id', $product['product_id'])->value('is_best');
  302. if ($product_fg > 0) {
  303. $repurchase = 1;
  304. }
  305. }
  306. //TODO 上级推广员返佣之后的金额
  307. //TODO 添加推广记录
  308. if ($repurchase == 0) {
  309. $brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
  310. $integral = $realBrokeragePrice * 0.05;// 到账积分
  311. $mark = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokerage_price);
  312. $mark1 = $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广积分' . floatval($integral);
  313. $res = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $spreadUserInfo['brokerage_price'] + $brokerage_price, $mark);
  314. $res = UserBill::income('获得推广积分', $userInfo['spread_uid'], 'integral', 'push', $integral, $orderInfo['id'], $spreadUserInfo['integral'] + $integral, $mark1);
  315. $res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokerage_price, 'uid');
  316. $res2 = self::bcInc($userInfo['spread_uid'], 'integral', $integral, 'uid');
  317. if ($spreadUserInfo['identity'] == 1) {
  318. $uid = getParent($userInfo['spread_uid'], User::select()); //找到最上级
  319. if (count($uid) > 0) {
  320. $uid1 = array_pop($uid);
  321. $user1 = User::where('uid', $uid1)->find();
  322. if ($user1['line'] >= 3) {
  323. $amministrazione = User::where('uid', $user1['spread_uid'])->find();// 发放管理奖
  324. if ($amministrazione) {
  325. $realBrokeragePrice = $realBrokeragePrice * (sys_config('administration') / 100);
  326. $brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
  327. $integral = $realBrokeragePrice * 0.05;// 到账积分
  328. UserBill::income('获得推广佣金', $amministrazione['uid'], 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $amministrazione['brokerage_price'] + $brokerage_price, '管理佣金奖励');
  329. UserBill::income('获得推广积分', $amministrazione['uid'], 'integral', 'Level', $integral, $orderInfo['id'], $amministrazione['integral'] + $integral, '管理积分奖励');
  330. self::bcInc($amministrazione['uid'], 'brokerage_price', $brokerage_price, 'uid'); //发放管理奖
  331. self::bcInc($amministrazione['uid'], 'integral', $integral, 'uid'); //发放管理奖
  332. self::livello($amministrazione['spread_uid'], $realBrokeragePrice);
  333. }
  334. }
  335. }
  336. } elseif ($spreadUserInfo['identity'] == 2) {
  337. self::livello($spreadUserInfo['spread_uid'], $realBrokeragePrice);
  338. }
  339. } else {
  340. $brokerage_price = $realBrokeragePrice * 0.95;// 到账佣金
  341. $integral = $realBrokeragePrice * 0.05;// 到账积分
  342. $mark = $userInfo['nickname'] . '复购成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokerage_price);
  343. $mark1 = $userInfo['nickname'] . '复购成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广积分' . floatval($integral);
  344. $res = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokerage_price, $orderInfo['id'], $spreadUserInfo['brokerage_price'] + $brokerage_price, $mark);
  345. $res = UserBill::income('获得推广积分', $userInfo['spread_uid'], 'integral', 'push', $integral, $orderInfo['id'], $spreadUserInfo['integral'] + $integral, $mark1);
  346. $res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokerage_price, 'uid');
  347. $res2 = self::bcInc($userInfo['spread_uid'], 'integral', $integral, 'uid');
  348. }
  349. }
  350. // $res = $res && self::backOrderBrokerageTwo($orderInfo);
  351. // $open && self::checkTrans($res);
  352. return $res;
  353. }
  354. /**
  355. * 平级奖励
  356. * @param $uid
  357. * @param $price
  358. * @return void
  359. */
  360. public static function livello($uid, $price)
  361. {
  362. $uids = getParent_livello($uid, User::select());
  363. if (count($uids) > 0) {
  364. // 第一级店长
  365. if (isset($uids[0])) {
  366. $user = User::where('uid', $uids[0])->find();
  367. $price1 = $price * 0.7;
  368. $brokerage_price = $price1 * 0.95;// 到账佣金
  369. $integral = $price1 * 0.05;// 到账积分
  370. UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励');
  371. UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励');
  372. self::bcInc($user['uid'], 'brokerage_price', $brokerage_price, 'uid'); //发放管理奖
  373. self::bcInc($user['uid'], 'integral', $integral, 'uid'); //发放管理奖
  374. }
  375. if (isset($uids[1])) {
  376. // 第二级店长
  377. $user = User::where('uid', $uids[1])->find();
  378. $price2 = $price * 0.3;
  379. $brokerage_price = $price2 * 0.95;// 到账佣金
  380. $integral = $price2 * 0.05;// 到账积分
  381. if (UserLevel::getUserLevelInfo(UserLevel::getUserLevel($uids[1]), 'level_id') < 2) {
  382. UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励', 0, 1);
  383. UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励', 0, 1);
  384. } else {
  385. UserBill::income('获得推广佣金', $user['uid'], 'now_money', 'brokerage', $brokerage_price, '', $user['brokerage_price'] + $brokerage_price, '店长平级佣金奖励');
  386. UserBill::income('获得推广积分', $user['uid'], 'integral', 'Level', $integral, '', $user['integral'] + $integral, '店长平级积分奖励');
  387. self::bcInc($user['uid'], 'brokerage_price', $brokerage_price, 'uid'); //发放管理奖
  388. self::bcInc($user['uid'], 'integral', $integral, 'uid'); //发放管理奖
  389. }
  390. }
  391. }
  392. }
  393. /**
  394. * TODO 二级推广
  395. * @param $orderInfo
  396. * @return bool
  397. * @throws DataNotFoundException
  398. * @throws ModelNotFoundException
  399. * @throws DbException
  400. */
  401. public static function backOrderBrokerageTwo($orderInfo, bool $open = true)
  402. {
  403. //TODO 获取购买商品的用户
  404. $userInfo = User::getUserInfo($orderInfo['uid']);
  405. //TODO 获取上推广人
  406. $userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
  407. //TODO 上推广人不存在 或者 上推广人没有上级 或者 当用用户上上级时自己 直接返回
  408. if (!$userInfoTwo || !$userInfoTwo['spread_uid'] || $userInfoTwo['spread_uid'] == $orderInfo['uid']) return true;
  409. //TODO 获取后台分销类型 1 指定分销 2 人人分销
  410. if (!User::be(['uid' => $userInfoTwo['spread_uid'], 'is_promoter' => 1])) return true;
  411. $cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
  412. list($realBrokeragePrice, $virtualBrokeragePrice) = StoreProduct::getProductBrokerage($cartId, false);
  413. //TODO 返佣金额小于等于0 直接返回不返佣金
  414. if ($realBrokeragePrice <= 0 && $virtualBrokeragePrice <= 0) return true;
  415. // $open && self::beginTrans();
  416. $res = true;
  417. if ($virtualBrokeragePrice > 0) {
  418. $spreadUserInfoTwo = User::getUserInfo($userInfoTwo['spread_uid']);
  419. //TODO 上级推广员返佣之后的金额
  420. $balance = bcadd($spreadUserInfoTwo['brokerage_price'], $virtualBrokeragePrice, 2);
  421. $mark = '二级推广人' . $userInfo['nickname'] . '成功消费[虚拟产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($virtualBrokeragePrice);
  422. //TODO 添加推广记录
  423. $res1 = UserBill::income('获得推广佣金', $userInfoTwo['spread_uid'], 'now_money', 'brokerage', $virtualBrokeragePrice, $orderInfo['id'], $balance, $mark);
  424. //TODO 添加用户余额
  425. $res2 = self::bcInc($userInfoTwo['spread_uid'], 'brokerage_price', $virtualBrokeragePrice, 'uid');
  426. //TODO 一级返佣成功 跳转二级返佣
  427. $res = $res1 && $res2;
  428. }
  429. if ($realBrokeragePrice > 0) {
  430. $spreadUserInfoTwo = User::getUserInfo($userInfoTwo['spread_uid']);
  431. //TODO 上级推广员返佣之后的金额
  432. $mark = '二级推广人' . $userInfo['nickname'] . '成功消费[实体产品]' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($realBrokeragePrice);
  433. //TODO 添加推广记录
  434. $res = UserBill::income('获得推广佣金', $userInfoTwo['spread_uid'], 'now_money', 'brokerage', $realBrokeragePrice, $orderInfo['id'], $spreadUserInfoTwo['brokerage_price'], $mark, 0);
  435. }
  436. // $res = $res && self::backOrderBrokerageTwo($orderInfo);
  437. // $open && self::checkTrans($res);
  438. return $res;
  439. }
  440. /**
  441. * 发放实际商品佣金
  442. * @param $orderInfo
  443. * @return bool
  444. * @throws DataNotFoundException
  445. * @throws DbException
  446. * @throws ModelNotFoundException
  447. */
  448. public static function sendBackOrderBrokerage($orderInfo)
  449. {
  450. $list = UserBill::where(['link_id' => $orderInfo['id'], 'type' => 'brokerage', 'category' => 'now_money', 'pm' => 1, 'status' => 0])->select();
  451. if ($list) {
  452. self::beginTrans();
  453. try {
  454. foreach ($list as $v) {
  455. self::bcInc($v['uid'], 'brokerage_price', $v['number'], 'uid');
  456. $balance = self::getUserInfo($v['uid'])['brokerage_price'];
  457. UserBill::where('id', $v['id'])->update(['add_time' => time(), 'status' => 1, 'balance' => $balance]);
  458. }
  459. self::commitTrans();
  460. return true;
  461. } catch (Exception $e) {
  462. self::rollbackTrans();
  463. return false;
  464. }
  465. }
  466. return true;
  467. }
  468. /**
  469. * 发放实际商品佣金
  470. * @param $orderInfo
  471. * @return bool
  472. * @throws DataNotFoundException
  473. * @throws DbException
  474. * @throws ModelNotFoundException
  475. */
  476. public static function sendLockBrokerage($uid)
  477. {
  478. $list = UserBill::where(['uid' => $uid, 'type' => 'brokerage', 'category' => 'now_money', 'pm' => 1, 'status' => 0, 'lock' => 1])->select();
  479. $list2 = UserBill::where(['uid' => $uid, 'type' => 'Level', 'category' => 'integral', 'pm' => 1, 'status' => 0, 'lock' => 1])->select();
  480. if ($list || $list2) {
  481. // self::beginTrans();
  482. try {
  483. foreach ($list as $v) {
  484. self::bcInc($v['uid'], 'brokerage_price', $v['number'], 'uid');
  485. $balance = self::getUserInfo($v['uid'])['brokerage_price'];
  486. UserBill::where('id', $v['id'])->update(['add_time' => time(), 'status' => 1, 'balance' => $balance]);
  487. }
  488. foreach ($list2 as $v) {
  489. $balance = self::getUserInfo($v['uid'])['integral'];
  490. self::bcInc($v['uid'], 'integral', $v['number'], 'uid');
  491. UserBill::where('id', $v['id'])->update(['add_time' => time(), 'status' => 1, 'balance' => $balance]);
  492. }
  493. // self::commitTrans();
  494. return true;
  495. } catch (Exception $e) {
  496. // self::rollbackTrans();
  497. return false;
  498. }
  499. }
  500. return true;
  501. }
  502. /**
  503. * 获取推荐人 暂无使用
  504. * @param $uid
  505. * @param $page
  506. * @param $limit
  507. * @return mixed
  508. */
  509. public static function getSpreadList($uid, $page, $limit)
  510. {
  511. $list = self::where('spread_uid', $uid)->field('uid,nickname,avatar,add_time')->page($page, $limit)->order('add_time DESC')->select();
  512. foreach ($list as $k => $user) {
  513. $list[$k]['add_time'] = date('Y/m/d', $user['add_time']);
  514. $list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
  515. }
  516. $count = self::where('spread_uid', $uid)->field('uid,nickname,avatar,add_time')->count();
  517. $data['count'] = $count;
  518. $data['list'] = $list;
  519. return $data;
  520. }
  521. /**
  522. * 获取某个用户的下级uid
  523. * @param $uid
  524. * @return array
  525. */
  526. public static function getOneSpreadUid($uid)
  527. {
  528. return self::where('spread_uid', $uid)->column('uid');
  529. }
  530. /**
  531. * 修改个人信息
  532. * @param $avatar 头像
  533. * @param $nickname 昵称
  534. * @param $uid 用户uid
  535. * @return bool
  536. */
  537. public static function editUser($avatar, $nickname, $uid)
  538. {
  539. return self::edit(['avatar' => $avatar, 'nickname' => $nickname], $uid, 'uid');
  540. }
  541. /**
  542. * TODO 获取推广人数 一级
  543. * @param int $uid
  544. * @return bool|int|string
  545. */
  546. public static function getSpreadCount($uid = 0)
  547. {
  548. if (!$uid) return false;
  549. return self::where('spread_uid', $uid)->count();
  550. }
  551. /**
  552. * 修改当前用户的推广人数
  553. * @param $uid
  554. */
  555. public static function setUserSpreadCount($uid)
  556. {
  557. if (!$uid) return true;
  558. if (self::getSpreadCount($uid) > 0) {
  559. self::where('uid', $uid)->update(['spread_count' => 0]);
  560. } else {
  561. self::where('uid', $uid)->update(['spread_count' => 0]);
  562. return true;
  563. }
  564. return self::where('uid', $uid)->update(['spread_count' => self::getSpreadCount($uid)]);
  565. }
  566. /**
  567. * TODO 获取推广人数 二级
  568. * @param int $uid
  569. * @return bool|int|string
  570. */
  571. public static function getSpreadLevelCount($uid = 0)
  572. {
  573. if (!$uid) return false;
  574. $uidSubordinate = self::where('spread_uid', $uid)->column('uid');
  575. if (!count($uidSubordinate)) return 0;
  576. return self::where('spread_uid', 'IN', implode(',', $uidSubordinate))->count();
  577. }
  578. /**
  579. * 获取用户下级推广人
  580. * @param int $uid 当前用户
  581. * @param int $grade 等级 0 一级 1 二级
  582. * @param string $orderBy 排序
  583. * @param string $keyword
  584. * @param int $page
  585. * @param int $limit
  586. * @return array|bool
  587. */
  588. public static function getUserSpreadGrade($uid = 0, $grade = 0, $orderBy = '', $keyword = '', $page = 0, $limit = 20)
  589. {
  590. if (!$uid) return [];
  591. $gradeGroup = [0, 1];
  592. if (!in_array($grade, $gradeGroup)) return self::setErrorInfo('等级错误');
  593. $userStair = self::where('spread_uid', $uid)->column('uid');
  594. if (!count($userStair)) return [];
  595. if ($grade == 0) return self::getUserSpreadCountList(implode(',', $userStair), $orderBy, $keyword, $page, $limit);
  596. $userSecondary = self::where('spread_uid', 'in', implode(',', $userStair))->column('uid');
  597. return self::getUserSpreadCountList(implode(',', $userSecondary), $orderBy, $keyword, $page, $limit);
  598. }
  599. /**
  600. * 获取团队信息
  601. * @param $uid
  602. * @param string $orderBy
  603. * @param string $keyword
  604. * @param int $page
  605. * @param int $limit
  606. * @return array
  607. */
  608. public static function getUserSpreadCountList($uid, $orderBy = '', $keyword = '', $page = 0, $limit = 20)
  609. {
  610. $model = new self;
  611. if ($orderBy === '') $orderBy = 'u.add_time desc';
  612. $model = $model->alias(' u');
  613. $sql = StoreOrder::where('o.paid', 1)->group('o.uid')->field(['SUM(o.pay_price) as numberCount', 'o.uid', 'o.order_id'])
  614. ->where('o.is_del', 0)->where('o.is_system_del', 0)->alias('o')->fetchSql(true)->select();
  615. $model = $model->join("(" . $sql . ") p", 'u.uid = p.uid', 'LEFT');
  616. $model = $model->where('u.uid', 'IN', $uid);
  617. $model = $model->field("u.uid,u.nickname,u.avatar,from_unixtime(u.add_time,'%Y/%m/%d') as time,u.spread_count as childCount,u.pay_count as orderCount,p.numberCount");
  618. if (strlen(trim($keyword))) $model = $model->where('u.nickname|u.phone', 'like', "%$keyword%");
  619. $model = $model->group('u.uid');
  620. $model = $model->order($orderBy);
  621. $model = $model->page($page, $limit);
  622. $list = $model->select();
  623. if ($list) return $list->toArray();
  624. else return [];
  625. }
  626. /**
  627. * 设置用户的上级关系
  628. * @param $uid 用户uid
  629. * @param $spreadUid 上级用户uid
  630. * @return User|bool
  631. * @throws DataNotFoundException
  632. * @throws ModelNotFoundException
  633. * @throws DbException
  634. */
  635. public static function setSpreadUid($uid, $spreadUid)
  636. {
  637. return UserSpread::setSpread($uid, $spreadUid);
  638. // 自己不能绑定自己为上级
  639. // if ($uid == $spreadUid) return false;
  640. // //TODO 获取后台分销类型
  641. // $storeBrokerageStatus = sys_config('store_brokerage_statu');
  642. // $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  643. // if ($storeBrokerageStatus == 1) {
  644. // $spreadCount = self::where('uid', $spreadUid)->count();
  645. // if ($spreadCount) {
  646. // $spreadInfo = self::where('uid', $spreadUid)->find();
  647. // if ($spreadInfo->is_promoter) {
  648. // //TODO 只有扫码才可以获得推广权限
  649. // if (isset($wechatUser['isPromoter'])) $data['is_promoter'] = 1;
  650. // }
  651. // }
  652. // }
  653. // return self::where('uid', $uid)->update(['spread_uid' => $spreadUid, 'spread_time' => time()]);
  654. }
  655. /**
  656. * 判断上下级关系是否存在
  657. * @param $uid
  658. * @param $spreadUid
  659. * @return bool|int
  660. */
  661. public static function validSpread($uid, $spreadUid)
  662. {
  663. if (!$uid || !$spreadUid) return false;
  664. return self::where('uid', $uid)->where('spread_uid', $spreadUid)->count();
  665. }
  666. /**
  667. * H5用户注册
  668. * @param $account
  669. * @param $password
  670. * @param $spread
  671. * @return bool
  672. * @throws DataNotFoundException
  673. * @throws DbException
  674. * @throws ModelNotFoundException
  675. */
  676. public static function register($account, $password, $spread)
  677. {
  678. $storeBrokerageStatu = sys_config('store_brokerage_statu') ?: 1;//获取后台分销类型
  679. if (self::be(['account' => $account])) return self::setErrorInfo('用户已存在');
  680. $phone = $account;
  681. $data['account'] = $account;
  682. $data['pwd'] = md5($password);
  683. $data['phone'] = $phone;
  684. // if ($spread) {
  685. // $data['spread_uid'] = $spread;
  686. // $data['spread_time'] = time();
  687. // }
  688. $data['real_name'] = '';
  689. $data['birthday'] = 0;
  690. $data['card_id'] = '';
  691. $data['mark'] = '';
  692. $data['addres'] = '';
  693. $data['user_type'] = 'h5';
  694. $data['add_time'] = time();
  695. $data['add_ip'] = app('request')->ip();
  696. $data['last_time'] = time();
  697. $data['last_ip'] = app('request')->ip();
  698. $data['nickname'] = substr(md5($account . time()), 0, 12);
  699. $data['avatar'] = $data['headimgurl'] = sys_config('h5_avatar');
  700. $data['city'] = '';
  701. $data['language'] = '';
  702. $data['province'] = '';
  703. $data['country'] = '';
  704. $data['is_promoter'] = $storeBrokerageStatu != 1 ? 1 : 0;
  705. self::beginTrans();
  706. $res2 = WechatUser::create($data);
  707. $data['uid'] = $res2->uid;
  708. $res1 = self::create($data);
  709. $res = $res1 && $res2 && UserSpread::setSpread($data['uid'], $spread);
  710. self::checkTrans($res);
  711. return $res;
  712. }
  713. /**
  714. * 密码修改
  715. * @param $account
  716. * @param $password
  717. * @return User|bool
  718. */
  719. public static function reset($account, $password)
  720. {
  721. if (!self::be(['account' => $account])) return self::setErrorInfo('用户不存在');
  722. $count = self::where('account', $account)->where('pwd', md5($password))->count();
  723. if ($count) return true;
  724. return self::where('account', $account)->update(['pwd' => md5($password)]);
  725. }
  726. /**
  727. * 获取手机号是否注册
  728. * @param $phone
  729. * @return bool
  730. */
  731. public static function checkPhone($phone)
  732. {
  733. return self::be(['account' => $phone]);
  734. }
  735. /**
  736. * 获取推广人
  737. * @param $data 查询条件
  738. * @return array
  739. * @throws DataNotFoundException
  740. * @throws ModelNotFoundException
  741. * @throws \think\exception\DbException
  742. */
  743. public static function getRankList($data)
  744. {
  745. switch ($data['type']) {
  746. case 'week':
  747. $startTime = strtotime('this week');
  748. $endTime = time();
  749. break;
  750. case 'month':
  751. $startTime = strtotime('last month');
  752. $endTime = time();
  753. break;
  754. }
  755. $list = self::alias('t0')
  756. ->field('t0.uid,t0.spread_uid,count(t1.spread_uid) AS count,t0.add_time,t0.nickname,t0.avatar')
  757. ->join('user t1', 't0.uid = t1.spread_uid', 'LEFT')
  758. ->where('t1.spread_uid', '<>', 0)
  759. ->order('count desc')
  760. ->order('t0.uid desc')
  761. ->where('t1.add_time', 'BETWEEN', [$startTime, $endTime])
  762. ->page($data['page'], $data['limit'])
  763. ->group('t0.uid')
  764. ->select();
  765. return count($list) ? $list->toArray() : [];
  766. }
  767. /**
  768. * 获取佣金排行
  769. * @param $data
  770. * @return array
  771. */
  772. public static function brokerageRank($data)
  773. {
  774. $model = self::where('status', 1);
  775. switch ($data['type']) {
  776. case 'week':
  777. $model = $model->whereIn('uid', function ($query) {
  778. $query->name('user_bill')->where('category', 'now_money')->where('type', 'brokerage')
  779. ->whereWeek('add_time')->field('uid');
  780. });
  781. break;
  782. case 'month':
  783. $model = $model->whereIn('uid', function ($query) {
  784. $query->name('user_bill')->where('category', 'now_money')->where('type', 'brokerage')
  785. ->whereMonth('add_time')->field('uid');
  786. });
  787. break;
  788. }
  789. $users = $model->field('uid,nickname,avatar,brokerage_price')->order('brokerage_price desc')
  790. ->page((int)$data['page'], (int)$data['limit'])->select();
  791. return count($users) ? $users->toArray() : [];
  792. }
  793. /**
  794. * 获取当前用户的佣金排行位置
  795. * @param $uid
  796. * @return int
  797. */
  798. public static function currentUserRank($type, $brokerage_price)
  799. {
  800. $model = self::where('status', 1);
  801. switch ($type) {
  802. case 'week':
  803. $model = $model->whereIn('uid', function ($query) {
  804. $query->name('user_bill')->where('category', 'now_money')->where('type', 'brokerage')
  805. ->whereWeek('add_time')->field('uid');
  806. });
  807. break;
  808. case 'month':
  809. $model = $model->whereIn('uid', function ($query) {
  810. $query->name('user_bill')->where('category', 'now_money')->where('type', 'brokerage')
  811. ->whereMonth('add_time')->field('uid');
  812. });
  813. break;
  814. }
  815. return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
  816. }
  817. /**
  818. * 升级店长店员
  819. * @param $uid
  820. * @return void
  821. * @throws DataNotFoundException
  822. * @throws DbException
  823. * @throws ModelNotFoundException
  824. */
  825. public static function upgrade($uid)
  826. {
  827. $user = User::where('uid', $uid)->find();
  828. if ($user['identity'] == 0) {
  829. $price = StoreOrder::where('uid', $uid)->where('paid', 1)->sum('pay_price');
  830. if ($price >= sys_config('cumulative')) {
  831. $user['identity'] = 1;
  832. if ($user['spread_uid']) {
  833. $spd = User::where('uid', $user['spread_uid'])->find();
  834. $user['line'] = $spd['lines'] + 1;
  835. $spd['lines'] += 1;
  836. $spd->save();
  837. }
  838. }
  839. } elseif ($user['identity'] == 1) {
  840. $count = User::where('spread_uid', $user['uid'])->where('identity', 1)->count();
  841. if ($count >= sys_config('push_clerk')) {
  842. $user['identity'] = 2;
  843. }
  844. }
  845. $res = $user->save();
  846. if ($user['spread_uid']) {
  847. $spd = User::where('uid', $user['spread_uid'])->find();
  848. $count = User::where('spread_uid', $spd['uid'])->where('identity', 1)->count();
  849. if ($count >= sys_config('push_clerk')) {
  850. $spd['identity'] = 2;
  851. }
  852. $spd->save();
  853. }
  854. if ($res) return true;
  855. return false;
  856. }
  857. /**
  858. * 团队奖励分红
  859. * @return void
  860. * @throws DataNotFoundException
  861. * @throws DbException
  862. * @throws ModelNotFoundException
  863. */
  864. public static function bonus()
  865. {
  866. if (!cache('bonus')) {
  867. $user = User::select();
  868. foreach ($user as $item) {
  869. $start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
  870. $end_time = date('Y-m-d 23:59:59', strtotime(-date('d') . 'day'));
  871. $price = StoreOrder::whereBetweenTime('add_time', $start_time, $end_time)->where('paid', 1)->where('uid', $item['uid'])->sum('pay_price');// 月结
  872. if ($item['spread_uid'] > 0 and $price > 0) {
  873. $spread = getParents($item['spread_uid'], $user->toArray());// 找到所有上级
  874. $v1 = 0;
  875. $v2 = 0;
  876. $v3 = 0;
  877. $one = sys_config('area') / 100; // 区代
  878. $tow = sys_config('city') / 100; // 市代
  879. $three = sys_config('partner') / 100;// 合伙人
  880. foreach ($spread as $value) {
  881. $details = User::where('uid', $value)->find();
  882. if ($details['level'] > 0) {
  883. if ($details['level'] == 1) {
  884. if ($v2 == 0 and $v3 == 0) {
  885. // 没有发放市代和合伙人的奖励
  886. if ($v1 == 0) { // 没有发放v1的奖励
  887. $jl = $price * $one;
  888. $details['dynamic_integral'] += $jl; // 区代团队奖励
  889. $v1++;
  890. }
  891. }
  892. } elseif ($details['level'] == 2) {
  893. if ($v3 == 0) {
  894. // 没有发放合伙人的奖励
  895. if ($v1 == 0 and $v2 == 0) { // 没有发放区代和市代的奖励的奖励
  896. $jl = $price * $tow;// 市代团队奖励
  897. $v2++;
  898. } elseif ($v1 > 0 and $v2 == 0) {// 发放区代奖励,没有发放市代的奖励
  899. $jl = $price * ($tow - $one); // 市代团队奖励
  900. $v2++;
  901. }
  902. }
  903. }
  904. // }elseif ($details['level'] == 3){
  905. // if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放区代和市代,合伙人的奖励的奖励
  906. // $jl = $price * $three; // 合伙人团队奖励
  907. // $v3++;
  908. // }elseif ($v1 > 0 and $v2 == 0 and $v3 == 0){// 发放区代奖励,没有发放市代,合伙人的奖励
  909. // $jl = $price * ($three - $one); // 合伙人团队奖励
  910. // $v3++;
  911. // }elseif ($v1 == 0 and $v2 > 0 and $v3 == 0){// 没有发放区代奖励,发放市代的奖励,没有发放合伙人的奖励
  912. // $jl = ($price * ($three - $tow)); // 合伙人团队奖励
  913. // $v3++;
  914. // }elseif ($v1 > 0 and $v2 > 0 and $v3 == 0){// 发放区代奖励,发放市代的奖励,发放合伙人的奖励
  915. // $jl = ($price * ($three - $tow)); // 合伙人团队奖励
  916. // $v3++;
  917. // }
  918. // }
  919. if ($jl > 0) {
  920. $brokerage_price = $jl * 0.95;// 到账佣金
  921. $integral = $jl * 0.05;// 到账积分
  922. User::where('uid', $value)->inc('brokerage_price', $brokerage_price)->update();
  923. User::where('uid', $value)->inc('integral', $integral)->update();
  924. if ($details['level'] == 3) {
  925. $bl = $three;
  926. if ($v2 > 0 and $v1 > 0) $bl -= $tow;
  927. if ($v2 > 0 and $v1 == 0) $bl -= $tow;
  928. if ($v2 == 0 and $v1 > 0) $bl -= $one;
  929. }
  930. if ($details['level'] == 2) {
  931. $bl = $tow;
  932. if ($v1 > 0) $bl -= $one;
  933. }
  934. if ($details['level'] == 1) $bl = $one;
  935. UserBill::income('获得推广佣金', $details['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $details['brokerage_price'] + $brokerage_price, '用户' . $item['uid'] . '月结' . $price . '团队奖励比例' . $bl . '的95%佣金');
  936. UserBill::income('获得推广积分', $details['uid'], 'integral', 'bonus', $integral, $item['uid'], $details['integral'] + $integral, '用户' . $item['uid'] . '月结' . $price . '团队奖励比例' . $bl . '的5%积分');
  937. }
  938. $jl = 0;
  939. }
  940. }
  941. }
  942. }
  943. cache('bonus', 1, 86400);
  944. }
  945. }
  946. /**
  947. * 获取ID
  948. * @param $key
  949. * @return mixed
  950. */
  951. public static function getkeytoid($key)
  952. {
  953. $rs = self::order('uid DESC')->find();
  954. return $rs['uid'] + 1;
  955. }
  956. /**
  957. * 联创分红
  958. * @return void
  959. * @throws DataNotFoundException
  960. * @throws DbException
  961. * @throws ModelNotFoundException
  962. */
  963. public static function creation()
  964. {
  965. $user = User::where('level', 4)->select();
  966. if (count($user) > 0) {
  967. $start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
  968. $end_time = date('Y-m-d 23:59:59', strtotime(-date('d') . 'day'));
  969. $price = StoreOrder::whereBetweenTime('add_time', $start_time, $end_time)->where('paid', 1)->sum('pay_price');// 月结
  970. if ($price > 0) {
  971. foreach ($user as $item) {
  972. $brokerage_price = ($price * sys_config('link') / 100) * 0.95;// 到账佣金
  973. $integral = ($price * sys_config('link') / 100) * 0.05;// 到账积分
  974. User::where('uid', $item['uid'])->inc('brokerage_price', $brokerage_price)->update();
  975. User::where('uid', $item['uid'])->inc('integral', $integral)->update();
  976. UserBill::income('联创分红佣金', $item['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $item['brokerage_price'] + $brokerage_price, '联创分红奖励比例' . (sys_config('link') / 100) . '的95%佣金');
  977. UserBill::income('联创分红积分', $item['uid'], 'integral', 'creation', $integral, $item['uid'], $item['integral'] + $integral, '联创分红奖励比例' . (sys_config('link') / 100) . '的5%积分');
  978. }
  979. }
  980. }
  981. }
  982. }