AccountLog.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. namespace App\Modes;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * App\Modes\AccountLog
  6. *
  7. * @property int $id
  8. * @property int $uid 用户ID
  9. * @property int $source_uid 来源用户id
  10. * @property int $type 记录类型 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金 6-广告业绩 10-直推(广告代理费分佣) 11-间一(广告代理费分佣) 12-间二(广告代理费分佣)13-全局(广告代理费分佣) 20-直推(推广代理费分佣) 21-间一(推广代理费分佣) 22-间二(推广代理费分佣)23-全局(推广代理费分佣) 10? 对应订单类型
  11. * @property int $status 状态 0-未生效 1-成功 2-失效
  12. * @property int $money_type 1-点币 2-RMB
  13. * @property float $money 金额(收入为正,支出为负)
  14. * @property int $current_money 当前用户余额
  15. * @property string $remark 备注
  16. * @property \Illuminate\Support\Carbon $created_at
  17. * @property \Illuminate\Support\Carbon $updated_at
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog newModelQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog newQuery()
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog query()
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereCreatedAt($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereCurrentMoney($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereId($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereMoney($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereMoneyType($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereRemark($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereSourceUid($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereStatus($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereType($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereUid($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereUpdatedAt($value)
  32. * @mixin \Eloquent
  33. */
  34. class AccountLog extends Model
  35. {
  36. protected $table = 'account_log';
  37. //
  38. /**
  39. * 保存账号流水
  40. * @author lyh
  41. * @date 2019/3/25
  42. * @param int $type 记录类型 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金
  43. * @param int $money 金额
  44. * @param int $source_id 来源
  45. * @param int $money_type 类型 1-点币 2-RMB
  46. * @param int $status
  47. * @description
  48. */
  49. public static function saveData($type = 0, $money = 0, $source_id = 0, $money_type = 2, $status = 1, $remark = '')
  50. {
  51. AccountLog::insertGetId([
  52. 'uid' => \Auth::id(),
  53. 'source_uid' => $source_id,
  54. 'type' => $type,
  55. 'status' => $status,
  56. 'money_type' => $money_type,
  57. 'money' => $money,
  58. 'current_money' => self::getCurentMoney($type),
  59. 'remark' => $remark
  60. ]);
  61. }
  62. public static function saveDataByPost($uid,$type = 0, $money = 0,$current_money, $money_type = 2, $status = 1, $remark = '',$source_uid=0)
  63. {
  64. AccountLog::insert([
  65. 'uid' => $uid,
  66. 'source_uid' => $source_uid,
  67. 'type' => $type,
  68. 'status' => $status,
  69. 'money_type' => $money_type,
  70. 'money' => $money,
  71. 'current_money' => $current_money,
  72. 'remark' => $remark
  73. ]);
  74. }
  75. /*
  76. * 获取收益addby wsl
  77. * ids array 用户id
  78. *
  79. * */
  80. public static function getShouYi($ids,$starttime,$endtime){
  81. //$starttime='2019-06-01';
  82. //$endtime='2019-06-28 15:45:50';
  83. $list=AccountLog::whereIn('type',[5, 10, 11, 12, 13, 20, 21, 22, 23])->where('uid','=',\Auth::id())->whereIn('source_uid',$ids)->whereBetween('created_at',[$starttime,$endtime])->get();
  84. $count=0;
  85. $sum=0;
  86. $gguser=[];
  87. $dluser=[];
  88. $ggsum=0;
  89. $dlsum=0;
  90. if(!empty($list)){
  91. foreach($list as $key=>$value){
  92. $count++;
  93. $sum+=$value->money;
  94. if(strpos($value->remark,'广告')==true){
  95. if(!in_array($value->uid,$gguser)){
  96. $gguser[]=$value->uid;
  97. }
  98. $ggsum+=$value->money;
  99. }else{
  100. if(!in_array($value->uid,$dluser)){
  101. $dluser[]=$value->uid;
  102. }
  103. $dlsum+=$value->money;
  104. }
  105. }
  106. }
  107. $arr=[
  108. 'uv' => $count, // 代理收益次数
  109. 'earnings' => round($sum,3),// 总收益
  110. 'inviteNum' => count($ids), // 下级代理数量
  111. 'proxyNum' => count($dluser), // 代理数量
  112. 'proxyMoney' => round($dlsum,3), // 代理收益
  113. 'adverNum' => count($gguser), // 广告数量
  114. 'adverMoney' => round($ggsum,3), // 广告收益
  115. ];
  116. return $arr;
  117. }
  118. /**
  119. * 获取当前账号余额
  120. * @author lyh
  121. * @date 2019/3/25
  122. * @param int $type
  123. * @description
  124. */
  125. private static function getCurentMoney(int $type)
  126. {
  127. $user = User::find(\Auth::id());
  128. if ($type = 1) {
  129. return $user->coin;
  130. } else {
  131. return $user->balance;
  132. }
  133. }
  134. /**
  135. * 获取金额
  136. * @author lyh
  137. * @date 2019/3/25
  138. * @param $id
  139. * @param array $array
  140. * @return mixed
  141. * @description
  142. */
  143. public static function getSumMoney($id, array $array, $where = [])
  144. {
  145. $res = AccountLog::whereUid($id)
  146. ->whereStatus(1)
  147. ->whereIn('type', $array);
  148. if (!empty($where)) {
  149. $res->where($where);
  150. }
  151. return $res->sum('money');
  152. }
  153. /**
  154. * 统计次数
  155. * @author lyh
  156. * @date 2019/3/25
  157. * @param $id
  158. * @param array $array
  159. * @return mixed
  160. * @description
  161. */
  162. public static function getUv($id, array $array, $start_time, $end_time, $where = [])
  163. {
  164. $res = AccountLog::whereStatus(1)
  165. ->whereIn('uid', $id)
  166. ->whereIn('type', $array);
  167. if (!empty($where)) {
  168. $res->where($where);
  169. }
  170. if ($start_time != null && $end_time != null) {
  171. $res->whereBetween('created_at', [$start_time, $end_time]);
  172. }
  173. return $res->count('id');
  174. }
  175. /**
  176. * 业绩
  177. * @author lyh
  178. * @date 2019/3/26
  179. * @param int $id
  180. * @param array $type
  181. * @param string $start
  182. * @param string $end
  183. * @description
  184. */
  185. public static function getBusinessGoal(int $id, array $type, $start, $end)
  186. {
  187. return AccountLog::whereStatus(1)
  188. ->whereIn('uid', User::getAllInvite($id))
  189. ->whereBetween('created_at', [$start, $end])
  190. ->whereIn('type', $type)
  191. ->sum('money');
  192. }
  193. /**
  194. * 获取收益
  195. * @author lyh
  196. * @date 2019/3/27
  197. * @param array $id
  198. * @param array $type
  199. * @param $start_time
  200. * @param $end_time
  201. * @return int
  202. * @description
  203. */
  204. public static function getEarngings(array $id, array $type, $start_time, $end_time)
  205. {
  206. $res = AccountLog::whereStatus(1)
  207. ->whereIn('uid', $id)
  208. ->whereIn('type', $type);
  209. if (!empty($where)) {
  210. $res->where($where);
  211. }
  212. if ($start_time != null && $end_time != null) {
  213. $res->whereBetween('created_at', [$start_time, $end_time]);
  214. }
  215. return $res->sum('money');
  216. }
  217. /**
  218. * 获取带来收益用户数
  219. * @author lyh
  220. * @date 2019/3/27
  221. * @param array $ids
  222. * @param array $array
  223. * @param $start_time
  224. * @param $end_time
  225. * @param array $ids1
  226. * @return int
  227. * @description
  228. */
  229. public static function getInviteUv(array $ids, array $array, $start_time, $end_time, array $ids1)
  230. {
  231. $res = AccountLog::whereStatus(1)
  232. ->whereIn('uid', $ids)
  233. ->groupBy('uid')
  234. ->whereIn('type', $array);
  235. if (!empty($where)) {
  236. $res->where($where);
  237. }
  238. if ($start_time != null && $end_time != null) {
  239. $res->whereBetween('created_at', [$start_time, $end_time]);
  240. }
  241. return $res->count('uid');
  242. }
  243. /**
  244. * @author lyh
  245. * @date 2019/4/12
  246. * @param int $type
  247. * @description
  248. * 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金 6-广告业绩 7-升级交费 10-直推(广告代理费分佣) 11-间一(广告代理费分佣) 12-间二(广告代理费分佣)13-全局(广告代理费分佣) 20-直推(推广代理费分佣) 21-间一(推广代理费分佣) 22-间二(推广代理费分佣)23-全局(推广代理费分佣)30-点币转账-收入 31-点币转账-支出 32-点币购买 10? 对应订单类型
  249. */
  250. public static function getTypeMsg(int $type)
  251. {
  252. $msg = [
  253. 1 => '提现',
  254. 2 => '转账点币-收入',
  255. 3 => '转账点币-支出',
  256. 4 => '提现',
  257. 5 => '佣金',
  258. 6 => '广告业绩',
  259. 7 => '升级交费',
  260. 10 => '直推(广告代理费分佣)',
  261. 11 => '间一(广告代理费分佣)',
  262. 12 => '间二(广告代理费分佣)',
  263. 13 => '全局(广告代理费分佣)',
  264. 20 => '直推(推广代理费分佣)',
  265. 21 => '间一(推广代理费分佣)',
  266. 22 => '间二(推广代理费分佣)',
  267. 23 => '全局(推广代理费分佣)',
  268. 30 => '点币转账-收入',
  269. 31 => '点币转账-支出',
  270. 32 => '点币购买',
  271. 101 => '升级支付',
  272. 102 => '购买广告支付',
  273. 103 > '点币购买',
  274. ];
  275. if (in_array($type, $msg)) {
  276. return $msg[$type];
  277. }
  278. return '';
  279. }
  280. }