User.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php
  2. namespace app\models\user;
  3. use app\models\store\StoreOrder;
  4. use crmeb\services\SystemConfigService;
  5. use think\facade\Session;
  6. use crmeb\traits\ModelTrait;
  7. use crmeb\basic\BaseModel;
  8. use crmeb\traits\JwtAuthModelTrait;
  9. /**
  10. * TODO 用户Model
  11. * Class User
  12. * @package app\models\user
  13. */
  14. class User extends BaseModel
  15. {
  16. use JwtAuthModelTrait;
  17. use ModelTrait;
  18. protected $pk = 'uid';
  19. protected $name = 'user';
  20. protected $insert = ['add_time','add_ip','last_time','last_ip'];
  21. protected $hidden = [
  22. 'add_ip','add_time','account', 'clean_time','last_ip', 'last_time', 'pwd', 'status', 'mark', 'pwd'
  23. ];
  24. protected function setAddTimeAttr($value)
  25. {
  26. return time();
  27. }
  28. protected function setAddIpAttr($value)
  29. {
  30. return app('request')->ip();
  31. }
  32. protected function setLastTimeAttr($value)
  33. {
  34. return time();
  35. }
  36. protected function setLastIpAttr($value)
  37. {
  38. return app('request')->ip();
  39. }
  40. public static function setWechatUser($wechatUser,$spread_uid = 0)
  41. {
  42. return self::create([
  43. 'account'=>'wx'.$wechatUser['uid'].time(),
  44. 'pwd'=>md5(123456),
  45. 'nickname'=>$wechatUser['nickname']?:'',
  46. 'avatar'=>$wechatUser['headimgurl']?:'',
  47. 'spread_uid'=>$spread_uid,
  48. 'add_time'=>time(),
  49. 'add_ip'=>app('request')->ip(),
  50. 'last_time'=>time(),
  51. 'last_ip'=>app('request')->ip(),
  52. 'uid'=>$wechatUser['uid'],
  53. 'user_type'=>'wechat'
  54. ]);
  55. }
  56. /**
  57. * TODO 获取会员是否被清除过的时间
  58. * @param $uid
  59. * @return int|mixed
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. */
  64. public static function getCleanTime($uid)
  65. {
  66. $user=self::where('uid',$uid)->field(['add_time','clean_time'])->find();
  67. if(!$user) return 0;
  68. return $user['clean_time'] ? $user['clean_time'] : $user['add_time'];
  69. }
  70. public static function updateWechatUser($wechatUser,$uid)
  71. {
  72. $userInfo = self::where('uid',$uid)->find();
  73. if(!$userInfo) return ;
  74. if($userInfo->spread_uid){
  75. return self::edit([
  76. 'nickname'=>$wechatUser['nickname']?:'',
  77. 'avatar'=>$wechatUser['headimgurl']?:'',
  78. 'login_type'=>isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
  79. ],$uid,'uid');
  80. }else {
  81. $data=[
  82. 'nickname' => $wechatUser['nickname'] ?: '',
  83. 'avatar' => $wechatUser['headimgurl'] ?: '',
  84. 'is_promoter' =>$userInfo->is_promoter,
  85. 'login_type'=>isset($wechatUser['login_type']) ? $wechatUser['login_type'] : $userInfo->login_type,
  86. 'spread_uid' => 0,
  87. 'spread_time' =>0,
  88. 'last_time' => time(),
  89. 'last_ip' => request()->ip(),
  90. ];
  91. //TODO 获取后台分销类型
  92. $storeBrokerageStatus = SystemConfigService::get('store_brokerage_statu');
  93. $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  94. if(isset($wechatUser['code']) && $wechatUser['code'] && $wechatUser['code'] != $uid){
  95. if($storeBrokerageStatus == 1){
  96. $spreadCount = self::where('uid',$wechatUser['code'])->count();
  97. if($spreadCount){
  98. $spreadInfo = self::where('uid',$wechatUser['code'])->find();
  99. if($spreadInfo->is_promoter){
  100. //TODO 只有扫码才可以获得推广权限
  101. // if(isset($wechatUser['isPromoter'])) $data['is_promoter'] = $wechatUser['isPromoter'] ? 1 : 0;
  102. }
  103. }
  104. }
  105. $data['spread_uid'] = $wechatUser['code'];
  106. $data['spread_time'] = time();
  107. }
  108. return self::edit($data, $uid, 'uid');
  109. }
  110. }
  111. /**
  112. * 设置推广关系
  113. * @param $spread
  114. * @param $uid
  115. * @return bool
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. * @throws \think\exception\DbException
  119. */
  120. public static function setSpread($spread, $uid)
  121. {
  122. //当前用户信息
  123. $userInfo = self::where('uid', $uid)->find();
  124. if(!$userInfo) return true;
  125. //当前用户有上级直接返回
  126. if($userInfo->spread_uid) return true;
  127. //没有推广编号直接返回
  128. if(!$spread) return true;
  129. if($spread == $uid) return true;
  130. //TODO 获取后台分销类型
  131. $storeBrokerageStatus = SystemConfigService::get('store_brokerage_statu');
  132. $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  133. if($storeBrokerageStatus == 1){
  134. $spreadCount = self::where('uid',$spread)->count();
  135. if($spreadCount){
  136. $spreadInfo = self::where('uid',$spread)->find();
  137. if($spreadInfo->is_promoter){
  138. //TODO 只有扫码才可以获得推广权限
  139. // if(isset($wechatUser['isPromoter'])) $data['is_promoter'] = $wechatUser['isPromoter'] ? 1 : 0;
  140. }
  141. }
  142. }
  143. $data['spread_uid'] = $spread;
  144. $data['spread_time'] = time();
  145. return self::edit($data, $uid, 'uid');
  146. }
  147. /**
  148. * 小程序用户添加
  149. * @param $routineUser
  150. * @param int $spread_uid
  151. * @return object
  152. */
  153. public static function setRoutineUser($routineUser,$spread_uid = 0){
  154. self::beginTrans();
  155. $res1 = true;
  156. if($spread_uid) $res1 = self::where('uid',$spread_uid)->inc('spread_count',1)->update();
  157. $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
  158. $res2 = self::create([
  159. 'account'=>'rt'.$routineUser['uid'].time(),
  160. 'pwd'=>md5(123456),
  161. 'nickname'=>$routineUser['nickname']?:'',
  162. 'avatar'=>$routineUser['headimgurl']?:'',
  163. 'spread_uid'=>$spread_uid,
  164. // 'is_promoter'=>$spread_uid || $storeBrokerageStatu != 1 ? 1: 0,
  165. 'spread_time'=>$spread_uid ? time() : 0,
  166. 'uid'=>$routineUser['uid'],
  167. 'add_time'=>$routineUser['add_time'],
  168. 'add_ip'=>request()->ip(),
  169. 'last_time'=>time(),
  170. 'last_ip'=>request()->ip(),
  171. 'user_type'=>$routineUser['user_type']
  172. ]);
  173. $res = $res1 && $res2;
  174. self::checkTrans($res);
  175. return $res2;
  176. }
  177. /**
  178. * 获得当前登陆用户UID
  179. * @return int $uid
  180. */
  181. public static function getActiveUid()
  182. {
  183. $uid = null;
  184. $uid = Session::get('LoginUid');
  185. if($uid) return $uid;
  186. else return 0;
  187. }
  188. /**
  189. * TODO 查询当前用户信息
  190. * @param $uid $uid 用户编号
  191. * @param string $field $field 查询的字段
  192. * @return array
  193. * @throws \think\Exception
  194. * @throws \think\db\exception\DataNotFoundException
  195. * @throws \think\db\exception\ModelNotFoundException
  196. * @throws \think\exception\DbException
  197. */
  198. public static function getUserInfo($uid,$field = '')
  199. {
  200. if(strlen(trim($field))) $userInfo = self::where('uid',$uid)->field($field)->find();
  201. else $userInfo = self::where('uid',$uid)->find();
  202. if(!$userInfo) return [];
  203. return $userInfo->toArray();
  204. }
  205. /**
  206. * 判断当前用户是否推广员
  207. * @param int $uid
  208. * @return bool
  209. */
  210. public static function isUserSpread($uid = 0){
  211. if(!$uid) return false;
  212. $status = (int)SystemConfigService::get('store_brokerage_statu');
  213. $isPromoter = true;
  214. if($status == 1) $isPromoter = self::where('uid',$uid)->value('is_promoter');
  215. if($isPromoter) return true;
  216. else return false;
  217. }
  218. /**
  219. * TODO 一级返佣
  220. * @param $orderInfo
  221. * @return bool
  222. * @throws \think\Exception
  223. * @throws \think\db\exception\DataNotFoundException
  224. * @throws \think\db\exception\ModelNotFoundException
  225. * @throws \think\exception\DbException
  226. */
  227. public static function backOrderBrokerage($orderInfo)
  228. {
  229. //TODO 如果时营销产品不返佣金
  230. if(isset($orderInfo['combination_id']) && $orderInfo['combination_id']) return true;
  231. if(isset($orderInfo['seckill_id']) && $orderInfo['seckill_id']) return true;
  232. if(isset($orderInfo['bargain_id']) && $orderInfo['bargain_id']) return true;
  233. //TODO 支付金额减掉邮费
  234. $orderInfo['pay_price'] = bcsub($orderInfo['pay_price'],$orderInfo['pay_postage'],2);
  235. //TODO 获取购买商品的用户
  236. $userInfo = User::getUserInfo($orderInfo['uid']);
  237. //TODO 当前用户不存在 没有上级 或者 当用用户上级时自己 直接返回
  238. if(!$userInfo || !$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid']) return true;
  239. //TODO 获取后台分销类型 1 指定分销 2 人人分销
  240. $storeBrokerageStatus = SystemConfigService::get('store_brokerage_statu');
  241. $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  242. //TODO 指定分销 判断 上级是否时推广员 如果不是推广员直接跳转二级返佣
  243. if($storeBrokerageStatus == 1){
  244. if(!User::be(['uid'=>$userInfo['spread_uid'],'is_promoter'=>1])) return self::backOrderBrokerageTwo($orderInfo);
  245. }
  246. //TODO 获取后台一级返佣比例
  247. $storeBrokerageRatio = SystemConfigService::get('store_brokerage_ratio');
  248. //TODO 一级返佣比例 小于等于零时直接返回 不返佣
  249. if($storeBrokerageRatio <= 0) return true;
  250. //TODO 计算获取一级返佣比例
  251. $brokerageRatio = bcdiv($storeBrokerageRatio,100,2);
  252. //TODO 成本价
  253. $cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;
  254. //TODO 成本价大于等于支付价格时直接返回
  255. if($cost >= $orderInfo['pay_price']) return true;
  256. //TODO 获取订单毛利
  257. $payPrice = bcsub($orderInfo['pay_price'],$cost,2);
  258. //TODO 返佣金额 = 毛利 / 一级返佣比例
  259. $brokeragePrice = bcmul($payPrice,$brokerageRatio,2);
  260. //TODO 返佣金额小于等于0 直接返回不返佣金
  261. if($brokeragePrice <= 0) return true;
  262. //TODO 获取上级推广员信息
  263. $spreadUserInfo = User::getUserInfo($userInfo['spread_uid']);
  264. //TODO 上级推广员返佣之后的金额
  265. $balance = bcadd($spreadUserInfo['brokerage_price'],$brokeragePrice,2);
  266. $mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
  267. self::beginTrans();
  268. //TODO 添加推广记录
  269. $res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
  270. //TODO 添加用户余额
  271. $res2 = self::bcInc($userInfo['spread_uid'],'brokerage_price',$brokeragePrice,'uid');
  272. //TODO 一级返佣成功 跳转二级返佣
  273. $res = $res1 && $res2 && self::backOrderBrokerageTwo($orderInfo);
  274. self::checkTrans($res);
  275. // if($res) return self::backOrderBrokerageTwo($orderInfo);
  276. return $res;
  277. }
  278. /**
  279. * TODO 二级推广
  280. * @param $orderInfo
  281. * @return bool
  282. * @throws \think\Exception
  283. * @throws \think\db\exception\DataNotFoundException
  284. * @throws \think\db\exception\ModelNotFoundException
  285. * @throws \think\exception\DbException
  286. */
  287. public static function backOrderBrokerageTwo($orderInfo){
  288. //TODO 获取购买商品的用户
  289. $userInfo = User::getUserInfo($orderInfo['uid']);
  290. //TODO 获取上推广人
  291. $userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
  292. //TODO 上推广人不存在 或者 上推广人没有上级 或者 当用用户上上级时自己 直接返回
  293. if(!$userInfoTwo || !$userInfoTwo['spread_uid'] || $userInfoTwo['spread_uid'] == $orderInfo['uid']) return true;
  294. //TODO 获取后台分销类型 1 指定分销 2 人人分销
  295. $storeBrokerageStatus = SystemConfigService::get('store_brokerage_statu');
  296. $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  297. //TODO 指定分销 判断 上上级是否时推广员 如果不是推广员直接返回
  298. if($storeBrokerageStatus == 1){
  299. if(!User::be(['uid'=>$userInfoTwo['spread_uid'],'is_promoter'=>1])) return true;
  300. }
  301. //TODO 获取二级返佣比例
  302. $storeBrokerageTwo = SystemConfigService::get('store_brokerage_two');
  303. //TODO 二级返佣比例小于等于0 直接返回
  304. if($storeBrokerageTwo <= 0) return true;
  305. //TODO 计算获取二级返佣比例
  306. $brokerageRatio = bcdiv($storeBrokerageTwo,100,2);
  307. //TODO 获取成本价
  308. $cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;
  309. //TODO 成本价大于等于支付价格时直接返回
  310. if($cost >= $orderInfo['pay_price']) return true;
  311. //TODO 获取订单毛利
  312. $payPrice = bcsub($orderInfo['pay_price'],$cost,2);
  313. //TODO 返佣金额 = 毛利 / 二级返佣比例
  314. $brokeragePrice = bcmul($payPrice,$brokerageRatio,2);
  315. //TODO 返佣金额小于等于0 直接返回不返佣金
  316. if($brokeragePrice <= 0) return true;
  317. //TODO 获取上上级推广员信息
  318. $spreadUserInfoTwo = User::getUserInfo($userInfoTwo['spread_uid']);
  319. //TODO 获取上上级推广员返佣之后余额
  320. $balance = bcadd($spreadUserInfoTwo['brokerage_price'],$brokeragePrice,2);
  321. $mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
  322. self::beginTrans();
  323. //TODO 添加返佣记录
  324. $res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
  325. //TODO 添加用户余额
  326. $res2 = self::bcInc($userInfoTwo['spread_uid'],'brokerage_price',$brokeragePrice,'uid');
  327. $res = $res1 && $res2;
  328. self::checkTrans($res);
  329. return $res;
  330. }
  331. /*
  332. * 获取推荐人
  333. * @param int $two_uid
  334. * @param int $first
  335. * @param int $limit
  336. * @return array
  337. * */
  338. public static function getSpreadList($uid,$page,$limit)
  339. {
  340. $list=self::where('spread_uid',$uid)->field('uid,nickname,avatar,add_time')->page($page,$limit)->order('add_time DESC')->select();
  341. foreach ($list as $k=>$user){
  342. $list[$k]['add_time'] = date('Y/m/d',$user['add_time']);
  343. $list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
  344. }
  345. $count = self::where('spread_uid',$uid)->field('uid,nickname,avatar,add_time')->count();
  346. $data['count'] = $count;
  347. $data['list'] = $list;
  348. return $data;
  349. }
  350. /*
  351. * 获取某个用户的下级uid
  352. * @param int $uid 用户uid
  353. * @return array
  354. * */
  355. public static function getOneSpreadUid($uid)
  356. {
  357. return self::where('spread_uid',$uid)->column('uid');
  358. }
  359. /*
  360. * 修改个人信息
  361. * */
  362. public static function editUser($avatar,$nickname,$uid)
  363. {
  364. return self::edit(['avatar'=>$avatar,'nickname'=>$nickname],$uid,'uid');
  365. }
  366. /**
  367. * TODO 获取推广人数 一级
  368. * @param int $uid
  369. * @return bool|int|string
  370. */
  371. public static function getSpreadCount($uid = 0){
  372. if(!$uid) return false;
  373. return self::where('spread_uid',$uid)->count();
  374. }
  375. public static function setUserSpreadCount($uid){
  376. self::where('uid',$uid)->update(['spread_count'=>self::getSpreadCount($uid)]);
  377. }
  378. /**
  379. * TODO 获取推广人数 二级
  380. * @param int $uid
  381. * @return bool|int|string
  382. */
  383. public static function getSpreadLevelCount($uid = 0){
  384. if(!$uid) return false;
  385. $uidSubordinate = self::where('spread_uid',$uid)->column('uid');
  386. if(!count($uidSubordinate)) return 0;
  387. return self::where('spread_uid','IN',implode(',',$uidSubordinate))->count();
  388. }
  389. /**
  390. * 获取用户下级推广人
  391. * @param int $uid 当前用户
  392. * @param int $grade 等级 0 一级 1 二级
  393. * @param string $orderBy 排序
  394. * @param string $keyword
  395. * @param int $page
  396. * @param int $limit
  397. * @return array|bool
  398. */
  399. public static function getUserSpreadGrade($uid = 0,$grade = 0,$orderBy = '',$keyword = '',$page = 0,$limit = 20){
  400. if(!$uid) return [];
  401. $gradeGroup = [0,1];
  402. if(!in_array($grade,$gradeGroup)) return self::setErrorInfo('等级错误');
  403. $userStair = self::where('spread_uid',$uid)->column('uid');
  404. if(!count($userStair)) return [];
  405. if($grade == 0) return self::getUserSpreadCountList(implode(',',$userStair),$orderBy,$keyword,$page,$limit);
  406. $userSecondary = self::where('spread_uid','in',implode(',',$userStair))->column('uid');
  407. return self::getUserSpreadCountList(implode(',',$userSecondary),$orderBy,$keyword,$page,$limit);
  408. }
  409. /**
  410. * 获取团队信息
  411. * @param $uid
  412. * @param string $orderBy
  413. * @param string $keyword
  414. * @param int $page
  415. * @param int $limit
  416. * @return array
  417. */
  418. public static function getUserSpreadCountList($uid, $orderBy = '',$keyword = '',$page = 0,$limit = 20)
  419. {
  420. $model = new self;
  421. if($orderBy==='') $orderBy='u.add_time desc';
  422. $model = $model->alias(' u');
  423. $model = $model->join('StoreOrder o','u.uid=o.uid','LEFT');
  424. $model = $model->where('u.uid','IN',$uid);
  425. $model = $model->field("u.uid,u.nickname,u.avatar,from_unixtime(u.add_time,'%Y/%m/%d') as time,u.spread_count as childCount,COUNT(o.id) as orderCount,SUM(o.pay_price) as numberCount");
  426. if(strlen(trim($keyword))) $model = $model->where('u.nickname|u.phone','like',"%$keyword%");
  427. $model = $model->group('u.uid');
  428. $model = $model->order($orderBy);
  429. $model = $model->page($page,$limit);
  430. $list = $model->select();
  431. if($list) return $list->toArray();
  432. else return [];
  433. }
  434. public static function setSpreadUid($uid,$spreadUid)
  435. {
  436. // 自己不能绑定自己为上级
  437. if($uid == $spreadUid) return false;
  438. //TODO 获取后台分销类型
  439. $storeBrokerageStatus = SystemConfigService::get('store_brokerage_statu');
  440. $storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
  441. if($storeBrokerageStatus == 1){
  442. $spreadCount = self::where('uid',$spreadUid)->count();
  443. if($spreadCount){
  444. $spreadInfo = self::where('uid',$spreadUid)->find();
  445. if($spreadInfo->is_promoter){
  446. //TODO 只有扫码才可以获得推广权限
  447. if(isset($wechatUser['isPromoter'])) $data['is_promoter'] = 1;
  448. }
  449. }
  450. }
  451. return self::where('uid',$uid)->update(['spread_uid'=>$spreadUid,'spread_time'=>time()]);
  452. }
  453. /**
  454. * 判断上下级关系是否存在
  455. * @param $uid
  456. * @param $spreadUid
  457. * @return bool|int
  458. */
  459. public static function validSpread($uid, $spreadUid){
  460. if(!$uid || !$spreadUid) return false;
  461. return self::where('uid', $uid)->where('spread_uid', $spreadUid)->count();
  462. }
  463. /**
  464. * H5用户注册
  465. * @param $account
  466. * @param $password
  467. * @param $spread
  468. * @return User|\think\Model
  469. */
  470. public static function register($account, $password, $spread)
  471. {
  472. if(self::be(['account'=>$account])) return self::setErrorInfo('用户已存在');
  473. $phone = $account;
  474. $data['account'] = $account;
  475. $data['pwd'] = md5($password);
  476. $data['phone'] = $phone;
  477. if($spread){
  478. $data['spread_uid'] = $spread;
  479. $data['spread_time'] = time();
  480. }
  481. $data['real_name'] = '';
  482. $data['birthday'] = 0;
  483. $data['card_id'] = '';
  484. $data['mark'] = '';
  485. $data['addres'] = '';
  486. $data['user_type'] = 'h5';
  487. $data['add_time'] = time();
  488. $data['add_ip'] = app('request')->ip();
  489. $data['last_time'] = time();
  490. $data['last_ip'] = app('request')->ip();
  491. $data['nickname'] = substr(md5($account.time()), 0, 12);
  492. $data['avatar'] = $data['headimgurl'] = SystemConfigService::get('h5_avatar');
  493. $data['city'] = '';
  494. $data['language'] = '';
  495. $data['province'] = '';
  496. $data['country'] = '';
  497. self::beginTrans();
  498. $res2 = WechatUser::create($data);
  499. $data['uid'] = $res2->uid;
  500. $res1 = self::create($data);
  501. $res = $res1 && $res2;
  502. self::checkTrans($res);
  503. return $res;
  504. }
  505. /**
  506. * 密码修改
  507. * @param $account
  508. * @param $password
  509. * @return User|bool
  510. */
  511. public static function reset($account, $password)
  512. {
  513. if(!self::be(['account'=>$account])) return self::setErrorInfo('用户不存在');
  514. $count = self::where('account', $account)->where('pwd', md5($password))->count();
  515. if($count) return true;
  516. return self::where('account', $account)->update(['pwd'=>md5($password)]);
  517. }
  518. /**
  519. * 获取手机号是否注册
  520. * @param $phone
  521. * @return bool
  522. */
  523. public static function checkPhone($phone)
  524. {
  525. return self::be(['account'=>$phone]);
  526. }
  527. }