WalletLog.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Log;
  7. class WalletLog extends Model
  8. {
  9. use ModelHelpers;
  10. protected $guarded = [];
  11. const STATUS_OK = 1;
  12. const STATUS_PAUSE = 0;
  13. public static $statusMaps = [
  14. self::STATUS_OK => '正常',
  15. self::STATUS_PAUSE => '暂停'
  16. ];
  17. const OPERATE_TYPE_ADD = 1;
  18. const OPERATE_TYPE_SUB = 0;
  19. public static $operateTypeMaps = [
  20. self::OPERATE_TYPE_ADD => '充值',
  21. self::OPERATE_TYPE_SUB => '消费'
  22. ];
  23. //充值(微信)
  24. const TYPE_ADD_WECHAT_TO_WALLET = 0;
  25. //骑车消费(从余额)/////////////////////////
  26. const TYPE_SUB_WALLET_BIKE_ORDER = 1;
  27. // 后台管理员结算订单(从余额扣除)//////////////////
  28. const TYPE_ADMIN_SUB_BIKE_ORDER = 2;
  29. // 后台管理员返还(增加到钱包余额)
  30. const TYPE_ADMIN_ADD_TO_WALLET = 3;
  31. //租金消费(从余额)////////////////////////////////
  32. const TYPE_SUB_WALLET_RENT_ORDER = 7;
  33. //租车订单消费
  34. const TYPE_SUB_WALLET_RENT_ORDER_MONEY = 5;
  35. // 企业支付 退余额
  36. const TYPE_SUB_WALLET = 9;
  37. //充值(微信)
  38. const TYPE_ADD_ADMIN_TO_WALLET = 11;
  39. // 微信支付订单
  40. const TYPE_ADD_WECHAT_PAY_ORDER = 20;
  41. // 微信订单消费(直接)
  42. const TYPE_SUB_WECHAT_PAY_ORDER = 21;
  43. // 微信支付订单
  44. const TYPE_ADD_WECHAT_PAY_PUNISHMENT_ORDER = 22;
  45. // 微信订单消费(直接)
  46. const TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER = 23;
  47. //【充值】微信直接支付租金
  48. const TYPE_ADD_WECHAT_PAY_RENT_ORDER = 30;
  49. //【消费】微信直接支付租金
  50. const TYPE_SUB_WECHAT_PAY_RENT_ORDER = 31;
  51. //【充值】微信直接支付租车超时金额
  52. const TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY = 32;
  53. //【消费】微信直接支付租车超时金额
  54. const TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY = 33;
  55. //订单返现
  56. const TYPE_ADD_WECHAT_PAY_ORDER_MONEY = 34;
  57. const TYPE_SUB_ORDER_MONEY_PAY_WECHAT = 35;
  58. // 骑行卡
  59. const TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER = 40;
  60. const TYPE_SUB_WECHAT_PAY_CARD_RIDING_ORDER = 41;
  61. // 免押金卡
  62. const TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER = 50;
  63. const TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER = 51;
  64. //充值赠送
  65. const TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET = 10;
  66. //邀新赠送
  67. const TYPE_ADD_INVITE_NEW_TO_WELLET = 12;
  68. public static $subType = [
  69. // 次处为 纯收益 不带余额
  70. self::TYPE_SUB_WALLET_RENT_ORDER_MONEY,
  71. self::TYPE_SUB_WALLET_RENT_ORDER,
  72. self::TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY,
  73. self::TYPE_SUB_WECHAT_PAY_RENT_ORDER,
  74. self::TYPE_SUB_WALLET_BIKE_ORDER,
  75. self::TYPE_ADMIN_SUB_BIKE_ORDER,
  76. self::TYPE_SUB_WECHAT_PAY_ORDER,
  77. self::TYPE_ADD_WECHAT_PAY_ORDER_MONEY, // 中和返还微信得钱
  78. self::TYPE_ADMIN_ADD_TO_WALLET, // 中和返还余额得钱
  79. self::TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER,
  80. self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER,
  81. self::TYPE_SUB_WALLET,
  82. ];
  83. public static $addType = [
  84. // 此处为毛收益 带余额
  85. self::TYPE_ADD_WECHAT_TO_WALLET, // 充值到钱包
  86. self::TYPE_ADD_WECHAT_PAY_ORDER, // 支付订单
  87. self::TYPE_ADD_WECHAT_PAY_RENT_ORDER, // 支付日租订单
  88. self::TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY, // 【充值】微信直接支付租车超时金额
  89. self::TYPE_SUB_ORDER_MONEY_PAY_WECHAT, //订单返现 中和返现
  90. self::TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER, // 购买骑行卡
  91. self::TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER, // 购买免押金卡
  92. self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER
  93. // self::TYPE_ADMIN_ADD_TO_WALLET
  94. ];
  95. public static $typeMaps = [
  96. self::TYPE_ADD_WECHAT_TO_WALLET => '【充值】用户充值(微信)',
  97. self::TYPE_SUB_WALLET_BIKE_ORDER => '【消费】用户消费(骑车)',
  98. self::TYPE_SUB_WALLET_RENT_ORDER => '【消费】用户支付租金',
  99. self::TYPE_ADMIN_SUB_BIKE_ORDER => '【消费】用户消费(骑车,后台管理员结算)',
  100. self::TYPE_ADMIN_ADD_TO_WALLET => '【充值】后台管理员返还到平台余额',
  101. self::TYPE_ADD_WECHAT_PAY_ORDER_MONEY => '【充值】后台管理员返还到微信',
  102. self::TYPE_SUB_ORDER_MONEY_PAY_WECHAT => '【消费】后台管理员返还到微信',
  103. self::TYPE_ADD_WECHAT_PAY_PUNISHMENT_ORDER => '【充值】微信直接支付罚单',
  104. self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER => '【消费】微信直接支付罚单',
  105. self::TYPE_ADD_ADMIN_TO_WALLET => '【充值】系统充值余额',
  106. self::TYPE_SUB_WALLET_RENT_ORDER_MONEY => '【消费】用户支付租车超时金额',
  107. self::TYPE_ADD_WECHAT_PAY_ORDER => '【充值】微信直接支付订单',
  108. self::TYPE_SUB_WECHAT_PAY_ORDER => '【消费】微信直接支付订单',
  109. self::TYPE_ADD_WECHAT_PAY_RENT_ORDER => '【充值】微信直接支付租金',
  110. self::TYPE_SUB_WECHAT_PAY_RENT_ORDER => '【消费】微信直接支付租金',
  111. self::TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY => '【充值】微信直接支付租车超时金额',
  112. self::TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY => '【消费】微信直接支付租车超时金额',
  113. self::TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER => '【充值】微信支付购买骑行卡',
  114. self::TYPE_SUB_WECHAT_PAY_CARD_RIDING_ORDER => '【消费】微信支付购买骑行卡',
  115. self::TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET => '【充值】用户充值赠送(微信)',
  116. self::TYPE_ADD_INVITE_NEW_TO_WELLET => '【赠送】邀请新用户赠送',
  117. self::TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER => '【充值】微信支付购买免押金卡',
  118. self::TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER => '【消费】微信支付购买免押金卡',
  119. self::TYPE_SUB_WALLET => '【消费】平余额退到用户微信',
  120. ];
  121. public static $payTypeMaps = [
  122. self::TYPE_ADMIN_SUB_BIKE_ORDER => '余额支付(管理员结算)',
  123. self::TYPE_SUB_WALLET_BIKE_ORDER => '余额支付',
  124. self::TYPE_SUB_WECHAT_PAY_ORDER => '微信支付'
  125. ];
  126. public function users()
  127. {
  128. return $this->belongsTo(User::class, 'user_id', 'id');
  129. }
  130. public static function log($operate_type, $money, $user_id, $type, $area_id, $log_id = false, $log_type = false, $ext = false, $name = false)
  131. {
  132. if (!$name) $name = self::$typeMaps[$type];
  133. if (!$operate_type) {
  134. $money = -$money;
  135. }
  136. $data = [
  137. 'area_id' => $area_id,
  138. 'money' => $money,
  139. 'operate_type' => $operate_type,
  140. 'user_id' => $user_id,
  141. 'type' => $type,
  142. 'name' => $name,
  143. 'status' => self::STATUS_OK
  144. ];
  145. if ($log_id && $log_type) {
  146. $data['log_id'] = $log_id;
  147. $data['log_type'] = $log_type;
  148. }
  149. if ($ext) {
  150. $data['data'] = $ext;
  151. }
  152. self::create($data);
  153. if ($type < 20) {
  154. User::where('id', $user_id)->increment('wallet_money', $money);
  155. if ($type === self::TYPE_ADD_WECHAT_TO_WALLET) {
  156. // 充值
  157. User::where('id', $user_id)->increment('recharge', $money);
  158. }
  159. }
  160. }
  161. }