123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class WalletLog extends Model
- {
- use ModelHelpers;
- protected $guarded = [];
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const OPERATE_TYPE_ADD = 1;
- const OPERATE_TYPE_SUB = 0;
- public static $operateTypeMaps = [
- self::OPERATE_TYPE_ADD => '充值',
- self::OPERATE_TYPE_SUB => '消费'
- ];
- //充值(微信)
- const TYPE_ADD_WECHAT_TO_WALLET = 0;
- //骑车消费(从余额)/////////////////////////
- const TYPE_SUB_WALLET_BIKE_ORDER = 1;
- // 后台管理员结算订单(从余额扣除)//////////////////
- const TYPE_ADMIN_SUB_BIKE_ORDER = 2;
- // 后台管理员返还(增加到钱包余额)
- const TYPE_ADMIN_ADD_TO_WALLET = 3;
- //租金消费(从余额)////////////////////////////////
- const TYPE_SUB_WALLET_RENT_ORDER = 7;
- //租车订单消费
- const TYPE_SUB_WALLET_RENT_ORDER_MONEY = 5;
- // 企业支付 退余额
- const TYPE_SUB_WALLET = 9;
- //充值(微信)
- const TYPE_ADD_ADMIN_TO_WALLET = 11;
- // 微信支付订单
- const TYPE_ADD_WECHAT_PAY_ORDER = 20;
- // 微信订单消费(直接)
- const TYPE_SUB_WECHAT_PAY_ORDER = 21;
- // 微信支付订单
- const TYPE_ADD_WECHAT_PAY_PUNISHMENT_ORDER = 22;
- // 微信订单消费(直接)
- const TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER = 23;
- //【充值】微信直接支付租金
- const TYPE_ADD_WECHAT_PAY_RENT_ORDER = 30;
- //【消费】微信直接支付租金
- const TYPE_SUB_WECHAT_PAY_RENT_ORDER = 31;
- //【充值】微信直接支付租车超时金额
- const TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY = 32;
- //【消费】微信直接支付租车超时金额
- const TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY = 33;
- //订单返现
- const TYPE_ADD_WECHAT_PAY_ORDER_MONEY = 34;
- const TYPE_SUB_ORDER_MONEY_PAY_WECHAT = 35;
- // 骑行卡
- const TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER = 40;
- const TYPE_SUB_WECHAT_PAY_CARD_RIDING_ORDER = 41;
- // 免押金卡
- const TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER = 50;
- const TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER = 51;
- //充值赠送
- const TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET = 10;
- //邀新赠送
- const TYPE_ADD_INVITE_NEW_TO_WELLET = 12;
- public static $subType = [
- // 次处为 纯收益 不带余额
- self::TYPE_SUB_WALLET_RENT_ORDER_MONEY,
- self::TYPE_SUB_WALLET_RENT_ORDER,
- self::TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY,
- self::TYPE_SUB_WECHAT_PAY_RENT_ORDER,
- self::TYPE_SUB_WALLET_BIKE_ORDER,
- self::TYPE_ADMIN_SUB_BIKE_ORDER,
- self::TYPE_SUB_WECHAT_PAY_ORDER,
- self::TYPE_ADD_WECHAT_PAY_ORDER_MONEY, // 中和返还微信得钱
- self::TYPE_ADMIN_ADD_TO_WALLET, // 中和返还余额得钱
- self::TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER,
- self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER,
- self::TYPE_SUB_WALLET,
- ];
- public static $addType = [
- // 此处为毛收益 带余额
- self::TYPE_ADD_WECHAT_TO_WALLET, // 充值到钱包
- self::TYPE_ADD_WECHAT_PAY_ORDER, // 支付订单
- self::TYPE_ADD_WECHAT_PAY_RENT_ORDER, // 支付日租订单
- self::TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY, // 【充值】微信直接支付租车超时金额
- self::TYPE_SUB_ORDER_MONEY_PAY_WECHAT, //订单返现 中和返现
- self::TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER, // 购买骑行卡
- self::TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER, // 购买免押金卡
- self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER
- // self::TYPE_ADMIN_ADD_TO_WALLET
- ];
- public static $typeMaps = [
- self::TYPE_ADD_WECHAT_TO_WALLET => '【充值】用户充值(微信)',
- self::TYPE_SUB_WALLET_BIKE_ORDER => '【消费】用户消费(骑车)',
- self::TYPE_SUB_WALLET_RENT_ORDER => '【消费】用户支付租金',
- self::TYPE_ADMIN_SUB_BIKE_ORDER => '【消费】用户消费(骑车,后台管理员结算)',
- self::TYPE_ADMIN_ADD_TO_WALLET => '【充值】后台管理员返还到平台余额',
- self::TYPE_ADD_WECHAT_PAY_ORDER_MONEY => '【充值】后台管理员返还到微信',
- self::TYPE_SUB_ORDER_MONEY_PAY_WECHAT => '【消费】后台管理员返还到微信',
- self::TYPE_ADD_WECHAT_PAY_PUNISHMENT_ORDER => '【充值】微信直接支付罚单',
- self::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER => '【消费】微信直接支付罚单',
- self::TYPE_ADD_ADMIN_TO_WALLET => '【充值】系统充值余额',
- self::TYPE_SUB_WALLET_RENT_ORDER_MONEY => '【消费】用户支付租车超时金额',
- self::TYPE_ADD_WECHAT_PAY_ORDER => '【充值】微信直接支付订单',
- self::TYPE_SUB_WECHAT_PAY_ORDER => '【消费】微信直接支付订单',
- self::TYPE_ADD_WECHAT_PAY_RENT_ORDER => '【充值】微信直接支付租金',
- self::TYPE_SUB_WECHAT_PAY_RENT_ORDER => '【消费】微信直接支付租金',
- self::TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY => '【充值】微信直接支付租车超时金额',
- self::TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY => '【消费】微信直接支付租车超时金额',
- self::TYPE_ADD_WECHAT_PAY_CARD_RIDING_ORDER => '【充值】微信支付购买骑行卡',
- self::TYPE_SUB_WECHAT_PAY_CARD_RIDING_ORDER => '【消费】微信支付购买骑行卡',
- self::TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET => '【充值】用户充值赠送(微信)',
- self::TYPE_ADD_INVITE_NEW_TO_WELLET => '【赠送】邀请新用户赠送',
- self::TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER => '【充值】微信支付购买免押金卡',
- self::TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER => '【消费】微信支付购买免押金卡',
- self::TYPE_SUB_WALLET => '【消费】平余额退到用户微信',
- ];
- public static $payTypeMaps = [
- self::TYPE_ADMIN_SUB_BIKE_ORDER => '余额支付(管理员结算)',
- self::TYPE_SUB_WALLET_BIKE_ORDER => '余额支付',
- self::TYPE_SUB_WECHAT_PAY_ORDER => '微信支付'
- ];
- public function users()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
- public static function log($operate_type, $money, $user_id, $type, $area_id, $log_id = false, $log_type = false, $ext = false, $name = false)
- {
- if (!$name) $name = self::$typeMaps[$type];
- if (!$operate_type) {
- $money = -$money;
- }
- $data = [
- 'area_id' => $area_id,
- 'money' => $money,
- 'operate_type' => $operate_type,
- 'user_id' => $user_id,
- 'type' => $type,
- 'name' => $name,
- 'status' => self::STATUS_OK
- ];
- if ($log_id && $log_type) {
- $data['log_id'] = $log_id;
- $data['log_type'] = $log_type;
- }
- if ($ext) {
- $data['data'] = $ext;
- }
- self::create($data);
- if ($type < 20) {
- User::where('id', $user_id)->increment('wallet_money', $money);
- if ($type === self::TYPE_ADD_WECHAT_TO_WALLET) {
- // 充值
- User::where('id', $user_id)->increment('recharge', $money);
- }
- }
- }
- }
|