UserBill.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\user;
  12. use basic\ModelBasic;
  13. use traits\ModelTrait;
  14. /**记录
  15. * Class UserBill
  16. * @package app\wap\model\user
  17. */
  18. class UserBill extends ModelBasic
  19. {
  20. use ModelTrait;
  21. protected $insert = ['add_time'];
  22. protected function setAddTimeAttr()
  23. {
  24. return time();
  25. }
  26. public static function income($title, $uid, $category, $type, $number, $link_id = 0, $balance = 0, $mark = '', $status = 1, $get_uid = 0)
  27. {
  28. $pm = 1;
  29. return self::set(compact('title', 'uid', 'link_id', 'category', 'type', 'number', 'balance', 'mark', 'status', 'pm', 'get_uid'));
  30. }
  31. public static function expend($title, $uid, $category, $type, $number, $link_id = 0, $balance = 0, $mark = '', $status = 1)
  32. {
  33. $pm = 0;
  34. return self::set(compact('title', 'uid', 'link_id', 'category', 'type', 'number', 'balance', 'mark', 'status', 'pm'));
  35. }
  36. public static function getSginDay($year, $month, $uid)
  37. {
  38. $model = self::where('uid', $uid)->where(['category' => 'integral', 'type' => 'sign', 'status' => 1, 'pm' => 1]);
  39. if (!$year && !$month) {
  40. $model->whereTime('add_time', 'm');
  41. } else {
  42. $t = date('t', strtotime($year . '-' . $month));
  43. $model->whereTime('add_time', 'between', [strtotime($year . '-' . $month), strtotime($year . '-' . $month . '-' . $t)]);
  44. }
  45. $list = $model->field(['from_unixtime(add_time,\'%d\') as time'])->order('time asc')->select();
  46. count($list) && $list = $list->toArray();
  47. foreach ($list as &$item) {
  48. $item['day'] = ltrim($item['time'], '\0');
  49. }
  50. return $list;
  51. }
  52. /**
  53. * 获取提现记录或者佣金记录
  54. * @param $where arrat 查询条件
  55. * @param $uid int 用户uid
  56. * @return array
  57. *
  58. * */
  59. public static function getSpreadList($where, $uid)
  60. {
  61. $uids = User::where('spread_uid', $uid)->column('uid');
  62. $uids1 = User::where('spread_uid', 'in', $uids)->group('uid')->column('uid');
  63. $model = self::where('a.uid', $uid)->alias('a')->join('__USER__ u', 'u.uid=a.uid')->where('a.link_id', 'neq', 0)->order('a.add_time desc');
  64. switch ((int)$where['type']) {
  65. case 0:
  66. $model = $model->join('store_order o', 'o.id = a.link_id')->whereIn('o.uid', $uids);
  67. $model = $model->where('a.category', 'now_money')->order('a.add_time desc')->where('a.number', '<>', 0)
  68. ->field('FROM_UNIXTIME(a.add_time,"%Y-%m") as time,group_concat(a.id SEPARATOR ",") ids')
  69. ->where('a.type', 'in', 'brokerage,brokerage_return')
  70. ->group('time');
  71. break;
  72. case 1:
  73. $model = $model->join('store_order o', 'o.id = a.link_id')->whereIn('o.uid', $uids1);
  74. $model = $model->where('a.category', 'now_money')->order('a.add_time desc')->where('a.number', '<>', 0)
  75. ->field('FROM_UNIXTIME(a.add_time,"%Y-%m") as time,group_concat(a.id SEPARATOR ",") ids')
  76. ->where('a.type', 'in', 'brokerage,brokerage_return')
  77. ->group('time');
  78. break;
  79. }
  80. $model = $model->page((int)$where['page'], (int)$where['limit']);
  81. $list = ($list = $model->select()) ? $list->toArray() : [];
  82. $data = [];
  83. foreach ($list as &$item) {
  84. $value['time'] = $item['time'];
  85. $value['list'] = self::where('id', 'in', $item['ids'])->field('FROM_UNIXTIME(add_time,"%Y-%m-%d %H:%i") as add_time,uid,title,number,mark,pm')->order('add_time DESC')->select();
  86. array_push($data, $value);
  87. }
  88. $page = $where['page'] + 1;
  89. return compact('data', 'page');
  90. }
  91. public static function get_user_withdrawal_list($where, $uid)
  92. {
  93. $model = self::where('uid', $uid)->where('category', 'now_money')->order('add_time desc')->where('number', '<>', 0)
  94. ->field('FROM_UNIXTIME(add_time,"%Y-%m") as time,group_concat(id SEPARATOR ",") ids')
  95. ->where('type', 'in', 'extract,extract_fail')
  96. ->group('time');
  97. $model = $model->page((int)$where['page'], (int)$where['limit']);
  98. $list = ($list = $model->select()) ? $list->toArray() : [];
  99. $data = [];
  100. foreach ($list as $item) {
  101. $value['time'] = $item['time'];
  102. $value['list'] = self::where('id', 'in', $item['ids'])->field('FROM_UNIXTIME(add_time,"%Y-%m-%d %H:%i") as add_time,title,number,pm')->order('add_time DESC')->select();
  103. array_push($data, $value);
  104. }
  105. $page = $where['page'] + 1;
  106. return compact('data', 'page');
  107. }
  108. /*
  109. * 获得某年某月的天数
  110. * */
  111. public static function DaysInMonth($month, $year)
  112. {
  113. return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
  114. }
  115. /*
  116. * 获取总佣金
  117. * */
  118. public static function getBrokerage($uid, $category = 'now_money', $type = 'brokerage', $where)
  119. {
  120. return self::getModelTime($where, self::where('uid', 'in', $uid)->where('category', $category)
  121. ->where('type', $type)->where('pm', 1)->where('status', 1))->sum('number');
  122. }
  123. /*
  124. * 获取返还佣金
  125. * */
  126. public static function getReturnBrokerage($uid, $category = 'now_money', $type = 'brokerage_return', $where)
  127. {
  128. return self::getModelTime($where, self::where('uid', 'in', $uid)->where('category', $category)
  129. ->where('type', $type)->where('pm', 0)->where('status', 1))->sum('number');
  130. }
  131. /**获取用户佣金金额
  132. * @param int $uid
  133. */
  134. public static function getCommissionAmount($uid = 0)
  135. {
  136. $brokerage = self::where('uid', 'in', $uid)->where('category', 'now_money')
  137. ->where('type', 'brokerage')->where('pm', 1)->where('status', 1)->sum('number');
  138. $brokerage_return = self::where('uid', 'in', $uid)->where('category', 'now_money')
  139. ->where('type', 'brokerage_return')->where('pm', 0)->where('status', 1)->sum('number');
  140. $commission = bcsub($brokerage, $brokerage_return, 2);
  141. return $commission;
  142. }
  143. public static function getUserGoldBill(array $where, $page = 0, $limit = 10)
  144. {
  145. $model = self::where('status', 1);
  146. if ($where) {
  147. $list = $model->where($where);
  148. }
  149. $list = $model->order('add_time desc')->page((int)$page, (int)$limit)->select();
  150. $list = count($list) ? $list->toArray() : [];
  151. foreach ($list as &$item) {
  152. $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  153. }
  154. $page--;
  155. return ['list' => $list, 'page' => $page];
  156. }
  157. }