Userwallet.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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_log(){
  136. $list = Db::name('take_cash')->field('id, number, status, createtime')->where(['user_id'=>$this->auth->id])->autopage()->order('id desc')->select();
  137. if ($list) {
  138. foreach ($list as &$v) {
  139. $v['title'] = '余额提现';
  140. $v['number'] = '-' . $v['number'];
  141. $v['createtime'] = date('Y.m.d H:i', $v['createtime']);
  142. }
  143. }
  144. $this->success('success',$list);
  145. }
  146. //提现金额配置
  147. public function withdrawal_config() {
  148. $show = config('site.withdrawal_show');
  149. $list = Db::name('withdrawal_config')->where('is_show',1)->order('weight asc,id asc')->select();
  150. if ($list) {
  151. $arr = [
  152. 'id' => -1,
  153. 'money' => 0,
  154. 'real_money' => 0,
  155. 'type' => 0,
  156. 'is_show' => 1,
  157. 'weight' => 1
  158. ];
  159. array_push($list, $arr);
  160. }
  161. $return_data['show'] = $show;
  162. $return_data['withdrawal_rate'] = config('site.withdrawal_rate') > 0 ? config('site.withdrawal_rate') : 10;
  163. $return_data['list'] = $list;
  164. $this->success('success',$return_data);
  165. }
  166. //提现
  167. public function withdrawal() {
  168. if ($this->auth->idcard_status != 1) {
  169. $this->error('请先完成实名认证~');
  170. }
  171. $id = input('id', 0, 'intval');
  172. $type = input('type', 0, 'intval'); //账户类型:1=支付宝,2=银行卡
  173. $freemoney = input_post('freemoney', 0, 'intval'); //自定义金额
  174. if (!$id && !$freemoney) {
  175. $this->error('请选择或填写提现金额');
  176. }
  177. if ($id > 0) {
  178. $withdrawal_config = Db::name('withdrawal_config')->find($id);
  179. if (!$withdrawal_config) {
  180. $this->error('提现金额不存在~');
  181. }
  182. if ($withdrawal_config['is_show'] != 1) {
  183. $this->error('提现金额暂未开放~');
  184. }
  185. if ($withdrawal_config['money'] <= 0 || $withdrawal_config['real_money'] <= 0 || $withdrawal_config['money'] < $withdrawal_config['real_money']) {
  186. $this->error('提现金额异常~');
  187. }
  188. //扣除金额
  189. $money = floatval($withdrawal_config['money']);
  190. //实际获得金额
  191. $real_money = $withdrawal_config['real_money'];
  192. }
  193. if ($freemoney > 0) {
  194. //扣除金额
  195. $money = $freemoney;
  196. //实际获得金额
  197. $bili = config('site.withdrawal_rate') >= 0 ? config('site.withdrawal_rate') : 10;
  198. $real_money = number_format($money * (100 - $bili) / 100, 2, '.', '');
  199. }
  200. if ($money <= 0) {
  201. $this->error('提现金额异常');
  202. }
  203. if (!in_array($type, [1, 2])) {
  204. $this->error('请选择提现账户~');
  205. }
  206. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  207. if($check){
  208. $this->error('您有一笔提现在审核中,待审核通过后再申请提现。');
  209. }
  210. $time = strtotime(date('Y-m-d'));
  211. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id, 'wallet_id'=>$id, 'createtime' => ['egt', $time]])->find();
  212. if($check){
  213. $this->error('您今日已经提现过该额度');
  214. }
  215. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  216. if($money > $user_money){
  217. $this->error('可提现余额不足');
  218. }
  219. $user_bank_info = Db::name('user_bank')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  220. if (!$user_bank_info) {
  221. $this->error('请先添加提现方式');
  222. }
  223. $alipay_account = $user_bank_info['banknumber'];
  224. $realname = $user_bank_info['realname'];
  225. $data = [
  226. 'user_id' => $this->auth->id,
  227. 'wallet_id' => $freemoney > 0 ? 0 : $id,
  228. 'number' => $money,
  229. 'money' => $real_money,
  230. 'alipay_account' => $alipay_account,
  231. 'status' => 0,
  232. 'createtime' => time(),
  233. 'updatetime' => time(),
  234. 'type' => $type,
  235. 'realname' => $realname
  236. ];
  237. //计算上级可获得金额
  238. /*if ($this->auth->intro_uid) {
  239. $data['intro_uid'] = $this->auth->intro_uid;
  240. //获取返利比率
  241. $intro_withdrawal_rebate_rate = (int)config('site.intro_withdrawal_rebate_rate');
  242. if ($intro_withdrawal_rebate_rate > 0 && $intro_withdrawal_rebate_rate <= 100) {
  243. //上级获得金额数量
  244. $intro_uid_money = number_format($money * $intro_withdrawal_rebate_rate / 100, 2, '.', '');
  245. if ($intro_uid_money > 0) {
  246. $data['intro_money'] = $intro_uid_money;
  247. }
  248. }
  249. }*/
  250. $msg = '申请成功请等待审核';
  251. //开启事务
  252. Db::startTrans();
  253. $log_id = Db::name('take_cash')->insertGetId($data);
  254. if (!$log_id) {
  255. Db::rollback();
  256. $this->error('您的网络开小差啦~');
  257. }
  258. Db::commit();
  259. //审核时候再扣,或者这里先扣,等需求方确认
  260. $this->success($msg);
  261. }
  262. //每日数据
  263. public function todayincome() {
  264. $start = input('time', 0, 'strtotime'); //时间: 2022-09-30
  265. if (!$start) {
  266. $start = strtotime(date('Y-m-d')); //默认今日
  267. }
  268. $end = $start + 86399;
  269. //收益type
  270. $profit_type = [21,22,23,54,58,60,67];
  271. //今日收益
  272. $today_map = [
  273. 'log_type' => ['IN',$profit_type],
  274. 'user_id' => $this->auth->id,
  275. 'createtime' => ['between',[$start,$end]],
  276. ];
  277. $today_profit = Db::name('user_money_log')->where($today_map)->sum('change_value');
  278. //今日视频时长/收益/人数
  279. $map = [
  280. 'to_user_id' => $this->auth->id,
  281. 'createtime' => ['between',[$start,$end]],
  282. ];
  283. $today_video_min = Db::name('user_match_video_log')->where($map)->sum('call_minutes');
  284. $today_video_income = Db::name('user_match_video_log')->where($map)->sum('money');
  285. $today_video_income = $today_video_income ? : 0;
  286. $today_video_user = Db::name('user_match_video_log')->where($map)->column('user_id');
  287. $today_video_user = array_unique($today_video_user);
  288. $today_video_user_num = count($today_video_user);
  289. //今日语音时长/收益/人数
  290. $today_audio_min = Db::name('user_match_audio_log')->where($map)->sum('call_minutes');
  291. $today_audio_income = Db::name('user_match_audio_log')->where($map)->sum('money');
  292. $today_audio_income = $today_audio_income ? : 0;
  293. $today_audio_user = Db::name('user_match_audio_log')->where($map)->column('user_id');
  294. $today_audio_user = array_unique($today_audio_user);
  295. $today_audio_user_num = count($today_audio_user);
  296. //今日时长/收益/人数
  297. $today_time = $today_video_min + $today_audio_min;
  298. $today_time_income = number_format($today_video_income + $today_audio_income, 2, '.', '');
  299. $today_user_num = $today_video_user_num + $today_audio_user_num;
  300. //礼物收益
  301. $gitft_map = [
  302. 'log_type' => ['IN',[54, 58, 60]],
  303. 'user_id' => $this->auth->id,
  304. 'createtime' => ['between',[$start,$end]],
  305. ];
  306. $today_gift_income = Db::name('user_money_log')->where($gitft_map)->sum('change_value');
  307. //私聊时长/收益/人数
  308. $today_chat_min = Db::name('user_match_typing_log')->where($map)->count('id');
  309. $today_chat_income = Db::name('user_match_typing_log')->where($map)->sum('money');
  310. $today_chat_income = $today_chat_income ? : 0;
  311. $today_chat_user = Db::name('user_match_typing_log')->where($map)->column('user_id');
  312. $today_chat_user = array_unique($today_chat_user);
  313. $today_chat_user_num = count($today_chat_user);
  314. //任务收益 客户要求由money改为gold
  315. $today_task_income = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => 67, 'createtime' => ['between',[$start,$end]]])->sum('change_value');
  316. $today_task_income = $today_task_income ? : 0;
  317. $result = [
  318. 'today_profit' => $today_profit,
  319. 'today_time_income' => $today_time_income,
  320. 'today_gift_income' => $today_gift_income,
  321. 'today_chat_income' => $today_chat_income,
  322. 'today_task_income' => $today_task_income,
  323. 'today_time' => $today_time,
  324. 'today_user_num' => $today_user_num,
  325. 'today_chat_min' => $today_chat_min,
  326. 'today_chat_user_num' => $today_chat_user_num
  327. ];
  328. $this->success('success',$result);
  329. }
  330. //每日数据礼物列表
  331. public function todaygiftlist() {
  332. $start = input('time', 0, 'strtotime'); //时间: 09-30
  333. if (!$start) {
  334. $start = strtotime(date('Y-m-d')); //默认今日
  335. }
  336. $end = $start + 86399;
  337. //今日收益
  338. $today_map = [
  339. 'log_type' => ['IN', [54,/*58,*/60]],
  340. 'user_id' => $this->auth->id,
  341. 'createtime' => ['between',[$start,$end]],
  342. ];
  343. $list = Db::name('user_money_log')->where($today_map)->autopage()->order('id desc')->select();
  344. if (!$list) {
  345. $this->success('success', $list);
  346. }
  347. $mt_gift_user_typing = Db::name('gift_user_typing'); //54
  348. // $mt_gift_user_greet = Db::name('gift_user_greet'); //58
  349. $mt_gift_user_dongtai = Db::name('gift_user_dongtai'); //60
  350. foreach ($list as &$v) {
  351. if ($v['log_type'] == 54) {
  352. $table = $mt_gift_user_typing;
  353. }/* elseif ($v['log_type'] == 58) {
  354. $table = $mt_gift_user_greet;
  355. } */else {
  356. $table = $mt_gift_user_dongtai;
  357. }
  358. $info = $table->where(['id' => $v['table_id']])->find();
  359. $v['gift_name'] = $info['gift_name'];
  360. $v['number'] = $info['number'];
  361. }
  362. $this->success('success', $list);
  363. }
  364. }