123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\dao\activity\promotions;
- use app\dao\BaseDao;
- use app\model\activity\promotions\StorePromotions;
- use app\model\activity\promotions\StorePromotionsAuxiliary;
- class StorePromotionsAuxiliaryDao extends BaseDao
- {
-
- protected function setModel(): string
- {
- return StorePromotionsAuxiliary::class;
- }
- public function joinModel(): string
- {
- return StorePromotions::class;
- }
-
- public function getList(array $where = [], string $field = '*', array $with = [], int $page = 0, int $limit = 0)
- {
- return $this->search($where)->field($field)
- ->when($with, function ($query) use ($with) {
- $query->with($with);
- })->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->select()->toArray();
- }
-
- public function getJoinModel(string $alias = 'a', string $join_alias = 'p', $join = 'left')
- {
- $this->alias = $alias;
- $this->joinAlis = $join_alias;
-
- $storePromotions = app()->make($this->joinModel());
- $table = $storePromotions->getName();
- return parent::getModel()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.promotions_id = ' . $join_alias . '.id', $join);
- }
-
- public function getProductsPromotionsIds(array $product_id, int $product_partake_type = 2, string $field = '')
- {
- $time = time();
- return $this->getJoinModel()->field($field)
- ->where($this->joinAlis . '.type', 1)
- ->where($this->joinAlis . '.status', 1)
- ->where($this->joinAlis . '.is_del', 0)
- ->where($this->joinAlis . '.start_time', '<=', $time)
- ->where($this->joinAlis . '.stop_time', '>=', $time)
- ->where($this->alias . '.type', 1)
- ->when(in_array($product_partake_type, [2, 3]), function ($query) use ($product_partake_type, $product_id) {
- if ($product_partake_type == 2) {
- $query->where(function ($q) use ($product_id) {
- $q->whereOr( $this->joinAlis.'.product_partake_type', 1)
- ->whereOr(function ($w) use ($product_id) {
- $w->where($this->joinAlis.'.product_partake_type', 2)->where(function ($p) use ($product_id) {
- if (is_array($product_id)) {
- $p->whereIn($this->alias.'.product_id', $product_id);
- } else {
- $p->where($this->alias.'.product_id', $product_id);
- }
- });
- })->whereOr(function ($e) use ($product_id) {
- $e->where($this->joinAlis.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id) {
- if (is_array($product_id)) {
- $p->whereNotIn($this->alias.'.product_id', $product_id);
- } else {
- $p->where($this->alias.'.product_id', '<>', $product_id);
- }
- });
- });
- });
- } else {
- $query->where($this->alias.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id){
- if(is_array($product_id)){
- $p->whereNotIn($this->alias.'.product_id', $product_id);
- }else{
- $p->where($this->alias.'.product_id', $product_id);
- }
- });
- }
- })->select()->toArray();
- }
- }
|