12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- class RechargeOrder extends Model
- {
- protected $guarded = [];
- const NO_TAG = 'C';
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const PAY_STATUS_OK = 1;
- const PAY_STATUS_NO = 0;
- public static $payStatusMaps = [
- self::PAY_STATUS_NO => '已支付',
- self::PAY_STATUS_OK => '未支付'
- ];
- const PAY_TYPE_NO = 0;
- const PAY_TYPE_WECHAT = 1;
- const PAY_TYPE_SYSTERM = 2;
- public static $payTypeMaps = [
- self::PAY_TYPE_NO => '待支付',
- self::PAY_TYPE_WECHAT => '微信支付',
- self::PAY_TYPE_SYSTERM => '系统赠送',
- ];
- /**
- * 生成订单号
- * @return bool|string
- * User: Mead
- */
- public static function makeNo()
- {
- // 订单流水号前缀
- $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
- for ($i = 0; $i < 10; $i++) {
- // 随机生成 6 位的数字
- $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
- // 判断是否已经存在
- if (!static::query()->where('no', $no)->exists()) {
- return $no;
- }
- }
- Log::warning('find order no failed');
- return false;
- }
- /**
- * 充值成功回调
- * @return bool
- * User: Mead
- */
- public function pay_order_callback()
- {
- // 修改用户钱包
- WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['recharge_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_TO_WALLET, $this->attributes['area_id'], $this->attributes['id'], RechargeOrder::class);
- $config = js2php($this->attributes['recharge_config']);
- if (count($config) !== 0) {
- //检查用户是否满足充值赠送活动
- WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $config['give_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET, $this->attributes['area_id'], $this->attributes['id'], RechargeOrder::class);
- }
- return true;
- }
- }
|