Plantask.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. namespace app\index\controller;
  3. use app\utils\JingXiu\JingXiuPayUtil;
  4. use think\Controller;
  5. use think\Db;
  6. use think\Cache;
  7. class Plantask extends Controller
  8. {
  9. /**
  10. * 精秀支付订单支付状态查询
  11. * @return string|void
  12. */
  13. public function auto_pay_queue()
  14. {
  15. // 处理次数
  16. $queue_times = 6;
  17. //查询订单信息 十分钟未处理的
  18. $order_info = Db::name('pay_order')
  19. ->where('queue_status', 1)
  20. ->where('status',0)
  21. ->where('queue_times','<',$queue_times)
  22. ->where('createtime','<',time() - 600)
  23. ->order('queue_times','asc')
  24. ->find();
  25. if (!$order_info){
  26. return '无订单';
  27. }
  28. // 增加处理次数
  29. Db::name('pay_order')->where('id',$order_info['id'])->update(['queue_times' => $order_info['queue_times'] + 1]);
  30. // 查询订单是否支付成功
  31. $pay = new JingXiuPayUtil();
  32. if (!$pay->getOrder($order_info['pay_no'])){
  33. $this->error($pay->getMessage());
  34. }
  35. //PROCESSING=订单待支付,SUCCESS=订单支付成功,TIME_OUT=订单已过期,FAIL=订单支付失败,CLOSE=订单关闭,CALL_FAIL=支付成功未返回
  36. $params = $pay->getData();
  37. if (empty($params['order_status']) || $params['order_status'] != 'SUCCESS' || empty($params['out_trade_no'])) {
  38. $status = $params['order_status'] ?? 'error';
  39. return '支付信息有误'.$status.':'.$params['out_trade_no'];
  40. }
  41. // 开始处理业务逻辑
  42. $pay_no = $params['out_trade_no'];
  43. //查询订单信息
  44. $order_info = Db::name('pay_order')->where('pay_no', $pay_no)->find();
  45. if (!$order_info) {
  46. return '订单信息不存在'.$pay_no;
  47. }
  48. if ($order_info['status'] == 3){
  49. return '订单信息_已删除'.$pay_no;
  50. }
  51. if ($order_info['status'] == 1 || $order_info['status'] == 2) {
  52. return '充值入账更新余额失败_status已更新过'.$pay_no;
  53. }
  54. $extendType = '';
  55. //区分vip 还是 冲金币
  56. $is_g = stripos($pay_no, 'P');
  57. if ($is_g !== false) {
  58. $extendType = 'gold';
  59. } else {
  60. $is_v = stripos($pay_no, 'V');
  61. if ($is_v !== false) {
  62. $extendType = 'vip';
  63. }
  64. }
  65. //status已更新过
  66. $result = Db::name('pay_order')->where('pay_no', $pay_no)->where('status',$order_info['status'])->setField(['status' => 2]);
  67. if (!$result) {
  68. return '充值入账更新余额失败_status更新状态2不成功'.$pay_no;
  69. }
  70. //你可以在此编写订单逻辑
  71. $payEvent = Db::name('pay_event')->where('pay_no', $pay_no)->find();
  72. $args = json_decode($payEvent['args'] ?? '', true);
  73. $rechargeM = new \app\common\model\Recharge();
  74. if ($extendType == 'gold') {
  75. $payRes = $rechargeM->goldpaysucc($pay_no, $args);
  76. $payTypeStr = '充值';
  77. } elseif ($extendType == 'vip') {
  78. $payRes = $rechargeM->vippaysucc($pay_no, $args);
  79. $payTypeStr = 'vip';
  80. } else {
  81. $payRes = false;
  82. $payTypeStr = '未知支付类型';
  83. }
  84. if (!$payRes) {
  85. return '更新失败'.$payTypeStr.$pay_no;
  86. }
  87. return '订单处理成功'.$payTypeStr.$pay_no;
  88. }
  89. //定时跑用户活跃,改成离线
  90. public function auto_user_active(){
  91. $actitime = time() - 7200;
  92. $sql = 'update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime < '.$actitime.')';
  93. db()->query($sql);
  94. }
  95. //计划任务
  96. //代替公会的人10秒内发出五句话
  97. public function firstuser_send()
  98. {
  99. exit;
  100. //找出24小时内注册的男人
  101. $map = [
  102. 'jointime' => ['gt',time()-86400],
  103. 'gender' => 1,
  104. 'gh_id' => 0,
  105. 'auto_first_word' => 0,
  106. ];
  107. $oneuser = Db::name('user')->where($map)->order('id asc')->value('id');
  108. dump($oneuser);
  109. if(!$oneuser){
  110. echo 'empty';
  111. exit;
  112. }
  113. //找出公会的人
  114. $map = [
  115. 'gh_id' => ['gt',0],
  116. 'gender' => 0,
  117. ];
  118. $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->limit(5)->column('id');
  119. //dump($ghuser);
  120. //随机取出一句话
  121. $oneword = Db::name('plantask_accost')->orderRaw('rand()')->limit(5)->column('title');
  122. //dump($oneword);
  123. //发送出去
  124. $tenim = new \app\common\library\Tenim;
  125. for($i = 0;$i < 5;$i++){
  126. $ghuser_one = isset($ghuser[$i]) ? $ghuser[$i] : $ghuser[array_rand($ghuser)];
  127. $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
  128. $tenim->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
  129. sleep(2);
  130. }
  131. Db::name('user')->where('id',$oneuser)->update(['auto_first_word'=>1]);
  132. }
  133. //计划任务,二期之后,废弃
  134. //代替公会的人发出第一句话
  135. public function firstword_send()
  136. {
  137. exit;
  138. //找出24小时内注册的男人
  139. $map = [
  140. 'jointime' => ['gt',time()-86400],
  141. 'gender' => 1,
  142. 'gh_id' => 0,
  143. ];
  144. $oneuser = Db::name('user')->where($map)->orderRaw('rand()')->value('id');
  145. //dump($oneuser);
  146. //找出公会的人
  147. $map = [
  148. 'gh_id' => ['gt',0],
  149. 'gender' => 0,
  150. ];
  151. $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->value('id');
  152. //dump($ghuser);
  153. //随机取出一句话
  154. $oneword = Db::name('plantask_accost')->orderRaw('rand()')->value('title');
  155. //dump($oneword);
  156. //发送出去
  157. $cache = Cache::connect(['type'=>'Redis']);
  158. $times = $cache->get('plantask_first_word_'.$oneuser);
  159. //dump($times);
  160. if($times === false){
  161. $times = 0;
  162. }
  163. if($times < 5){
  164. $tenim = new \app\common\library\Tenim;
  165. $tenim->sendMessageToUser($ghuser,$oneuser,$oneword);
  166. $cache->set('plantask_first_word_'.$oneuser, $times + 1);
  167. }
  168. }
  169. //计划任务
  170. //清空没用的redis
  171. public function firstword_clear(){
  172. $map = [
  173. 'jointime' => ['between',[time()-172800,time()-86400]],
  174. 'gender' => 1,
  175. 'gh_id' => 0,
  176. ];
  177. $map = [];
  178. $userlist = Db::name('user')->where($map)->order('id asc')->column('id');
  179. if(empty($userlist)){
  180. echo 'empty';
  181. exit;
  182. }
  183. //清除
  184. $cache = Cache::connect(['type'=>'Redis']);
  185. foreach($userlist as $key => $val){
  186. $cache->rm('plantask_first_word_'.$val);
  187. }
  188. }
  189. //测试用
  190. //清空redis
  191. public function clear_redis(){
  192. $val = input('uid');
  193. $cache = Cache::connect(['type'=>'Redis']);
  194. $cache->rm('plantask_first_word_'.$val);
  195. }
  196. //发放代理奖励
  197. public function issuingreward() {
  198. set_time_limit(0);
  199. //本周开始时间
  200. $week_start_time = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  201. $where['user_id'] = ['gt', 0];
  202. $where['issuingtime'] = ['elt', $week_start_time];
  203. $mt_admin = Db::name('admin');
  204. $list = $mt_admin->field('id, user_id, issuingtime')->where($where)->limit(100)->select();
  205. if (!$list) {
  206. echo 'mei shu ju';
  207. die;
  208. }
  209. //上周开始时间 上周结束时间
  210. $starttime = $week_start_time - 604800;
  211. $endtime = $week_start_time - 1;
  212. $money_map['log_type'] = ['in', [21, 22, 23, 54, 60, 82]];
  213. $money_map['createtime'] = ['between', [$starttime, $endtime]];
  214. $mt_user_money_log = Db::name('user_money_log');
  215. $mt_user = Db::name('user');
  216. $mt_extend_reward = Db::name('extend_reward');
  217. $issuingtime = time();
  218. foreach ($list as $k => &$v) {
  219. //开启事务
  220. Db::startTrans();
  221. //修改记录状态
  222. $rs = $mt_admin->where(['id' => $v['id'], 'issuingtime' => $v['issuingtime']])->setField('issuingtime', $issuingtime);
  223. if (!$rs) {
  224. Db::rollback();
  225. continue;
  226. }
  227. $user_ids = $mt_user->where(['intro_uid' => $v['user_id']])->column('id');
  228. if ($user_ids) {
  229. $money_map['user_id'] = ['in', $user_ids];
  230. //周收益
  231. $week_sum_money = $mt_user_money_log->where($money_map)->sum('change_value');
  232. $week_sum_money = $week_sum_money > 0 ? $week_sum_money : 0;
  233. if ($week_sum_money) {
  234. //查询推广奖励等级
  235. $extend_reward_info = $mt_extend_reward->where(['total_flow' => ['elt', $week_sum_money]])->order('id desc')->find();
  236. if ($extend_reward_info) {
  237. //额外提成
  238. $extra_moeny = number_format($week_sum_money * $extend_reward_info['extra_reward'] / 100, 2, '.', '');
  239. if ($extra_moeny > 0) {
  240. //发放额外提出
  241. $wallet_rs = model('wallet')->lockChangeAccountRemain($v['user_id'],0,'money',$extra_moeny,91,'额外提成奖励');
  242. if($wallet_rs['status'] === false){
  243. Db::rollback();
  244. } else {
  245. //发送系统消息
  246. \app\common\model\Message::addMessage($v['user_id'],'额外提成奖励','上周额外提成奖励已经发放');
  247. }
  248. }
  249. }
  250. }
  251. }
  252. Db::commit();
  253. }
  254. echo 'wan bi';
  255. die;
  256. }
  257. /**
  258. * 超过24小时未上传头像的女用户隐身
  259. * @return void
  260. */
  261. public function userHide()
  262. {
  263. //找出24小时内注册未上传头像的女用户
  264. $userHideTime = config('site.user_hide_time');
  265. $start_time = time() - (3600 * 27);
  266. $end_time = time() - ($userHideTime * 60);
  267. $girlAvatar = config('avatar_girl');
  268. $where = [
  269. 'gender' => 0,
  270. 'avatar' => $girlAvatar,
  271. 'status' => 1,
  272. ];
  273. $user = Db::name('user')->field('id')->whereBetween('jointime',[$start_time,$end_time])->where($where)->order('id asc')->select();
  274. if(empty($user)){
  275. echo 'empty';
  276. exit;
  277. }
  278. $userIds = array_column($user,'id');
  279. $updateWhere['id'] = ['in',$userIds];
  280. $countRes = Db::name('user')->where($updateWhere)->update(['status'=>2]);//隐藏
  281. echo 'update '.$countRes;
  282. exit;
  283. }
  284. /**
  285. * 五分钟禁用女用户账号
  286. * @return void
  287. */
  288. public function userClose()
  289. {
  290. $start_time = time() - (3600 * 27);
  291. $end_time = time() - (5 * 60);
  292. $where = [
  293. 'gender' => 0,
  294. 'is_closed' => 0,
  295. 'status' => 1,
  296. ];
  297. $user = Db::name('user')->field('id')->whereBetween('jointime',[$start_time,$end_time])->where($where)->order('id asc')->select();
  298. if(empty($user)){
  299. echo 'empty';
  300. exit;
  301. }
  302. $userIds = array_column($user,'id');
  303. $updateWhere['id'] = ['in',$userIds];
  304. $updateWhere2['user_id'] = ['in',$userIds];
  305. $countRes = Db::name('user')->where($updateWhere)->update(['status'=>0,'is_closed'=>1]);//金庸
  306. $countRes2 = Db::name('user_token')->where($updateWhere2)->delete();//金庸
  307. echo 'update '.$countRes;
  308. echo 'delete '.$countRes2;
  309. exit;
  310. }
  311. /**
  312. * 自动推荐
  313. * @return void
  314. */
  315. public function userRecommend()
  316. {
  317. $payMoney = config('site.recommend_pay_money');//财富值
  318. $getMoney = config('site.recommend_get_money');//魅力值
  319. if ($payMoney <= 0 && $getMoney <= 0) {
  320. echo 'empty';exit;
  321. }
  322. $where = 'u.is_recommend = 0 ';
  323. if ($payMoney > 0) {
  324. $whereAppend = $where.' and uw.pay_money >= '.$payMoney;
  325. }
  326. if ($getMoney > 0) {
  327. $whereAppend = $where.' and uw.get_money >= '.$getMoney;
  328. }
  329. if ($payMoney >0 && $getMoney >0) {
  330. $whereAppend = $where. ' and (uw.pay_money >= '.$payMoney.' or uw.get_money >= '.$getMoney.')' ;
  331. }
  332. $user = Db::name('user')->alias('u')->field('u.id')
  333. ->join('user_wallet uw','uw.user_id = u.id','LEFT')
  334. ->where($whereAppend)
  335. ->select();
  336. if (empty($user)) {
  337. echo 'update 0';exit;
  338. }
  339. $userIds = array_column($user,'id');
  340. $userWhere['id'] = ['in',$userIds];
  341. $userUpdateData['is_recommend'] = 1;
  342. $userUpdateData['updatetime'] = time();
  343. $userRes = Db::name('user')->where($userWhere)->update($userUpdateData);
  344. echo 'update '.$userRes;exit;
  345. }
  346. }