123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- declare (strict_types=1);
- namespace app\dao\activity\bargain;
- use app\dao\BaseDao;
- use app\model\activity\bargain\StoreBargain;
- class StoreBargainDao extends BaseDao
- {
-
- protected function setModel(): string
- {
- return StoreBargain::class;
- }
-
- public function search(array $where = [])
- {
- return parent::search($where)
- ->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
- $time = time();
- switch ($where['start_status']) {
- case -1:
- $query->where('stop_time', '<', $time);
- break;
- case 0:
- $query->where('start_time', '>', $time);
- break;
- case 1:
- $query->where('start_time', '<=', $time)->where('stop_time', '>=', $time);
- break;
- }
- });
- }
-
- public function getList(array $where, int $page = 0, int $limit = 0)
- {
- return $this->search($where)->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->order('sort desc,id desc')->select()->toArray();
- }
-
- public function getBargainIdsArray(array $ids, array $field = [])
- {
- return $this->search(['is_del' => 0, 'status' => 1])->where('start_time', '<=', time())
- ->where('stop_time', '>=', time())->whereIn('product_id', $ids)->column(implode(',', $field), 'product_id');
- }
-
- public function idByBargainList(array $ids, string $field)
- {
- return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
- }
-
- public function validWhere(int $status = 1)
- {
- return $this->getModel()->where('is_del', 0)->where('status', $status)->where('start_time', '<', time())->where('stop_time', '>', time());
- }
-
- public function bargainList(int $page = 0, int $limit = 0)
- {
- return $this->search(['is_del' => 0, 'status' => 1])
- ->where('start_time', '<=', time())
- ->where('stop_time', '>=', time())
- ->where('product_id', 'IN', function ($query) {
- $query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
- })->with('product')->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->order('sort DESC,id DESC')->select()->toArray();
- }
-
- public function addBargain(int $id, string $field)
- {
- return $this->getModel()->where('id', $id)->inc($field, 1)->update();
- }
- }
|