UserService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/21
  6. * Time: 10:42
  7. */
  8. namespace App\Modules\User\Services;
  9. use App\Consts\QuickConst;
  10. use App\Modules\Book\Models\BookGiftsSend;
  11. use App\Modules\Book\Models\UserShelfBooks;
  12. use App\Modules\Subscribe\Models\BookOrder;
  13. use App\Modules\Subscribe\Models\ChapterOrder;
  14. use App\Modules\Subscribe\Services\ChapterOrderService;
  15. use App\Modules\User\Models\User;
  16. use App\Modules\User\Models\UserEnv;
  17. use DB;
  18. use App\Jobs\ActionTrigger;
  19. use App\Jobs\UserAddDeskJob;
  20. use App\Modules\OfficialAccount\Models\DistributionSelfDefineConfig;
  21. use App\Modules\Channel\Models\Channel;
  22. use App\Modules\Trade\Models\Order;
  23. use App\Modules\User\Models\QappUserAddDestop;
  24. use App\Modules\UserTask\Services\BaseTask;
  25. use App\Modules\UserTask\Services\UserTaskService;
  26. use Redis;
  27. class UserService
  28. {
  29. public static function setUserSendOrder(int $uid, int $send_order_id)
  30. {
  31. if (empty($uid) || empty($send_order_id)) {
  32. return false;
  33. }
  34. Redis::hmset('book_read:' . $uid,'send_order_id',$send_order_id,'soid_time',time());
  35. //return Redis::hset('book_read:' . $uid, 'send_order_id', $send_order_id);
  36. }
  37. public static function getUserSendOrderTime($uid)
  38. {
  39. $send_order_id_time = Redis::hGet('book_read:' . $uid, 'soid_time');
  40. $send_order_id_time = (int)($send_order_id_time);
  41. return $send_order_id_time;
  42. }
  43. public static function getUserSendOrder(int $uid)
  44. {
  45. $send_order_id = Redis::hGet('book_read:' . $uid, 'send_order_id');
  46. $send_order_id = (int)($send_order_id ? $send_order_id : 0);
  47. return $send_order_id;
  48. }
  49. public static function qappAddDesktop(int $uid, int $status)
  50. {
  51. $time = getMillisecond();
  52. myLog('incrAddDeskTop')->info('qappAddDesktop', compact('uid', 'status','time'));
  53. $log = QappUserAddDestop::where('uid', $uid)->orderBy('id', 'desc')->first();
  54. if($status == 1){
  55. UserTaskService::addUserTaskQueue($uid, BaseTask::add_desk, UserTaskService::add_trigger);
  56. $time = getMillisecond();
  57. myLog('incrAddDeskTop')->info('qappAddDesktop', compact('uid', 'status','time'));
  58. }
  59. if (!$log) {
  60. //第一次加桌 没有任何记录,加桌状态为1
  61. if($status == 1){
  62. // 加桌统计
  63. // QappAddDeskTopService::incrAddDeskTop($uid, QuickConst::FIELD_ADD_DESKTOP);
  64. $job = new UserAddDeskJob($uid);
  65. dispatch($job)->onConnection('rabbitmq')->onQueue('qapp_user_add_desk')->delay(now()->addMinutes(3));
  66. }
  67. //第一次加桌 没有任何记录,加桌状态为0
  68. if($status == 0){
  69. QappUserAddDestop::create([
  70. 'uid' => $uid,
  71. 'status' => $status,
  72. ]);
  73. }
  74. }else{
  75. //如果有记录,但是都是0 没有1的记录
  76. $oneexists = QappUserAddDestop::where('uid', $uid)->where('status', 1)->exists();
  77. if(!$oneexists && $status == 1){
  78. // 加桌统计
  79. // QappAddDeskTopService::incrAddDeskTop($uid, QuickConst::FIELD_ADD_DESKTOP);
  80. $job = new UserAddDeskJob($uid);
  81. dispatch($job)->onConnection('rabbitmq')->onQueue('qapp_user_add_desk')->delay(now()->addMinutes(3));
  82. $time = getMillisecond();
  83. myLog('incrAddDeskTop')->info('qappAddDesktop', compact('uid', 'status','time'));
  84. return false;
  85. }
  86. //有加桌记录 最近一次加桌状态和和此次状态是否相等
  87. if($log->status != $status){
  88. //不相等 插入记录
  89. QappUserAddDestop::create([
  90. 'uid' => $uid,
  91. 'status' => $status,
  92. ]);
  93. }
  94. //相等 不做处理
  95. $time = getMillisecond();
  96. myLog('incrAddDeskTop')->info('qappAddDesktop', compact('uid', 'status','time'));
  97. return false;
  98. }
  99. }
  100. /**
  101. * 创建用户
  102. * $params
  103. * 必穿参数 openid、unionid、distribution_channel_id
  104. * 可传 province、city、country、headimgurl、send_order_id、sex、register_ip
  105. */
  106. static function addUser($params)
  107. {
  108. return User::addUser($params);
  109. }
  110. static function getUserList($limit, $offset)
  111. {
  112. return User::getUserList($limit, $offset);
  113. }
  114. static function getUserByNickAndChannelId($distribution_channel_id, $nickname)
  115. {
  116. return User::getUserByNickAndChannelId($distribution_channel_id, $nickname);
  117. }
  118. /**
  119. * 获取用户信息列表
  120. * @param $pageSize 每页显示的条数
  121. */
  122. static function getPaginationList($pageSize = 20)
  123. {
  124. return User::getPaginationList($pageSize);
  125. }
  126. /**
  127. * 获取用户信息列表
  128. * @param $pageSize 每页显示的条数
  129. */
  130. static function getUsers($pageSize = 20, $careStatus)
  131. {
  132. return User::getPaginationList($pageSize, $careStatus);
  133. }
  134. /**
  135. * 根据id获取用户信息
  136. * @return user object
  137. */
  138. static function getById($id)
  139. {
  140. return User::getById($id);
  141. }
  142. /**
  143. * 根据id获取用户信息
  144. * @return user object
  145. */
  146. static function getUserDataById($id)
  147. {
  148. return User::getUserDataById($id);
  149. }
  150. /**
  151. * 根据id获取用户信息
  152. * @return user object
  153. */
  154. static function getUserDataDetailById($id)
  155. {
  156. return User::getUserDataDetailById($id);
  157. }
  158. /**
  159. * 根据id获取用户名称
  160. * @return string [用户昵称]
  161. */
  162. static function getNicknameById($id)
  163. {
  164. return User::getById($id)->nickname;
  165. }
  166. /**
  167. * 更新用户信息
  168. * @param int $id 用户ID
  169. * @param array $params 可传 province、city、country、headimgurl、sex
  170. * @return boolen
  171. */
  172. static function updateInfo($id, $params)
  173. {
  174. \Log::info('~~~~~~~~~~~~~~~~~====update User====~~~~~~~~~~~~~~~~' . "\n");
  175. \Log::info($id);
  176. \Log::info($params);
  177. return User::updateInfo($id, $params);
  178. }
  179. /**
  180. * 根据union和分销id获取用户信息
  181. * @param $union
  182. * @param $channel_id
  183. * @return mixed
  184. */
  185. static function getUserByUnionAndChannelId($openid, $channel_id)
  186. {
  187. return User::where('openid', $openid)->where('distribution_channel_id', $channel_id)->select('id', 'openid', 'unionid', 'balance', 'charge_balance', 'reward_balance')->first();
  188. }
  189. static function getUserByOpenidAndChannelId($openid, $channel_id)
  190. {
  191. return User::where('openid', $openid)->where('distribution_channel_id', $channel_id)->first();
  192. }
  193. /**
  194. * 用户余额充值
  195. * @param $uid
  196. * @param $fee
  197. * @return mixed
  198. */
  199. static function addBalance($uid, $fee, $charge, $given)
  200. {
  201. return User::addBalance($uid, $fee, $charge, $given);
  202. }
  203. /**
  204. * 查询推广注册用户总数
  205. * @param $send_order_id
  206. * @return mixed
  207. */
  208. static function getPromotionTotal($send_order_id)
  209. {
  210. return User::getPromotionTotal($send_order_id);
  211. }
  212. /**
  213. * 查询渠道某天注册用户总数
  214. * @param $channel_id
  215. * @param $date
  216. * @return mixed
  217. */
  218. static function getChannelDayTotal($channel_id, $date)
  219. {
  220. return User::getChannelDayTotal($channel_id, $date);
  221. }
  222. /**
  223. * 查询渠道注册用户总数
  224. * @param $channel_id
  225. * @return mixed
  226. */
  227. static function getChannelTotal($channel_id)
  228. {
  229. return User::getChannelTotal($channel_id);
  230. }
  231. /**
  232. * 查询渠道某段时间注册用户总数
  233. * @param $channel_id
  234. * @param $startDate
  235. * @param $endDate
  236. * @return mixed
  237. */
  238. static function getChannelDayToDayTotal($channel_id, $startDate = '', $endDate = '')
  239. {
  240. return User::getChannelDayToDayTotal($channel_id, $startDate, $endDate);
  241. }
  242. /**
  243. * 查询渠道某段时间注册用户总数
  244. * @param array $channelIds
  245. * @param $startDate
  246. * @param $endDate
  247. * @return mixed
  248. */
  249. static function getChannelsDayToDayTotal($channelIds, $startDate = '', $endDate = '')
  250. {
  251. return User::getChannelsDayToDayTotal($channelIds, $startDate, $endDate);
  252. }
  253. /**
  254. * 查询注册用户总数
  255. * @param $params
  256. */
  257. static function getTotalCount($params)
  258. {
  259. return User::getTotalCount($params);
  260. }
  261. /**
  262. * 查询渠道是否有登录
  263. * @param $channelId
  264. * @param $start_time
  265. * @param $end_time
  266. * @return int
  267. */
  268. static function judgeUserYesterdayLogin($channelId, $start_time, $end_time)
  269. {
  270. $user_behavior = DB::table('channel_operate_record')
  271. ->where([
  272. ['distribution_channel_id', '=', $channelId],
  273. ['created_at', '>=', $start_time],
  274. ['created_at', '<=', $end_time]
  275. ])
  276. ->first();
  277. if ($user_behavior) return 1;
  278. return 0;
  279. }
  280. /**
  281. * @param $date
  282. * @param $company_id
  283. * @return mixed
  284. */
  285. static function getCompanyDayTotal($date, $company_id)
  286. {
  287. $end_date = date('Y-m-d', strtotime($date) + 86400);
  288. $info = User::leftjoin('distribution_channels', 'distribution_channels.id', '=', 'users.distribution_channel_id')
  289. ->leftjoin('channel_users', 'channel_users.id', '=', 'distribution_channels.channel_user_id')
  290. ->where([
  291. ['users.created_at', '>=', $date],
  292. ['users.created_at', '<', $end_date],
  293. ['channel_users.company_id', '=', $company_id]
  294. ])
  295. ->groupBy('channel_users.company_id')
  296. ->select(DB::raw("count(users.id) as register_sum"))
  297. ->first();
  298. if ($info) return $info->register_sum;
  299. //\Log::info('getCompanyDayTotal error:' . $company_id);
  300. return $info;
  301. }
  302. static function getCompanyTotal($company_id)
  303. {
  304. $info = User::leftjoin('distribution_channels', 'distribution_channels.id', '=', 'users.distribution_channel_id')
  305. ->leftjoin('channel_users', 'channel_users.id', '=', 'distribution_channels.channel_user_id')
  306. ->where('channel_users.company_id', $company_id)
  307. ->groupBy('channel_users.company_id')
  308. ->select(DB::raw("count(users.id) as register_sum"))
  309. ->first();
  310. if ($info) return $info->register_sum;
  311. //\Log::error('getCompanyTotal error:' . $company_id);
  312. return $info;
  313. }
  314. static function transfromBalanceByUser($from_uid, $to_uid)
  315. {
  316. $add_balance_sql = "update users,(select * from users where id =" . $from_uid . ") as u2
  317. set users.balance = users.balance + u2.balance,
  318. users.reward_balance = users.reward_balance +u2.reward_balance,
  319. users.charge_balance = users.charge_balance +u2.charge_balance where users.id =" . $to_uid;
  320. $res = DB::update($add_balance_sql);
  321. return User::updateInfo($from_uid, ['balance' => 0, 'reward_balance' => 0, 'charge_balance' => 0]);
  322. }
  323. // 扔用户一些动作到队列,异步处理一些额外逻辑
  324. static function PushUserActionToQueue($action_type, $distribution_channel_id, $param)
  325. {
  326. try {
  327. // \Log::info('PushUserActionToQueue_param_start:'.$distribution_channel_id.' action_type:'.$action_type. ' param:'.json_encode($param));
  328. // 判断站点是否需要额外逻辑
  329. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'action_call_ycsd');
  330. if (empty($distribution_self_define_config)) {
  331. // \Log::info('not_action_call_ycsd:'.$distribution_channel_id);
  332. return '';
  333. } else {
  334. \Log::info('PushUserActionToQueue_param:' . $distribution_channel_id . ' action_type:' . $action_type . ' param:' . json_encode($param));
  335. // 如果支付通道已经切换回去,则不推送了
  336. // $pay_merchant_id = env('YCSD_CALL_PAY_MERCHANT_ID');
  337. // 当前默认
  338. $pay_merchant_id = Redis::get('YCSD_CALL_PAY_MERCHANT_ID');
  339. $channel = Channel::getById($distribution_channel_id);
  340. $current_pay_merchant_id = isset($channel->pay_merchant_id) ? $channel->pay_merchant_id : '';
  341. \Log::info('action_call_ycsd:' . $distribution_channel_id . ' $pay_merchant_id:' . $pay_merchant_id . ' $current_pay_merchant_id:' . $current_pay_merchant_id);
  342. if ($current_pay_merchant_id != $pay_merchant_id) {
  343. // 判断订单是否是默认支付,放行,切换期间的bug
  344. if ($action_type == 'CallBackOrder') {
  345. $order = Order::getByTradeNo($distribution_channel_id, $param['order_sn']);
  346. if (isset($order->pay_merchant_id) && $order->pay_merchant_id == $pay_merchant_id) {
  347. \Log::info('action_call_ycsd_old_order_continue:' . $param['order_sn']);
  348. } else {
  349. \Log::info('action_call_ycsd_has_change_pay_return:' . $distribution_channel_id);
  350. return '';
  351. }
  352. } else {
  353. \Log::info('action_call_ycsd_has_change_pay_return:' . $distribution_channel_id);
  354. return '';
  355. }
  356. }
  357. \Log::info('action_call_ycsd:' . $distribution_channel_id);
  358. }
  359. $data = [];
  360. $data['send_time'] = date("Y-m-d H:i:s");
  361. $data['action_type'] = $action_type;
  362. if ($action_type == 'Register') {
  363. $data['openid'] = $param['openid'];
  364. $data['uid'] = $param['uid'];
  365. } elseif ($action_type == 'CreateOrder') {
  366. $data['orderSn'] = $param['order_sn'];
  367. $data['amount'] = $param['amount'];
  368. $data['openid'] = $param['openid'];
  369. $data['uid'] = $param['uid'];
  370. } elseif ($action_type == 'CallBackOrder') {
  371. $data['orderSn'] = $param['order_sn'];
  372. $data['openid'] = $param['openid'];
  373. }
  374. $send_data = array(
  375. 'send_time' => date("Y-m-d H:i:s"),
  376. 'data' => $data
  377. );
  378. \Log::info('PushUserActionToQueue_openid:' . $data['openid'] . ' action_type:' . $action_type);
  379. \Log::info('$send_data');
  380. \Log::info($send_data);
  381. $delay = 0;
  382. $job = (new ActionTrigger($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('action_trigger_list');
  383. dispatch($job);
  384. } catch (\Exception $e) {
  385. \Log::info('ept:' . $e->getMessage());
  386. }
  387. }
  388. public static function isCpcUser($uid)
  389. {
  390. //openid下所有强关超过三天的uid都无充值,对强关后的uid进行曝光
  391. //openid下有一个强关超过三天的uid,都无充值,对强关后的uid进行曝光
  392. $sql_format = "SELECT u.id,f.subscribe_time,(SELECT id from orders where uid = u.id and `status` = 'PAID' LIMIT 1)as oid FROM users u
  393. JOIN force_subscribe_users f on u.id = f.uid and f.is_subscribed= 1
  394. WHERE u.openid in (SELECT openid from users WHERE id = %s)";
  395. $result = DB::select(sprintf($sql_format, $uid));
  396. if (!$result) return false;
  397. $is_has_force_subscribe_three_days = false;
  398. foreach ($result as $item) {
  399. //有充值
  400. if ($item->oid) return false;
  401. //强关没超过超过三天
  402. //if(time()-strtotime($item->subscribe_time) < 86400*3) return false;
  403. if (time() - strtotime($item->subscribe_time) > 86400 * 3) $is_has_force_subscribe_three_days = true;
  404. }
  405. return $is_has_force_subscribe_three_days;
  406. }
  407. public static function recordUA($ua, $uid)
  408. {
  409. return UserEnv::recordUA($ua, $uid);
  410. }
  411. public static function transfer(int $from, int $to, int $distribution_channel_id)
  412. {
  413. $transfer_record = DB::table('crm_transfer')->where('from_uid', $from)->first();
  414. if ($transfer_record) {
  415. return;
  416. }
  417. $from_user = self::getById($from);
  418. $to_user = self::getById($to);
  419. if (!$from_user) return;
  420. if (!$to_user) return;
  421. //阅读记录迁移***************************************
  422. $record = Redis::hgetall('book_read:' . $from);
  423. $not_uid_key = ['last_read', 'sign_counts', 'sign_info', 'sign_day'];
  424. $data = [];
  425. foreach ($record as $k => $item) {
  426. if (is_numeric($k) || in_array($k, $not_uid_key)) {
  427. $data[$k] = $item;
  428. }
  429. }
  430. //\Log::info('read record is');
  431. //\Log::info($data);
  432. if ($data) Redis::hmset('book_read:' . $to, $data);
  433. //签到记录
  434. /*$user_sign_model = new UserSign();
  435. $user_sign_model->setCurrentTable(date('Ym'));
  436. $sign_record = $user_sign_model->where('uid',$from)->select('price','sign_time','day','created_at')->orderBy('sign_time','desc')->get();
  437. $temp = [];
  438. if($sign_record){
  439. foreach ($sign_record as $item){
  440. $temp[] = [
  441. 'uid'=>$to,
  442. 'price'=>$item->price,
  443. 'day'=>$item->day,
  444. 'sign_time'=>$item->sign_time,
  445. 'created_at'=>$item->created_at,
  446. 'updated_at'=>date('Y-m-d H:i:s'),
  447. ];
  448. }
  449. //\Log::info('user_sign is');
  450. //\Log::info($temp);
  451. DB::table('user_sign'.date('Ym'))->insert($temp);
  452. }*/
  453. //订阅记录(按本)
  454. $book_order = BookOrder::where('uid', $from)->where('bid', '>', 0)->get();
  455. if ($book_order) {
  456. $temp = [];
  457. foreach ($book_order as $book) {
  458. $temp[] = [
  459. 'distribution_channel_id' => $distribution_channel_id,
  460. 'bid' => $book->bid,
  461. 'book_name' => $book->book_name,
  462. 'uid' => $to,
  463. 'u' => $book->u,
  464. 'fee' => 0,
  465. 'created_at' => $book->created_at,
  466. 'updated_at' => date('Y-m-d H:i:s'),
  467. ];
  468. }
  469. //\Log::info('book_order is');
  470. //\Log::info($temp);
  471. DB::table('book_orders')->insert($temp);
  472. }
  473. //订阅记录(按章)
  474. $chapter_order_record = ChapterOrderService::getRecordByUid($from, '', '', true);
  475. if ($chapter_order_record) {
  476. $temp = [];
  477. $i = 1;
  478. $chapter_model = new ChapterOrder();
  479. $chapter_model->setCurrentTable($to);
  480. foreach ($chapter_order_record as $chapter_order) {
  481. $temp[] = [
  482. 'distribution_channel_id' => $distribution_channel_id,
  483. 'bid' => $chapter_order->bid,
  484. 'cid' => $chapter_order->cid,
  485. 'chapter_name' => $chapter_order->chapter_name,
  486. 'book_name' => $chapter_order->book_name,
  487. 'uid' => $to,
  488. 'send_order_id' => 0,
  489. 'fee' => 0,
  490. 'created_at' => $chapter_order->created_at,
  491. 'updated_at' => date('Y-m-d H:i:s')
  492. ];
  493. if ($i % 100 == 0) {
  494. $chapter_model->insert($temp);
  495. $temp = [];
  496. }
  497. $i++;
  498. }
  499. //\Log::info('chapter order is');
  500. //\Log::info($temp);
  501. $chapter_model->insert($temp);
  502. }
  503. //打赏记录
  504. $gift_result = BookGiftsSend::where('uid', $from)->get();
  505. if ($gift_result) {
  506. $tmp = [];
  507. foreach ($gift_result as $g) {
  508. $tmp[] = [
  509. 'uid' => $to,
  510. 'gift_id' => $g->gift_id,
  511. 'bid' => $g->bid,
  512. 'icon' => $g->icon,
  513. 'name_desc' => $g->name_desc,
  514. 'cost' => 0,
  515. 'cost_reward' => $g->cost_reward,
  516. 'cost_recharge' => $g->cost_recharge,
  517. 'created_at' => $g->created_at,
  518. 'updated_at' => date('Y-m-d H:i:s')
  519. ];
  520. }
  521. //\Log::info('book gift is');
  522. //\Log::info($temp);
  523. DB::table('book_gifts_send')->insert($tmp);
  524. }
  525. //书架
  526. $result = UserShelfBooks::where('uid', $from)->get();
  527. if ($result) {
  528. $tmp = [];
  529. foreach ($result as $s) {
  530. $tmp[] = [
  531. 'uid' => $to,
  532. 'distribution_channel_id' => $distribution_channel_id,
  533. 'bid' => $s->bid,
  534. 'created_at' => $s->created_at,
  535. 'updated_at' => date('Y-m-d H:i:s')
  536. ];
  537. }
  538. //\Log::info('user book shelf is');
  539. //\Log::info($temp);
  540. DB::table('user_shelf_books')->insert($tmp);
  541. }
  542. //包年
  543. $result = DB::table('year_orders')->where('uid', $from)->where('end_time', '>=', date('Y-m-d H:i:s'))->first();
  544. if ($result) {
  545. DB::table('year_orders')->insert([
  546. 'uid' => $to,
  547. 'begin_time' => $result->begin_time,
  548. 'end_time' => $result->end_time,
  549. 'distribution_channel_id' => $distribution_channel_id,
  550. 'send_order_id' => $result->send_order_id,
  551. 'fee' => $result->fee,
  552. 'created_at' => date('Y-m-d H:i:s'),
  553. 'updated_at' => $result->updated_at,
  554. ]);
  555. //\Log::info('year_orders is');
  556. //print_r($result);
  557. }
  558. //书币
  559. $to_user->balance += $from_user->balance;
  560. $to_user->reward_balance += $from_user->balance;
  561. $to_user->nickname = $from_user->nickname;
  562. $to_user->sex = $from_user->sex;
  563. $to_user->head_img = $from_user->head_img;
  564. $to_user->country = $from_user->country;
  565. $to_user->city = $from_user->city;
  566. $to_user->province = $from_user->province;
  567. $to_user->save();
  568. DB::table('crm_transfer')->insert([
  569. 'from_uid' => $from,
  570. 'to_uid' => $to,
  571. 'is_enable' => 1,
  572. 'created_at' => date('Y-m-d H:i:s'),
  573. 'updated_at' => date('Y-m-d H:i:s')
  574. ]);
  575. }
  576. public static function getUserByOpenid($openid)
  577. {
  578. return User::where('openid', $openid)->get();
  579. }
  580. /**
  581. * 实时绑定用户和最新派单的关系,目前在获取章节详情调用;只能在章节详情时调用
  582. * @param [type] $uid [用户id]
  583. * @param [type] $send_order_id [派单id]
  584. * @return [type] [description]
  585. */
  586. public static function bindSendOrderId($uid, $send_order_id)
  587. {
  588. if ($send_order_id) {
  589. $res = Redis::hset('book_read_chapter:' . $uid,'send_order_id', $send_order_id);
  590. }
  591. }
  592. /**
  593. * 实时绑定用户和最新派单的关系后,其它逻辑获取用户绑定的最新派单id
  594. * @param [type] $uid [用户id]
  595. * @param [type] $send_order_id [派单id]
  596. * @return [int] [返回用户的派单id值]
  597. */
  598. public static function GetBindSendOrderId($uid)
  599. {
  600. try {
  601. $send_order_id = Redis::hget('book_read_chapter:' . $uid, 'send_order_id');
  602. if ($send_order_id)
  603. return (int)$send_order_id;
  604. } catch (\Exception $e) {
  605. }
  606. }
  607. }