123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- declare (strict_types=1);
- namespace app\common\model\kjactivity;
- use app\common\model\Goods;
- use app\common\model\GoodsSku;
- use app\common\model\BaseModel;
- use app\common\model\User;
- /**
- * 活动中心 ▸ 砍价活动发起人
- * Class Ad
- * @package app\common\model
- */
- class KjActivityJoin extends BaseModel
- {
-
- protected $name = 'kj_activity_join';
- protected $append = ['fmt_end_time','user'];
- public function getFmtEndTimeAttr(){
- return strtotime($this->end_time)-time();
- }
- public function getUserAttr(){
- $user = User::detail($this->user_id,['avatar']);
- return ['nick_name'=>$user['nick_name'],'avatar_url'=>$user['avatar_url']];
- }
-
- /**
- * 获取列表
- * @param array $param
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function getList($param = [])
- {
- // 检索查询调价你
- $filter = $this->getFilter($param);
- // 排序条件
- // $sort = $this->setQuerySort($param);
- $sort = ['id'=>'desc'];
- // 查询列表数据
- $list = $this->where($filter)
- ->with(['help'])
- ->order($sort)
- ->paginate(15)->each(function($item) {
- // $id = $item['id'];
- $item['help_cnt'] = count($item['help']);
- });
- return $list ;
- }
- /**
- * 检索查询条件
- * @param array $param
- * @return array
- */
- private function getFilter($param = [])
- {
- // 默认查询条件
- // $params = $this->setQueryDefaultValue($param, []);
- // 检索查询条件
- $filter = [];
- if(isset($param['activity_id']) && $param['activity_id']>-1){
- $filter[] = ['activity_id', '=', $param['activity_id']];
- }
- return $filter;
- }
- /**
- * 一对多关联商品表
- */
- public function activity(){
- return $this->belongsTo('kj', 'id','activity_id');
- }
- /**
- * 一对多关联砍价表
- */
- public function help(){
- return $this->hasMany('KjActivityHelp', 'join_id')->order('id', 'desc');
- }
- // public function add($activity_id, $data){
- // // 先删除全部
- // static::deleteAll(['activity_id' => $activity_id]);
- // if (!empty($data)) {
- // // 添加
- // $dataset = [];
- // foreach ($data as $item) {
- // $dataset[] = [
- // 'activity_id' => $activity_id,
- // 'goods_id' => $item['goods_id'],
- // 'goods_sku_id' => $item['goods_sku_id'],
- // 'low_price'=>$item['low_price'],
- // 'help_kj_up_cnt'=>$item['help_kj_up_cnt']
- // ];
- // }
- // (new static)->addAll($dataset);
- // }
- // }
- }
|