validActivity($goodsId); if($list){ return ['preview_url'=>$list->preview_url??'', 'end_time'=>$list->end_time, 'activity_id'=>$list->id, 'ts_end'=>strtotime($list->end_time)-time(), 'share_title'=>$list['share_title'], 'name'=>$list['name'], 'za_goods_id'=>$list['za_goods_id'], 'expire_day'=>$list->expire_day, 'goods_name'=>$list->goods_name, 'goods_id'=>$list->goods_id??0 ]; } return null; } /** * 获取列表 * @param $goodsId * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function validActivity($goodsId) { // 检索查询条件 $now = date('Y-m-d H:i:s'); $filter[] = ['ac.start_time','<',$now]; $filter[] = ['ac.end_time','>',$now]; $filter[] = ['ac.audit_status','=',1]; $filter[] = ['ac.is_up','=',1]; $filter[] = ['g.goods_id','=',$goodsId]; // 执行查询 $one = self::field('ac.*,g.goods_name,g.preview_url,g.id as za_goods_id,g.goods_id as goods_id') ->with([]) ->alias('ac') ->leftJoin('za_activity_goods g','g.za_activity_id = ac.id') ->where($filter) ->find(); return $one; } // protected $name = 'za_activity'; // protected $append = ['status','image']; // public function getImageAttr(){ // $a = UploadFile::field('file_id,file_type,storage,domain,file_path')->find($this->image_up_id)->ali_url??''; // $b = UploadFile::field('file_id,file_type,storage,domain,file_path')->find($this->image_down_id)->ali_url??''; // return [$a,$b]; // } // public function imageshare(){ // return $this->hasOne('app\common\model\UploadFile', 'file_id', 'image_share_id'); // } // public function imageup(){ // return $this->hasOne('app\common\model\UploadFile', 'file_id', 'image_up_id'); // } // public function imagedown(){ // return $this->hasOne('app\common\model\UploadFile', 'file_id', 'image_down_id'); // } // public static function getCurrent(){ // $now = Date("Y-m-d H:i:s",time()); // // $filter['audit_status_zg'] = 10; // $filter['is_up'] = 1; // $one = ZaActivity::where('start_time','<',$now)->where('end_time','>',$now)->where($filter)->find(); // if($one){ // return $one; // }else{ // $one = ZaActivity::find(); // return $one; // } // return false; // } // /** // * 一对多关联商品表 // */ // public function goods(){ // return $this->hasMany('MsActivityGood', 'ms_activity_id')->order('is_end','asc')->order('start_time', 'asc'); // } // /** // * 一对多关联商品表 // */ // public function imagelist(){ // return $this->hasMany('MsActivityImage', 'ms_activity_id')->order('id', 'desc'); // } // /** // * 作废 // * @param array $data // * @return bool // */ // public function down(array $data): bool { // $this->transaction(function () use ($data) { // $id = (int)$this['id']; // $this->save($data); // }); // return true; // } // //获取秒杀价 // public function getMsPrice($goods_id,$goods_price_min){ // $now = Date("Y-m-d H:i:s",time()); // $filter[] = ['activity.start_time','<=',date('Y-m-d H:i:s')]; // $filter[] = ['activity.end_time','>=',date('Y-m-d H:i:s')]; // $filter[] = ['activity.is_up','=',1]; // $filter[] = ['activity.audit_status','=',1]; // $filter[] = ['ms_activity_goods.goods_id','=',$goods_id]; // $filter[] = ['ms_activity_goods.end_time','>',$now]; // $goods = $this->field('ms_activity_goods.*')->alias('activity')->leftjoin('ms_activity_goods','ms_activity_goods.ms_activity_id=activity.id')->where($filter)->find(); // $type = 0; // if($goods){ // $now = date("Y-m-d H:i:s",time()); // if ($now < $goods->start_time) { // $d = Date("d",time()); // // 2022-01-01 15:00:00; // if($d==substr($goods->start_time,8,2)){ // $type = 1; // $text = substr($goods->start_time,11,5).'开始秒杀'; // }else{ // $type = 2; // $text = Date('Y-m-d H:i',strtotime($goods->start_time)).'开始秒杀'; // } // } // if ($now > $goods->end_time) { // $type = 3; // $text = '秒杀结束'; // } // if($now>$goods->start_time&&$now<$goods->end_time){ // $type = 4; // $text = '限时秒杀'; // } // $data['ms_price'] = $goods->ms_price; //秒杀价 // $data['type'] = $type; //类型 1 当天开始秒杀,2 某天某时开始秒杀 4秒杀中 // $data['text'] = $text; //文字 // $data['dif_end_time'] = strtotime($goods->end_time) - time(); // $data['limit_mount'] = $goods->limit_mount; // $data['stock_num'] = $goods->stock_num; // $data['ms_id'] = $goods->id; // $data['start_time'] = substr($goods->start_time,0,16); // $data['zj_price'] = helper::bcsub($goods_price_min - $goods->ms_price,0,2); // $data['ms_activity_id'] = $goods->ms_activity_id; // return $data; // } // return null ; // } // /** // * 获取列表 // * @param array $param // * @return \think\Paginator // * @throws \think\db\exception\DbException // */ // public function getList($param = []) // { // // 检索查询砍价列表 // $filter = $this->getFilter($param); // // 排序条件 // // $sort = $this->setQuerySort($param); // $sort = ['activity.id'=>'desc']; // // 查询列表数据 // $param['status'] = $param['status']??-1; // // // $list = $this->field('activity.*')->alias('activity')->leftjoin('ms_activity_goods','ms_activity_goods.ms_activity_id=activity.id')->where($filter)->with(['goods'])->group('activity.id')->order($sort)->paginate(15)->each(function($item) { // $item['good_cnt'] = count($item['goods']); // $sale_cnt = 0; // foreach($item['goods'] as $k){ // $sale_cnt = $sale_cnt + $k['sale_num']; // } // $item['sale_cnt'] = $sale_cnt; // }); // return $list ; // } // /** // * 检索查询条件 // * @param array $param // * @return array // */ // private function getFilter($param = []) // { // // 默认查询条件 // $params = $this->setQueryDefaultValue($param, ['goods_name'=>'','audit_status'=>-1,'status'=>-1]); // // 检索查询条件 // $filter = []; // if(isset($params['audit_status']) && $params['audit_status']>-1){ // $filter[] = ['audit_status', '=', $params['audit_status']]; // } // if(isset($params['goods_name']) && !empty($params['goods_name'])){ // $filter[] = ['ms_activity_goods.goods_name', 'like','%'.$params['goods_name'].'%']; // } // if (!empty($params['betweenTime'])) { // $times = between_time_format($params['betweenTime']); // $filter[] = ['activity.start_time', '>=', Date('Y-m-d H:i:s',$times['start_time'])]; // $filter[] = ['activity.end_time', '<', Date('Y-m-d H:i:s',$times['end_time'])]; // } // //活动状态 // if(isset($params['status'])&&$params['status']>-1){ // switch ($params['status']){ // case 1://进行中 // $filter[] = ['activity.start_time','<=',date('Y-m-d H:i:s')]; // $filter[] = ['activity.end_time','>=',date('Y-m-d H:i:s')]; // // $filter[] = ['audit_status_zg','=',10]; // // $filter[] = ['is_up','=',1]; // // $filter[] = ['audit_status_zg','=',10]; // break; // case 2://未开始 // $filter[] = ['activity.start_time','>',date('Y-m-d H:i:s')]; // // $filter[] = ['is_up','=',1]; // // $filter[] = ['audit_status_zg','=',10]; // break; // case 3://已结束 // // $filter[] = ['end_time','<',date('Y-m-d H:i:s')]; // // $filter[] = ['is_up','in',[0,1]]; // $filter[] = ['activity.end_time','<',date('Y-m-d H:i:s')]; // break; // } // } // return $filter; // } // //活动状态 即将开始或已结束 // public function getStatusAttr() { // $now = date("Y-m-d H:i:s",time()); // if($this->is_up==0){ // return 4; // } // if ($now < $this->start_time) { // return 2; // } // if ($now > $this->end_time) { // return 3; // } // if($now>$this->start_time&&$now<$this->end_time){ // return 1; // } // return 0; // } // /** // * 审核 // * @param array $data // * @return bool // */ // public function audit(array $data): bool // { // $this->transaction(function () use ($data) { // $user = StoreUserService::getLoginInfo(); // $real_name = $user['user']['real_name']??''; // $id = (int)$this['id']; // $this->save($data); // $id = (int)$this['id']; // if($data['audit_status']==1){ // (new CommonHis())->add(3, $id, $real_name,'同意并发布活动'); // } // if($data['audit_status']==2){ // $remark = '不同意'." ".$data['audit_reason']; // (new CommonHis())->add(3, $id, $real_name,$remark); // } // }); // return true; // } // /** // * 详情 // * @param int $id // * @return null|static // */ // public static function detail(int $id,array $with=[]) // { // return self::get($id,$with); // } // /** // * 添加 // * @param $data // * @return false|int // */ // public function addOne($data) // { // $times = between_time_format($data['between_time']); // $data['start_time'] = Date('Y-m-d H:i:s',$times['start_time']); // $data['end_time'] = Date('Y-m-d H:i:s',$times['end_time']); // isset($data['start_time']) && empty($data['start_time']) && $data['start_time'] = null; // isset($data['end_time']) && empty($data['end_time']) && $data['end_time'] = null; // $this->transaction(function () use ($data) { // $this->save($data); // if(isset($data['goods'])){ // $goods = new MsActivityGoodModel; // $flag = $goods->add($this->id,$data['goods']); // if(!$flag){ // $this->error = $goods->error; // Db::rollback(); // return false; // } // } // if(isset($data['images'])){ // $images = new MsActivityImageModel; // $flag = $images->add($this->id,$data['images']); // if(!$flag){ // $this->error = $images->error; // Db::rollback(); // return false; // } // } // $user = StoreUserService::getLoginInfo(); // $real_name = $user['user']['real_name']??''; // $id = (int)$this['id']; // (new CommonHis())->add(3, $id, $real_name,'提交审核'); // }); // return true; // } // /** // * 编辑 // * @param $data // * @return bool|int // */ // public function edit($data) // { // $times = between_time_format($data['between_time']); // $data['start_time'] = Date('Y-m-d H:i:s',$times['start_time']); // $data['end_time'] = Date('Y-m-d H:i:s',$times['end_time']); // isset($data['start_time']) && empty($data['start_time']) && $data['start_time'] = null; // isset($data['end_time']) && empty($data['end_time']) && $data['end_time'] = null; // $this->transaction(function () use ($data) { // $this->save($data); // if(isset($data['goods'])){ // $goods = new MsActivityGoodModel; // $flag = $goods->add($this->id,$data['goods']); // if(!$flag){ // $this->error = $goods->error; // Db::rollback(); // return false; // } // } // if(isset($data['images'])){ // $images = new MsActivityImageModel; // $flag = $images->add($this->id,$data['images']); // if(!$flag){ // $this->error = $images->error; // Db::rollback(); // return false; // } // } // $user = StoreUserService::getLoginInfo(); // $real_name = $user['user']['real_name']??''; // $id = (int)$this['id']; // (new CommonHis())->add(3, $id, $real_name,'再次编辑'); // }); // return true; // } // /** // * 关联记录 // * @return \think\model\relation\BelongsTo // */ // public function his() // { // return $this->hasMany('app\common\model\CommonHis','target_id','id')->where('target_type',3)->order('id', 'desc'); // } // /** // * 删除 // * @param $id // * @return bool|int // */ // public function remove() // { // return $this->delete(); // } }