UserService.php 24 KB

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