123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Repositories;
- use App\Models\MembersPoint;
- use Prettus\Repository\Eloquent\BaseRepository;
- use Prettus\Repository\Criteria\RequestCriteria;
- /**
- * Class MemberRepositoryEloquent.
- *
- * @package namespace App\Repositories;
- */
- class MemberPointRepository extends BaseRepository
- {
- /**
- * Specify Model class name
- *
- * @return string
- */
- public function model()
- {
- return MembersPoint::class;
- }
- /**
- * Boot up the repository, pushing criteria
- */
- 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();
- }
- /**企业会员会员积分增减记录
- * @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]);
- }
- }
- }
- }
|