123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Repositories;
- use App\Models\MembersPoint;
- use Prettus\Repository\Eloquent\BaseRepository;
- use Prettus\Repository\Criteria\RequestCriteria;
- class MemberPointRepository extends BaseRepository
- {
-
- public function model()
- {
- return MembersPoint::class;
- }
-
- public function boot()
- {
- $this->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();
- }
-
- public function getComPointsById($uid, $utype)
- {
- return $this->with('getMembersHandsel')->model->where(['uid'=>$uid,'utype'=>$utype])->first();
- }
-
- 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);
- }
-
- 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]);
- }
- }
- }
- }
|