123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\admin\model\ump;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use app\admin\model\order\StoreOrder;
- class StorePink extends BaseModel
- {
-
- protected $pk = 'id';
-
- protected $name = 'store_pink';
- use ModelTrait;
-
- public static function systemPage($where){
- $model = new self;
- $model = $model->alias('p');
- $model = $model->field('p.*,c.title,u.nickname,u.avatar');
- if($where['data'] !== ''){
- list($startTime,$endTime) = explode(' - ',$where['data']);
- $model = $model->where('p.add_time','>',strtotime($startTime));
- $model = $model->where('p.add_time','<',strtotime($endTime));
- }
- if($where['status']) $model = $model->where('p.status',$where['status']);
- $model = $model->where('p.k_id',0);
- $model = $model->order('p.id desc');
- $model = $model->join('store_combination c','c.id=p.cid');
- $model = $model->join('user u','u.uid = p.uid');
- return self::page($model,function($item)use($where){
- $item['count_people'] = bcadd(self::where('k_id',$item['id'])->count(),1,0);
- },$where);
- }
-
- public static function getCountPeopleAll($combinationId = 0){
- if(!$combinationId) return self::count();
- return self::where('cid',$combinationId)->count();
- }
-
- public static function getCountPeoplePink($combinationId = 0){
- if(!$combinationId) return self::where('k_id',0)->count();
- return self::where('cid',$combinationId)->where('k_id',0)->count();
- }
-
- public static function getPinkUserOne($id){
- $model = new self();
- $model = $model->alias('p');
- $model = $model->field('p.*,u.nickname,u.avatar');
- $model = $model->where('id',$id);
- $model = $model->join('user u','u.uid = p.uid');
- $list = $model->find();
- if($list) return $list->toArray();
- else return [];
- }
-
- public static function getPinkMember($id){
- $model = new self();
- $model = $model->alias('p');
- $model = $model->field('p.*,u.nickname,u.avatar');
- $model = $model->where('k_id',$id);
- $model = $model->where('is_refund',0);
- $model = $model->join('user u','u.uid = p.uid');
- $model = $model->order('id asc');
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- public static function setRefundPink($oid){
- $res = true;
- $order = StoreOrder::where('id',$oid)->find();
- if($order['pink_id']) $id = $order['pink_id'];
- else return $res;
- $count = self::where('id',$id)->where('uid',$order['uid'])->find();
- $countY = self::where('k_id',$id)->where('uid',$order['uid'])->find();
- if(!$count && !$countY) return $res;
- if($count){
-
- $kCount = self::where('k_id',$id)->order('add_time asc')->find();
- if($kCount){
- $res11 = self::where('k_id',$id)->update(['k_id'=>$kCount['id']]);
- $res12 = self::where('id',$kCount['id'])->update(['stop_time'=>$count['add_time']+86400,'k_id'=>0]);
- $res1 = $res11 && $res12;
- $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$kCount['id'],'status'=>3]);
- }else{
- $res1 = true;
- $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
- }
-
- $res = $res1 && $res2;
- }else if($countY){
- $res = self::where('id',$countY['id'])->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
- }
- return $res;
- }
- }
|