Userwallet.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. //use app\common\model\wallet;
  6. /**
  7. * 用户钱包
  8. */
  9. class Userwallet extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //我的钱包余额
  14. public function my_wallet(){
  15. $wallet = model('wallet')->getwallet($this->auth->id);
  16. $this->success('success',$wallet);
  17. }
  18. //充值记录
  19. public function gold_recharge_log(){
  20. $map = [
  21. 'user_id' => $this->auth->id,
  22. 'log_type'=> 10,
  23. ];
  24. $list = Db::name('user_gold_log')->field('id,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
  25. $this->success('success',$list);
  26. }
  27. //我的收益,三个数据
  28. public function my_income_count(){
  29. //累计收益,不计来源
  30. $map = [
  31. 'user_id' => $this->auth->id,
  32. //'log_type'=> ['IN',[21,22,23]],
  33. ];
  34. $income_sum = Db::name('user_money_log')->where($map)->sum('change_value');
  35. //可提现总收益
  36. $money_remain = model('wallet')->getwallet($this->auth->id,'money');
  37. //今日收益
  38. $start = strtotime(date('Y-m-d'));
  39. $end = $start + 86399;
  40. $map['createtime'] = ['between',[$start,$end]];
  41. $today_income_sum = Db::name('user_money_log')->where($map)->sum('change_value');
  42. $result = [
  43. 'income_sum' => $income_sum,
  44. 'money_remain' => $money_remain,
  45. 'today_income_sum' => $today_income_sum,
  46. ];
  47. $this->success('success',$result);
  48. }
  49. //追加log_text
  50. private function list_appen_logtext($list){
  51. if(!empty($list)){
  52. $conf = config('wallet.logtype');
  53. foreach($list as $key => $val){
  54. $list[$key]['createtime'] = date('Y.m.d H:i');
  55. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  56. }
  57. }
  58. return $list;
  59. }
  60. //互动收益,打视频,语音,文字聊天,聊天送礼物
  61. public function hudong_money(){
  62. $map = [
  63. 'user_id' => $this->auth->id,
  64. 'log_type'=> ['IN',[21,22,23,54]],
  65. ];
  66. $list = Db::name('user_money_log')
  67. ->field('id,log_type,change_value,remain,remark,createtime')
  68. ->where($map)->order('id desc')->autopage()->select();
  69. $list = $this->list_appen_logtext($list);
  70. $this->success('success',$list);
  71. }
  72. //音聊收益,语聊间礼物
  73. public function party_money(){
  74. $map = [
  75. 'user_id' => $this->auth->id,
  76. 'log_type'=> 52,
  77. ];
  78. $list = Db::name('user_money_log')
  79. ->field('id,log_type,change_value,remain,remark,createtime')
  80. ->where($map)->order('id desc')->autopage()->select();
  81. $list = $this->list_appen_logtext($list);
  82. $this->success('success',$list);
  83. }
  84. //直播收益,直播间礼物
  85. public function livebc_money(){
  86. $map = [
  87. 'user_id' => $this->auth->id,
  88. 'log_type'=> 56,
  89. ];
  90. $list = Db::name('user_money_log')
  91. ->field('id,log_type,change_value,remain,remark,createtime')
  92. ->where($map)->order('id desc')->autopage()->select();
  93. $list = $this->list_appen_logtext($list);
  94. $this->success('success',$list);
  95. }
  96. //我的余额日志
  97. public function my_money_log(){
  98. $type = input_post('type',0);
  99. $map = [
  100. 'user_id' => $this->auth->id,
  101. ];
  102. // if($type){
  103. // $map['log_type'] = $type;
  104. // }
  105. $list = Db::name('user_money_log')
  106. ->field('id,log_type,change_value,remain,remark,createtime, remark log_text')
  107. ->where($map)->order('id desc')->autopage()->select();
  108. // $list = $this->list_appen_logtext($list);
  109. if(!empty($list)){
  110. foreach($list as $key => $val){
  111. $list[$key]['createtime'] = date('Y.m.d H:i', $val['createtime']);
  112. }
  113. }
  114. $this->success('success',$list);
  115. }
  116. //金币日志
  117. public function my_gold_log(){
  118. $type = input_post('type',0);
  119. $map = [
  120. 'user_id' => $this->auth->id,
  121. ];
  122. if($type == 19){
  123. $map['log_type'] = $type;
  124. }
  125. $list = Db::name('user_gold_log')->field('id,log_type,change_value,remain,createtime, remark log_text')->where($map)->order('id desc')->autopage()->select();
  126. // $list = $this->list_appen_logtext($list);
  127. if(!empty($list)){
  128. foreach($list as $key => $val){
  129. $list[$key]['createtime'] = date('Y.m.d H:i', $val['createtime']);
  130. }
  131. }
  132. $this->success('success',$list);
  133. }
  134. //提现配置
  135. public function take_cash_config(){
  136. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
  137. $data = [
  138. 'money' => model('wallet')->getwallet($this->auth->id,'money'),
  139. 'alipay_account' => ($this->auth->idcard_status == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  140. 'min' => 1,
  141. 'max' => 1000,
  142. ];
  143. $this->success('success',$data);
  144. }
  145. //提现
  146. public function take_cash(){
  147. $money = floatval(input_post('money',0));
  148. if(empty($money)){
  149. $this->error();
  150. }
  151. if(empty($this->auth->idcard_status)){
  152. $this->error('请先完成实名认证');
  153. }
  154. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  155. if($check){
  156. $this->error('您已经申请了提现,请等待审核');
  157. }
  158. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  159. if($money > $user_money){
  160. $this->error('提现金额不能大于可提现余额');
  161. }
  162. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
  163. $data = [
  164. 'user_id' => $this->auth->id,
  165. 'number' => $money,
  166. 'alipay_account' => $idcard_confirm['alipay_account'],
  167. 'status' => 0,
  168. 'createtime' => time(),
  169. 'updatetime' => time(),
  170. ];
  171. Db::name('take_cash')->insertGetId($data);
  172. //审核时候再扣,或者这里先扣,等需求方确认
  173. $this->success('申请成功请等待审核');
  174. }
  175. //提现记录
  176. public function take_cash_log(){
  177. $list = Db::name('take_cash')->field('id, number, status, createtime')->where(['user_id'=>$this->auth->id])->autopage()->order('id desc')->select();
  178. if ($list) {
  179. foreach ($list as &$v) {
  180. $v['title'] = '余额提现';
  181. $v['number'] = '-' . $v['number'];
  182. $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
  183. }
  184. }
  185. $this->success('success',$list);
  186. }
  187. //提现金额配置
  188. public function withdrawal_config() {
  189. $show = config('site.withdrawal_show');
  190. $list = Db::name('withdrawal_config')->where('is_show',1)->order('weight asc,id asc')->select();
  191. if ($list) {
  192. $arr = [
  193. 'id' => -1,
  194. 'money' => 0,
  195. 'real_money' => 0,
  196. 'type' => 0,
  197. 'is_show' => 1,
  198. 'weight' => 1
  199. ];
  200. array_push($list, $arr);
  201. }
  202. $return_data['show'] = $show;
  203. $return_data['withdrawal_rate'] = config('site.withdrawal_rate') > 0 ? config('site.withdrawal_rate') : 10;
  204. $return_data['list'] = $list;
  205. $this->success('success',$return_data);
  206. }
  207. //提现(废弃)
  208. public function withdrawal_feiqi() {
  209. if ($this->auth->idcard_status != 1) {
  210. $this->error('请先完成实名认证~');
  211. }
  212. $id = input('id', 0, 'intval');
  213. $type = input('type', 0, 'intval'); //账户类型:1=微信,2=支付宝
  214. if (!$id) {
  215. $this->error('您的网络开小差啦~');
  216. }
  217. $withdrawal_config = Db::name('withdrawal_config')->find($id);
  218. if (!$withdrawal_config) {
  219. $this->error('提现金额不存在~');
  220. }
  221. if ($withdrawal_config['is_show'] != 1) {
  222. $this->error('提现金额暂未开放~');
  223. }
  224. if ($withdrawal_config['money'] <= 0 || $withdrawal_config['real_money'] <= 0 || $withdrawal_config['money'] < $withdrawal_config['real_money']) {
  225. $this->error('提现金额异常~');
  226. }
  227. if (!in_array($type, [1, 2])) {
  228. $this->error('请选择提现账户~');
  229. }
  230. if ($type != 2) {
  231. $this->error('提现方式请选择支付宝');
  232. }
  233. //扣除金额
  234. $money = floatval($withdrawal_config['money']);
  235. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  236. if($check){
  237. $this->error('您已经申请了提现,请等待审核');
  238. }
  239. $time = strtotime(date('Y-m-d'));
  240. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id, 'wallet_id'=>$id, 'createtime' => ['egt', $time]])->find();
  241. if($check){
  242. $this->error('您今日已经提现过该额度');
  243. }
  244. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  245. if($money > $user_money){
  246. $this->error('可提现余额不足');
  247. }
  248. if ($type == 1) { //微信
  249. $alipay_account = '';
  250. } else { //支付宝
  251. $user_bank_info = Db::name('user_bank')->where(['user_id' => $this->auth->id, 'type' => 1])->find();
  252. if (!$user_bank_info) {
  253. $this->error('请先绑定支付宝');
  254. }
  255. $alipay_account = $user_bank_info['banknumber'];
  256. $realname = $user_bank_info['realname'];
  257. /*$idcard_confirm = Db::name('user_idconfirm')->where('user_id', $this->auth->id)->find();
  258. $alipay_account = $idcard_confirm['alipay_account'];*/
  259. }
  260. $data = [
  261. 'user_id' => $this->auth->id,
  262. 'wallet_id' => $id,
  263. 'number' => $money,
  264. 'money' => $withdrawal_config['real_money'],
  265. 'alipay_account' => $alipay_account,
  266. 'status' => 0,
  267. 'createtime' => time(),
  268. 'updatetime' => time(),
  269. 'type' => $type,
  270. 'realname' => $realname
  271. ];
  272. //计算上级可获得金额
  273. if ($this->auth->intro_uid) {
  274. $data['intro_uid'] = $this->auth->intro_uid;
  275. //获取返利比率
  276. $intro_withdrawal_rebate_rate = (int)config('site.intro_withdrawal_rebate_rate');
  277. if ($intro_withdrawal_rebate_rate > 0 && $intro_withdrawal_rebate_rate <= 100) {
  278. //上级获得金额数量
  279. $intro_uid_money = number_format($money * $intro_withdrawal_rebate_rate / 100, 2, '.', '');
  280. if ($intro_uid_money > 0) {
  281. $data['intro_money'] = $intro_uid_money;
  282. }
  283. }
  284. }
  285. $msg = '申请成功请等待审核';
  286. //开启事务
  287. Db::startTrans();
  288. $log_id = Db::name('take_cash')->insertGetId($data);
  289. if (!$log_id) {
  290. Db::rollback();
  291. $this->error('您的网络开小差啦~');
  292. }
  293. if ($withdrawal_config['type'] == 1) { //秒到账,无需审核
  294. $info = Db::name('take_cash')->find($log_id);
  295. //扣钱
  296. $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],0,'money',-$info['number'],15,'提现:'.$info['number'],'take_cash',$info['id']);
  297. if($wallet_rs['status'] === false){
  298. Db::rollback();
  299. $this->error($wallet_rs['msg']);
  300. }
  301. //上级返利
  302. if ($info['intro_uid'] && $info['intro_money'] > 0) {
  303. $wallet_rs = model('wallet')->lockChangeAccountRemain($info['intro_uid'],$info['user_id'],'money',$info['intro_money'],66,'邀请人提现奖励:'.$info['number'],'take_cash',$info['id']);
  304. if($wallet_rs['status'] === false){
  305. Db::rollback();
  306. $this->error($wallet_rs['msg']);
  307. }
  308. }
  309. //自动打款
  310. if ($info['type'] == 1) { //微信
  311. } elseif ($info['type'] == 2) { //支付宝
  312. $dakuanrs = $this->withdraw($info);
  313. if (!$dakuanrs) {
  314. Db::rollback();
  315. $this->error('打款失败');
  316. }
  317. }
  318. //修改提现记录状态
  319. $take_cash_result = Db::name('take_cash')->where(['id' => $log_id, 'status' => 0])->setField('status', 1);
  320. if (!$take_cash_result) {
  321. Db::rollback();
  322. $this->error('打款失败');
  323. }
  324. //系统消息
  325. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现','您的提现已经到账');
  326. $msg = '提现成功';
  327. }
  328. Db::commit();
  329. //审核时候再扣,或者这里先扣,等需求方确认
  330. $this->success($msg);
  331. }
  332. //提现
  333. public function withdrawal() {
  334. if ($this->auth->idcard_status != 1) {
  335. $this->error('请先完成实名认证~');
  336. }
  337. $id = input('id', 0, 'intval');
  338. $type = input('type', 0, 'intval'); //账户类型:1=支付宝,2=银行卡
  339. $freemoney = input_post('freemoney', 0, 'intval'); //自定义金额
  340. if (!$id && !$freemoney) {
  341. $this->error('请选择或填写提现金额');
  342. }
  343. if ($id > 0) {
  344. $withdrawal_config = Db::name('withdrawal_config')->find($id);
  345. if (!$withdrawal_config) {
  346. $this->error('提现金额不存在~');
  347. }
  348. if ($withdrawal_config['is_show'] != 1) {
  349. $this->error('提现金额暂未开放~');
  350. }
  351. if ($withdrawal_config['money'] <= 0 || $withdrawal_config['real_money'] <= 0 || $withdrawal_config['money'] < $withdrawal_config['real_money']) {
  352. $this->error('提现金额异常~');
  353. }
  354. //扣除金额
  355. $money = floatval($withdrawal_config['money']);
  356. //实际获得金额
  357. $real_money = $withdrawal_config['real_money'];
  358. }
  359. if ($freemoney > 0) {
  360. //扣除金额
  361. $money = $freemoney;
  362. //实际获得金额
  363. $bili = config('site.withdrawal_rate') >= 0 ? config('site.withdrawal_rate') : 10;
  364. $real_money = number_format($money * (100 - $bili) / 100, 2, '.', '');
  365. }
  366. if ($money <= 0) {
  367. $this->error('提现金额异常');
  368. }
  369. if (!in_array($type, [1, 2])) {
  370. $this->error('请选择提现账户~');
  371. }
  372. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  373. if($check){
  374. $this->error('您有一笔提现在审核中,待审核通过后再申请提现。');
  375. }
  376. $time = strtotime(date('Y-m-d'));
  377. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id, 'wallet_id'=>$id, 'createtime' => ['egt', $time]])->find();
  378. if($check){
  379. $this->error('您今日已经提现过该额度');
  380. }
  381. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  382. if($money > $user_money){
  383. $this->error('可提现余额不足');
  384. }
  385. $user_bank_info = Db::name('user_bank')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  386. if (!$user_bank_info) {
  387. $this->error('请先添加提现方式');
  388. }
  389. $alipay_account = $user_bank_info['banknumber'];
  390. $realname = $user_bank_info['realname'];
  391. /*$idcard_confirm = Db::name('user_idconfirm')->where('user_id', $this->auth->id)->find();
  392. $alipay_account = $idcard_confirm['alipay_account'];*/
  393. $data = [
  394. 'user_id' => $this->auth->id,
  395. 'wallet_id' => $freemoney > 0 ? 0 : $id,
  396. 'number' => $money,
  397. 'money' => $real_money,
  398. 'alipay_account' => $alipay_account,
  399. 'status' => 0,
  400. 'createtime' => time(),
  401. 'updatetime' => time(),
  402. 'type' => $type,
  403. 'realname' => $realname
  404. ];
  405. //计算上级可获得金额
  406. /*if ($this->auth->intro_uid) {
  407. $data['intro_uid'] = $this->auth->intro_uid;
  408. //获取返利比率
  409. $intro_withdrawal_rebate_rate = (int)config('site.intro_withdrawal_rebate_rate');
  410. if ($intro_withdrawal_rebate_rate > 0 && $intro_withdrawal_rebate_rate <= 100) {
  411. //上级获得金额数量
  412. $intro_uid_money = number_format($money * $intro_withdrawal_rebate_rate / 100, 2, '.', '');
  413. if ($intro_uid_money > 0) {
  414. $data['intro_money'] = $intro_uid_money;
  415. }
  416. }
  417. }*/
  418. $msg = '申请成功请等待审核';
  419. //开启事务
  420. Db::startTrans();
  421. $log_id = Db::name('take_cash')->insertGetId($data);
  422. if (!$log_id) {
  423. Db::rollback();
  424. $this->error('您的网络开小差啦~');
  425. }
  426. Db::commit();
  427. //审核时候再扣,或者这里先扣,等需求方确认
  428. $this->success($msg);
  429. }
  430. //提现转账(新版2020-01-01)
  431. public function withdraw($info) {
  432. $data['out_biz_no'] = getMillisecond() . mt_rand(1, 1000); //商户订单号
  433. $data['trans_amount'] = $info['money']; //订单总金额,单位为元,精确到小数点后两位
  434. $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';//业务产品码,收发现金红包固定为:STD_RED_PACKET;单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD;单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD
  435. $data['biz_scene'] = 'DIRECT_TRANSFER'; //描述特定的业务场景,可传的参数如下:PERSONAL_COLLECTION:C2C现金红包-领红包;DIRECT_TRANSFER:B2C现金红包、单笔无密转账到支付宝/银行卡
  436. $data['order_title'] = '知音佣金发放'; //转账业务的标题,用于在支付宝用户的账单里显示
  437. $data['payee_info']['identity'] = $info['alipay_account'];//收款方支付宝id或支付宝账户
  438. /*if ($info['alipay_type'] == 1) { //支付宝账户
  439. $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
  440. //收款支付宝账号真实姓名, 不为空时支付宝会验证
  441. $data['payee_info']['name'] = $info['name'];
  442. } else { //支付宝id
  443. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  444. $data['payee_info']['name'] = '';
  445. }*/
  446. //支付宝id
  447. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  448. $data['payee_info']['name'] = '';
  449. //转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。
  450. $data['remark'] = '知音佣金发放';
  451. require_once("../extend/AliPay/AliPay.php");
  452. $alipay =new \AliPay();
  453. $result =$alipay->AliPayWithdraw($data);
  454. return $result;
  455. }
  456. //每日数据
  457. public function todayincome() {
  458. $start = input('time', 0, 'strtotime'); //时间: 2022-09-30
  459. if (!$start) {
  460. $start = strtotime(date('Y-m-d')); //默认今日
  461. }
  462. $end = $start + 86399;
  463. //收益type
  464. $profit_type = [21,22,23,54,58,60,67];
  465. //今日收益
  466. $today_map = [
  467. 'log_type' => ['IN',$profit_type],
  468. 'user_id' => $this->auth->id,
  469. 'createtime' => ['between',[$start,$end]],
  470. ];
  471. $today_profit = Db::name('user_money_log')->where($today_map)->sum('change_value');
  472. //今日视频时长/收益/人数
  473. $map = [
  474. 'to_user_id' => $this->auth->id,
  475. 'createtime' => ['between',[$start,$end]],
  476. ];
  477. $today_video_min = Db::name('user_match_video_log')->where($map)->sum('call_minutes');
  478. $today_video_income = Db::name('user_match_video_log')->where($map)->sum('money');
  479. $today_video_income = $today_video_income ? : 0;
  480. $today_video_user = Db::name('user_match_video_log')->where($map)->column('user_id');
  481. $today_video_user = array_unique($today_video_user);
  482. $today_video_user_num = count($today_video_user);
  483. //今日语音时长/收益/人数
  484. $today_audio_min = Db::name('user_match_audio_log')->where($map)->sum('call_minutes');
  485. $today_audio_income = Db::name('user_match_audio_log')->where($map)->sum('money');
  486. $today_audio_income = $today_audio_income ? : 0;
  487. $today_audio_user = Db::name('user_match_audio_log')->where($map)->column('user_id');
  488. $today_audio_user = array_unique($today_audio_user);
  489. $today_audio_user_num = count($today_audio_user);
  490. //今日时长/收益/人数
  491. $today_time = $today_video_min + $today_audio_min;
  492. $today_time_income = number_format($today_video_income + $today_audio_income, 2, '.', '');
  493. $today_user_num = $today_video_user_num + $today_audio_user_num;
  494. //礼物收益
  495. $gitft_map = [
  496. 'log_type' => ['IN',[54, 58, 60]],
  497. 'user_id' => $this->auth->id,
  498. 'createtime' => ['between',[$start,$end]],
  499. ];
  500. $today_gift_income = Db::name('user_money_log')->where($gitft_map)->sum('change_value');
  501. //私聊时长/收益/人数
  502. $today_chat_min = Db::name('user_match_typing_log')->where($map)->count('id');
  503. $today_chat_income = Db::name('user_match_typing_log')->where($map)->sum('money');
  504. $today_chat_income = $today_chat_income ? : 0;
  505. $today_chat_user = Db::name('user_match_typing_log')->where($map)->column('user_id');
  506. $today_chat_user = array_unique($today_chat_user);
  507. $today_chat_user_num = count($today_chat_user);
  508. //任务收益 客户要求由money改为gold
  509. $today_task_income = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => 67, 'createtime' => ['between',[$start,$end]]])->sum('change_value');
  510. $today_task_income = $today_task_income ? : 0;
  511. $result = [
  512. 'today_profit' => $today_profit,
  513. 'today_time_income' => $today_time_income,
  514. 'today_gift_income' => $today_gift_income,
  515. 'today_chat_income' => $today_chat_income,
  516. 'today_task_income' => $today_task_income,
  517. 'today_time' => $today_time,
  518. 'today_user_num' => $today_user_num,
  519. 'today_chat_min' => $today_chat_min,
  520. 'today_chat_user_num' => $today_chat_user_num
  521. ];
  522. $this->success('success',$result);
  523. }
  524. //每日数据礼物列表
  525. public function todaygiftlist() {
  526. $start = input('time', 0, 'strtotime'); //时间: 09-30
  527. if (!$start) {
  528. $start = strtotime(date('Y-m-d')); //默认今日
  529. }
  530. $end = $start + 86399;
  531. //今日收益
  532. $today_map = [
  533. 'log_type' => ['IN', [54,/*58,*/60]],
  534. 'user_id' => $this->auth->id,
  535. 'createtime' => ['between',[$start,$end]],
  536. ];
  537. $list = Db::name('user_money_log')->where($today_map)->autopage()->order('id desc')->select();
  538. if (!$list) {
  539. $this->success('success', $list);
  540. }
  541. $mt_gift_user_typing = Db::name('gift_user_typing'); //54
  542. // $mt_gift_user_greet = Db::name('gift_user_greet'); //58
  543. $mt_gift_user_dongtai = Db::name('gift_user_dongtai'); //60
  544. foreach ($list as &$v) {
  545. if ($v['log_type'] == 54) {
  546. $table = $mt_gift_user_typing;
  547. }/* elseif ($v['log_type'] == 58) {
  548. $table = $mt_gift_user_greet;
  549. } */else {
  550. $table = $mt_gift_user_dongtai;
  551. }
  552. $info = $table->where(['id' => $v['table_id']])->find();
  553. $v['gift_name'] = $info['gift_name'];
  554. $v['number'] = $info['number'];
  555. }
  556. $this->success('success', $list);
  557. }
  558. }