123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\dao\activity\coupon;
- use app\dao\BaseDao;
- use app\model\activity\coupon\StoreCoupon;
- use app\model\activity\coupon\StoreCouponUser;
- class StoreCouponUserCouponDao extends BaseDao
- {
-
- protected $alias = 'a';
-
- protected $joinAlis = 'b';
-
- public function setModel(): string
- {
- return StoreCouponUser::class;
- }
-
- public function setJoinModel(): string
- {
- return StoreCoupon::class;
- }
-
- public function getModel()
- {
-
- $joinModel = app()->make($this->setJoinModel());
- $name = $joinModel->getName();
- return parent::getModel()->alias($this->alias)->join($name . ' ' . $this->joinAlis, $this->joinAlis . '.id=' . $this->alias . '.cid');
- }
-
- public function getUidCouponList(int $uid, string $truePrice, int $productId)
- {
- return $this->getModel()
- ->where($this->alias . '.uid', $uid)
- ->where($this->alias . '.is_fail', 0)
- ->where($this->alias . '.status', 0)
- ->where($this->alias . '.use_min_price', '<=', $truePrice)
- ->whereFindinSet($this->joinAlis . '.product_id', $productId)
- ->where($this->joinAlis . '.type', 2)
- ->field($this->alias . '.*,' . $this->joinAlis . '.type')
- ->order($this->alias . '.coupon_price', 'DESC')
- ->select()
- ->hidden(['status', 'is_fail'])
- ->toArray();
- }
-
- public function getUidCouponMinList($uid, $price, $value = '', int $type = 1)
- {
- return $this->getModel()->where($this->alias . '.uid', $uid)
- ->where($this->alias . '.is_fail', 0)
- ->where($this->alias . '.status', 0)
- ->where($this->alias . '.use_min_price', '<=', $price)
- ->when($value, function ($query) use ($value) {
- $query->whereFindinSet($this->joinAlis . '.category_id', $value);
- })
- ->where($this->joinAlis . '.type', $type)
- ->field($this->alias . '.*,' . $this->joinAlis . '.type')
- ->order($this->alias . '.coupon_price', 'DESC')
- ->select()
- ->hidden(['status', 'is_fail'])
- ->toArray();
- }
- }
|