| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/3/27
- * Time: 下午1:52
- */
- namespace app\common\models;
- use app\common\observers\income\IncomeObserver;
- /**
- * @property int status
- * @property float amount
- * @property string incometable_type
- *
- * Class Income
- * @package app\common\models
- */
- class Income extends BaseModel
- {
- protected $table = 'yz_member_income';
- protected $guarded = [''];
- protected $appends = ['status_name', 'pay_status_name'];
- /**
- * @var Withdraw withdraw
- */
- private $withdraw;
- /**
- * 提现状态:未提现
- */
- const STATUS_INITIAL = 0;
- /**
- * 提现状态:已提现
- */
- const STATUS_WITHDRAW = 1;
- /**
- * 打款状态:无效
- */
- const PAY_STATUS_INVALID = -1;
- /**
- * 打款状态:未审核
- */
- const PAY_STATUS_INITIAL = 0;
- /**
- * 打款状态:未打款
- */
- const PAY_STATUS_WAIT = 1;
- /**
- * 打款状态:已打款
- */
- const PAY_STATUS_FINISH = 2;
- /**
- * 打款状态:已驳回
- */
- const PAY_STATUS_REJECT = 3;
- /**
- * 分帐插件使用,['order_id' => '', 'mark' => '']
- *
- * @var array
- */
- public $separate = [];
- /**
- * 提现状态名称集合
- *
- * @var array
- */
- public static $statusComment = [
- self::STATUS_INITIAL => '未提现',
- self::STATUS_WITHDRAW => '已提现',
- ];
- /**
- * 打款状态名称集合
- *
- * @var array
- */
- public static $payStatusComment = [
- self::PAY_STATUS_INVALID => '无效',
- self::PAY_STATUS_INITIAL => '未审核',
- self::PAY_STATUS_WAIT => '未打款',
- self::PAY_STATUS_FINISH => '已打款',
- self::PAY_STATUS_REJECT => '已驳回',
- ];
- public static function boot()
- {
- parent::boot();
- self::observe(IncomeObserver::class);
- }
- /**
- * 通过 $status 值获取 $status 名称
- *
- * @param $status
- * @return mixed|string
- */
- public static function getStatusComment($status)
- {
- return isset(static::$statusComment[$status]) ? static::$statusComment[$status] : '';
- }
- /**
- * 通过 $pay_way 值获取 $pay_status 名称
- *
- * @param $pay_status
- * @return mixed|string
- */
- public static function getPayWayComment($pay_status)
- {
- return isset(static::$payStatusComment[$pay_status]) ? static::$payStatusComment[$pay_status] : '';
- }
- /**
- * 通过字段 status 输出 status_name ;
- *
- * @return string
- */
- public function getStatusNameAttribute()
- {
- return static::getStatusComment($this->attributes['status']);
- }
- /**
- * 通过字段 pay_status 输出 pay_status_name ;
- *
- * @return string
- */
- public function getPayStatusNameAttribute()
- {
- return static::getPayWayComment($this->attributes['pay_status']);
- }
- /**
- * 可提现收入检索条件
- *
- * @param $query
- * @return mixed
- */
- public function scopeCanWithdraw($query)
- {
- return $query->where('status', static::STATUS_INITIAL);
- }
- /**
- * 关联会员数据表
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function member()
- {
- return $this->belongsTo('app\common\models\Member', 'member_id', 'uid');
- }
- //todo 以下代码未检查 yitian :: 2017-11-14
- /**
- * @param $id
- * @return mixed
- */
- public static function getIncomeFindId($id)
- {
- return self::find($id);
- }
- /**
- * @param $id
- * @return mixed
- */
- public static function getIncomeById($id)
- {
- return self::uniacid()
- ->where('id', $id);
- }
- /**
- * @param $ids
- * @return mixed
- */
- public static function getIncomeByIds($ids)
- {
- return self::uniacid()
- ->whereIn('id', explode(',', $ids));
- }
- public function incometable()
- {
- return $this->morphTo();
- }
- /**
- * @return mixed
- */
- public static function getIncomes()
- {
- return self::uniacid();
- }
- public static function getIncomeInMonth($search)
- {
- $model = self::select('create_month');
- $model->uniacid();
- $model->with(['hasManyIncome' => function ($query) use ($search) {
- $query->select('id', 'create_month', 'incometable_type', 'type_name', 'amount', 'created_at');
- if ($search['type']) {
- $query->where('incometable_type', $search['type']);
- }
- $query->where('member_id', \YunShop::app()->getMemberId());
- $query->orderBy('id', 'desc');
- return $query->get();
- }]);
- $model->groupBy('create_month');
- $model->orderBy('create_month', 'desc');
- return $model;
- }
- public static function getDetailById($id)
- {
- $model = self::uniacid();
- $model->select('detail');
- $model->where('id', $id);
- return $model;
- }
- public static function getWithdraw($type, $typeId, $status)
- {
- return self::where('type', 'commission')
- ->where('member_id', \YunShop::app()->getMemberId())
- ->whereIn('id', explode(',', $typeId))
- ->update(['status' => $status]);
- }
- public static function updatedWithdraw($type, $typeId, $status)
- {
- return self::where('member_id', \YunShop::app()->getMemberId())
- ->whereIn('id', explode(',', $typeId))
- ->update(['status' => $status]);
- }
- public static function updatedIncomeStatus($type, $typeId, $status)
- {
- return self::where('member_id', \YunShop::app()->getMemberId())
- ->whereIn('id', explode(',', $typeId))
- ->update(['status' => $status]);
- }
- public function hasManyIncome()
- {
- return $this->hasMany(self::class, "create_month", "create_month");
- }
- public function hasManyOrder()
- {
- return $this->hasOne(Order::class, "order_sn", "order_sn");
- }
- public static function updatedIncomePayStatus($id, $updatedData)
- {
- return self::where('id', $id)
- ->update($updatedData);
- }
- public static function getIncomesList($search)
- {
- if($search['select']){
- $selects = ['id', 'create_month', 'incometable_type', 'type_name', 'amount', 'created_at','detail','incometable_id'];
- }else{
- $selects = ['id', 'create_month', 'incometable_type', 'type_name', 'amount', 'created_at'];
- }
- $model = self::uniacid();
- $model->select($selects);
- if ($search['type']) {
- $model->where('incometable_type', $search['type']);
- }
- $model->where('member_id', \YunShop::app()->getMemberId());
- $model->orderBy('id', 'desc');
- return $model;
- }
-
- /**
- * @return Withdraw
- */
- public function withdraw()
- {
- if (!isset($this->withdraw)) {
- $this->withdraw = Withdraw::where('type_id', 'like', "%{$this->id}%")->where('type', $this->incometable_type)->first();
- }
- return $this->withdraw;
- }
- }
|