123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace app\common\dao\store;
- use app\common\model\store\StoreSeckillActive;
- use app\common\dao\BaseDao;
- use app\common\repositories\store\product\SpuRepository;
- class StoreSeckillActiveDao extends BaseDao
- {
-
- protected function getModel(): string
- {
- return StoreSeckillActive::class;
- }
-
- public function search(array $where)
- {
- $query = $this->getModel()::getDB()
- ->when(isset($where['status']) && $where['status'] !== '',function($query) use($where){
- $query->where('status',$where['status']);
- })
- ->when(isset($where['start_day']) && $where['start_day'] !== '',function($query) use($where){
- $query->whereTime('start_day','<=',$where['start_day']);
- })
- ->when(isset($where['end_day']) && $where['end_day'] !== '',function($query) use($where){
- $query->whereTime('end_day','>',$where['end_day']);
- })
- ->when(isset($where['start_time']) && $where['start_time'] !== '',function($query) use($where){
- $query->whereTime('start_time','<=',$where['start_time']);
- })
- ->when(isset($where['end_time']) && $where['end_time'] !== '',function($query) use($where){
- $query ->whereTime('end_time','>',$where['end_time']);
- })
- ->when(isset($where['product_id']) && $where['product_id'] !== '',function($query) use($where){
- $query->where('product_id',$where['product_id']);
- })
- ->when(isset($where['day']) && $where['day'] !== '',function($query) use($where){
- $query->whereTime('start_day','<=',$where['day'])->whereTime('end_day','>',$where['day']);
- })
- ->when(isset($where['time']) && $where['time'] !== '',function($query) use($where){
- $query->whereTime('start_time','<=',$where['time'])->whereTime('end_time','>',$where['time']);
- });
- $query->order('start_time DESC');
- return $query;
- }
-
- public function updateByProduct(int $productId,array $data)
- {
- return $this->getModel()::getDB()->where('product_id',$productId)->update($data);
- }
-
- public function valActiveStatus()
- {
- $day = date('Y-m-d',time());
- $_h = date('H',time());
- $id = $this->getModel()::getDB()->where('status',1)
- ->whereTime('end_day','<=',$day)
- ->whereTime('end_time','<',$_h)
- ->column('seckill_active_id');
- if($id) {
- $this->getModel()::getDB()->where('seckill_active_id', 'in', $id)->update(['status' => -1]);
- $where = [
- 'product_type' => 1,
- 'activity_ids' => $id
- ];
- app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
- }
- }
-
- public function getStatus($status)
- {
- $day = date('Y-m-d',time());
- $_h = date('H',time());
- $query = $this->getModel()::getDB();
- if($status == 1)
- $query->where('status','<>',-1)->where(function($query)use ($day,$_h){
- $query->whereTime('start_day','>',$day)->whereOr(function($query)use($day,$_h){
- $query->whereTime('start_day','<=',$day)->where('start_time','>',$_h);
- });
- });
- if($status == 2)
- $query->where('status',1)
- ->whereTime('start_day','<=',$day)->whereTime('end_day','>',$day)
- ->where('start_time','<=',$_h)->where('end_time','>',$_h);
- if($status == 3)
- $query->where('status',-1)->whereOr(function($query)use($day,$_h){
- $query->whereTime('end_day','<',$day)
- ->whereOr(function($query)use($day,$_h){
- $query->whereTime('start_day','<=',$day)->whereTime('end_day','>=',$day)->where('end_time','<=',$_h);
- });
- });
- return $query;
- }
- }
|