UserService.php 24 KB

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