pushCriteria(app(RequestCriteria::class)); } public function getPointsById($uid, $utype) { return $this->model->where(['uid'=>$uid,'utype'=>$utype])->first(); } public function getTaskById($uid, $utype) { return $this->with('taskLogs')->model->where(['uid'=>$uid,'utype'=>$utype])->first()->toArray(); } /**企业会员会员积分增减记录 * @param $uid * @param $utype * @return mixed */ public function getComPointsById($uid, $utype) { return $this->with('getMembersHandsel')->model->where(['uid'=>$uid,'utype'=>$utype])->first(); } /**企业会员points * @param $uid * @return mixed */ public function getComTaskById($uid) { return $this->with('taskLogs')->model->where(['uid'=>$uid])->first()->toArray(); } public function getPointsOne($uid, $utype) { return $this->model->where(['uid'=>$uid, 'utype'=>$utype])->first(); } public function addNew($data) { return $this->model->create($data); } public function updateNew($uid, $utype, $data) { return $this->model->where(['uid'=>$uid, 'utype'=>$utype])->update($data); } /** * @param $uid * @param int $i_type 1增加 2减少 * @param int $points * @return mixed */ public function reportDeal($uid, $utype, $i_type = 1, $points = 0) { $userpoints = $this->getPointsOne($uid, $utype); if (!$userpoints) { $userpoints = 0; $this->addNew(['uid'=>$uid,'utype'=>$utype, 'points'=>0]); } if ($i_type==1) { return $this->model->where(['uid'=>$uid,'utype'=>$utype])->increment('points', $points); } if ($i_type==2) { if ($userpoints['points']>$points) { return $this->model->where(['uid'=>$uid,'utype'=>$utype])->decrement('points', $points); } else { return $this->model->where(['uid'=>$uid,'utype'=>$utype])->update(['points'=>0]); } } } }