TakeCash.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model;
  3. use app\service\pay_user\PayUserWechat;
  4. use think\Model;
  5. /**
  6. *@property
  7. */
  8. class TakeCash extends Model
  9. {
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = true;
  12. // 定义时间戳字段名
  13. protected $createTime = 'created_at';
  14. protected $updateTime = 'updated_at';
  15. // 追加属性
  16. protected $append = [
  17. ];
  18. const STATUS_APPLY=0;
  19. const STATUS_PASS=1;
  20. const STATUS_REJECT=2;
  21. public static $statusList=[
  22. self::STATUS_APPLY=>'审核中',
  23. self::STATUS_PASS=>'已通过',
  24. self::STATUS_REJECT=>'已拒绝',
  25. ];
  26. public function audit($status){
  27. empty(self::$statusList[$status]) && throw_user('状态有误');
  28. $this['status']=$status;
  29. $user=$this->user;
  30. if($status==self::STATUS_REJECT){
  31. $user::money($this['amount'],$user['id'],MoneyLog::TYPE_TAKECASH_REJECT,'提现不通过');
  32. }elseif ($status==self::STATUS_PASS){
  33. (new PayUserWechat())->payment($this['amount'],$user,MoneyLog::TYPE_TAKECASH,'提现',[],false);
  34. }
  35. if(!$this->save()){
  36. throw_user('保存失败');
  37. }
  38. }
  39. public function user()
  40. {
  41. return $this->belongsTo(User::class)->removeOption('soft_delete');
  42. }
  43. }