UserService.php 25 KB

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