diff --git a/application/api/controller/school/newactivity/ActivityDrafts.php b/application/api/controller/school/newactivity/ActivityDrafts.php new file mode 100644 index 0000000..42168bf --- /dev/null +++ b/application/api/controller/school/newactivity/ActivityDrafts.php @@ -0,0 +1,351 @@ +transactionCheck(); + + $this->model = new ActivityDraftsModel; + parent::_initialize(); + //敏感词过滤 +// $this->checkSensitivewords([]); + +// $this->setUrlLock(); + } + + + + + + /** + * @ApiTitle( 通用活动草稿箱大搜索列表) + * @ApiSummary(通用活动草稿箱大搜索列表) + * @ApiMethod(GET) + * @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字") + * @ApiParams(name = "my", type = "string",required=true,description = "是否查自己(需登录) 1是 0否") + * @ApiParams(name = "page", type = "string",required=true,description = "页数") + * @ApiParams(name = "limit", type = "string",required=true,description = "条数") + * @ApiParams(name = "start_time", type = "int",required=false,description = "开始时间10位秒级时间戳") + * @ApiParams(name = "end_time", type = "int",required=false,description = "结束时间10位秒级时间戳") + * @ApiParams(name = "sign_start_time", type = "int",required=false,description = "报名开始时间10位秒级时间戳") + * @ApiParams(name = "sign_end_time", type = "int",required=false,description = "报名结束时间10位秒级时间戳") + * @ApiParams(name = "cate_ids", type = "string",required=false,description = "平台分类ids 多值逗号拼接") + * @ApiParams(name = "province", type = "string",required=false,description = "省编号") + * @ApiParams(name = "city", type = "string",required=false,description = "市编号") + * @ApiParams(name = "district", type = "string",required=false,description = "县区编号") + * @ApiParams(name = "feel", type = "string",required=false,description = "是否免费:0=否,1=是") + * @ApiParams(name = "order", type = "string",required=false,description = " normal=综合排序,distance=距离优先") + * @ApiParams(name = "nearby", type = "string",required=false,description = "限制最大搜索距离(米)") + * @ApiParams(name = "latitude", type = "string",required=false,description = "latitude") + * @ApiParams(name = "longitude", type = "string",required=false,description = "longitude") + * @ApiReturn({ + * + *}) + */ + public function drafts_list() + { + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params =[]; + +// $params["platform"] = $this->request->get('platform/s', ''); //搜索关键字 + + $params["my"] = $this->request->get('my/d', 1); //机构店铺id + $params["my_user_id"] = $user_id; +// $params["collect"] = $this->request->get('collect/d', 0); //页数 + $params["page"] = $this->request->get('page/d', 1); //页数 + $params["limit"] = $this->request->get('limit/d', 10); //条数 + $params["keywords"] = $this->request->get('keywords/s', ''); //搜索关键字 + $params["shop_id"] = $this->request->get('shop_id/d', ''); //机构店铺id + + $params["cate_ids"] = $this->request->get('cate_ids/s', ''); //机构店铺id + + $params["address_type"] = $this->request->get('address_type/s', ''); //机构店铺id + $params["province"] = $this->request->get('province/s', ''); //机构店铺id + + $params["classes_type"] = $this->request->get('classes_type/s', ''); //机构店铺id + + $params["city"] = $this->request->get('city/s', ''); //机构店铺id + $params["district"] = $this->request->get('district/s', ''); //机构店铺id +// $params["status"] = $this->request->get('status/s', ''); //机构店铺id +// $params["recommend"] = $this->request->get('recommend/s', ''); //机构店铺id +// $params["hot"] = $this->request->get('hot/s', ''); //机构店铺id +// $params["new"] = $this->request->get('new/s', ''); //机构店铺id +// $params["selfhot"] = $this->request->get('selfhot/s', ''); //机构店铺id + $params["feel"] = $this->request->get('feel/s', ''); //机构店铺id + + $params["is_expire"] = $this->request->get('is_expire/d', 0); //机构店铺id + $params["is_sign_expire"] = $this->request->get('is_sign_expire/d', 0); //机构店铺id + + + $params["order"] = $this->request->get('order/s', ''); //机构店铺id + $params["nearby"] = $this->request->get('nearby/s', ''); //机构店铺id + $params["has_shop"] = $this->request->get('has_shop/d', ''); //主讲师用户id + + $params["latitude"] = $this->request->get('latitude/s', ''); //机构店铺id + $params["longitude"] = $this->request->get('longitude/s', ''); //机构店铺id + + + $params["sign_start_time"] = $this->request->get('sign_start_time/d', ''); //主讲师用户id + $params["sign_end_time"] = $this->request->get('sign_end_time/d', ''); //机构店铺id + + $params["start_time"] = $this->request->get('start_time/d', ''); //主讲师用户id + $params["end_time"] = $this->request->get('end_time/d', ''); //机构店铺id + +// $params["auth_status"] = $this->request->get('auth_status/s', ''); //机构店铺id + + + +// $type = $this->request->get('type/s', ''); //筛选学员和教练单 + + try{ + //当前申请状态 + $res = $this->model::getVaildList($params); + $count = $this->model::getVaildList($params,true); +// if($user_id =='670153'){ +// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql()); +// } + }catch (\Exception $e){ + + $this->error($e->getMessage()); + } + $this->success('查询成功', ["list"=>$res,"count"=>$count]); + } + + + + + + /** + * @ApiTitle(活动详情接口) + * @ApiSummary(活动详情接口) + * @ApiMethod(GET) + * @ApiParams(name = "id", type = "int",required=true,description = "活动id") + * @ApiReturn({ + + * + *}) + */ + public function detail(){ + $id = $this->request->get('id/d',''); + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + if(empty($id)){ + $this->error(__('缺少必要参数')); + } + + try { + $res = $this->model->detail($id,$user_id); + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('获取成功', ['detail' => $res]); + } + + + + + + /** + * @ApiTitle(活动草稿箱添加) + * @ApiSummary(活动草稿箱添加) + * @ApiMethod(POST) + * @ApiParams(name = "cate_ids", type = "string",required=true,description = "平台分类ids 多值逗号拼接") + * @ApiParams(name = "refund_id", type = "int",required=true,description = "退款策略id") + * @ApiParams(name = "title", type = "string",required=true,description = "标题") + * @ApiParams(name = "sign_time", type = "string",required=true,description = "报名区间示例: 2025-04-08 00:01:00 - 2025-04-08 15:29:00") + * @ApiParams(name = "time", type = "string",required=true,description = "活动区间示例: 2025-04-09 00:01:00 - 2025-04-09 15:29:00") + * @ApiParams(name = "platform", type = "string",required=false,description = "上架平台:wechat_miniapp=微信小程序,tt_miniapp=抖音小程序") + * @ApiParams(name = "images", type = "string",required=true,description = "轮播图多值逗号拼接") + * @ApiParams(name = "address", type = "string",required=false,description = "地图定位地址") + * @ApiParams(name = "address_detail", type = "string",required=false,description = "手录详细地址") + * @ApiParams(name = "longitude", type = "string",required=false,description = "经度") + * @ApiParams(name = "latitude", type = "string",required=false,description = "纬度") + * @ApiParams(name = "content", type = "string",required=false,description = "活动详情") + * @ApiParams(name = "price", type = "string",required=false,description = "报名单价 0为免费") + * @ApiParams(name = "stock", type = "string",required=false,description = "活动限制人数") + * @ApiParams(name = "image", type = "string",required=false,description = "入群二维码") + * @ApiReturn({ + * + *}) + */ + public function add(){ + +// $this->transactionCheck(); + + //敏感词过滤 + $this->checkSensitivewords(["title","content"]); + + $user_id = 73; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params = []; + $params["user_id"] = $user_id; //老师id + $params["cate_ids"] = $this->request->post('cate_ids/s', ''); //课程标签 + $params["refund_id"] = $this->request->post('refund_id/d', ''); //课程标签 + + $params["platform"] = $this->request->post('platform/s', 'wechat_miniapp'); //课程标签 + + $params["title"] = $this->request->post('title/s', ''); //老师id + $params["images"] = $this->request->post('images/s', ''); //老师id + $params["image"] = $this->request->post('image/s', ''); //老师id + + $params["stock"] = $this->request->post('stock/d', 0); //核销次数 + // + + + $params["address"] = $this->request->post('address/s', ''); //老师id + $params["address_detail"] = $this->request->post('address_detail/s', ''); //老师id + $params["longitude"] = $this->request->post('longitude/s', 0); //老师id + $params["latitude"] = $this->request->post('latitude/s', 0); //老师id + $params["content"] = $this->request->post('content/s', ''); //老师id + + $params["price"] = $this->request->post('price/f', 0); //老师id + + + $params["sign_time"] = $this->request->post('sign_time/s', 0); + $params["time"] = $this->request->post('time/s', 0); + + + //classes_type + + try{ + if(!config("site.miniapp_activity_swtich")) $this->error("已关闭发布渠道,请联系管理员后台添加!"); + + $res = $this->model->add($params,$user_id,'user',$user_id,true); + }catch (\Throwable $e){ + $this->error($e->getMessage(),[ + "errcode"=>$e->getCode() + ]); + } + $this->success('添加成功', $res); + } + + + + + /** + * @ApiTitle(活动草稿箱编辑) + * @ApiSummary(活动草稿箱编辑) + * @ApiMethod(POST) + * @ApiRoute (/api/school.newactivity.activity_drafts/edit/ids/{ids}) + * @ApiParams (name="ids", type="string", required=true, description="需要编辑的id") + * @ApiParams(name = "cate_ids", type = "string",required=true,description = "平台分类ids 多值逗号拼接") + * @ApiParams(name = "refund_id", type = "int",required=true,description = "退款策略id") + * @ApiParams(name = "title", type = "string",required=true,description = "标题") + * @ApiParams(name = "sign_time", type = "string",required=true,description = "报名区间示例: 2025-04-08 00:01:00 - 2025-04-08 15:29:00") + * @ApiParams(name = "time", type = "string",required=true,description = "活动区间示例: 2025-04-09 00:01:00 - 2025-04-09 15:29:00") + * @ApiParams(name = "platform", type = "string",required=false,description = "上架平台:wechat_miniapp=微信小程序,tt_miniapp=抖音小程序") + * @ApiParams(name = "images", type = "string",required=true,description = "轮播图多值逗号拼接") + * @ApiParams(name = "address", type = "string",required=false,description = "地图定位地址") + * @ApiParams(name = "address_detail", type = "string",required=false,description = "手录详细地址") + * @ApiParams(name = "longitude", type = "string",required=false,description = "经度") + * @ApiParams(name = "latitude", type = "string",required=false,description = "纬度") + * @ApiParams(name = "content", type = "string",required=false,description = "活动详情") + * @ApiParams(name = "price", type = "string",required=false,description = "报名单价 0为免费") + * @ApiParams(name = "stock", type = "string",required=false,description = "活动限制人数") + * @ApiParams(name = "image", type = "string",required=false,description = "入群二维码") + * @ApiReturn({ + * + *}) + */ + public function edit($ids = null){ + //敏感词过滤 + $this->checkSensitivewords(["title","content"]); + + $user_id = 73; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params = []; + $params["user_id"] = $user_id; //老师id + $params["cate_ids"] = $this->request->post('cate_ids/s', ''); //课程标签 + $params["refund_id"] = $this->request->post('refund_id/d', ''); //课程标签 + + $params["platform"] = $this->request->post('platform/s', 'wechat_miniapp'); //课程标签 + + $params["title"] = $this->request->post('title/s', ''); //老师id + $params["images"] = $this->request->post('images/s', ''); //老师id + $params["image"] = $this->request->post('image/s', ''); //老师id + + $params["stock"] = $this->request->post('stock/d', 0); //核销次数 + // + + + $params["address"] = $this->request->post('address/s', ''); //老师id + $params["address_detail"] = $this->request->post('address_detail/s', ''); //老师id + $params["longitude"] = $this->request->post('longitude/s', 0); //老师id + $params["latitude"] = $this->request->post('latitude/s', 0); //老师id + $params["content"] = $this->request->post('content/s', ''); //老师id + + $params["price"] = $this->request->post('price/f', 0); //老师id + + + $params["sign_time"] = $this->request->post('sign_time/s', 0); + $params["time"] = $this->request->post('time/s', 0); + + try{ + if(!config("site.miniapp_activity_swtich")) $this->error("已关闭发布渠道,请联系管理员后台添加!"); + + + $res = $this->model->edit($ids,$params,$user_id,'user',$user_id,true); + }catch (\Throwable $e){ + $this->error($e->getMessage()); + } + $this->success('编辑成功', $res); + } + + + + + /** + * 删除活动草稿箱 + * + * @ApiMethod (POST) + * @ApiParams (name="ids", type="string", required=true, description="要删除的ids,批量则逗号拼接多个") + */ + public function del() + { +// $admin_id = $this->auth->id; + + $user_id = 73; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + + $ids = $this->request->post('ids/s'); + + try{ + $menulist = $this->model->del($ids,$user_id,'user',$user_id,true); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + + $this->success('删除成功', $menulist); + } + + + + + +} \ No newline at end of file diff --git a/application/common/model/school/activity/ActivityDrafts.php b/application/common/model/school/activity/ActivityDrafts.php new file mode 100644 index 0000000..1d56ed7 --- /dev/null +++ b/application/common/model/school/activity/ActivityDrafts.php @@ -0,0 +1,1401 @@ += 1000; + $distance_text = round(($distance / 1000), 2) . 'km'; + break; + default : + $distance_text = $distance . 'm'; + break; + + } + + return $distance_text; + } + + + protected static function init() + { + self::afterInsert(function ($row) { + if (empty($row['weigh'])) { + $pk = $row->getPk(); + $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); + } + }); + } + + + + + public function getAddTypeList() + { + return ['1' => __('Add_type 1'), '2' => __('Add_type 2')]; + } + + public function getFeelList() + { + return ['0' => __('Feel 0'), '1' => __('Feel 1')]; + } + + + + + public function getStartTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getEndTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getSignStartTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['sign_start_time']) ? $data['sign_start_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getSignEndTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['sign_end_time']) ? $data['sign_end_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + + + + + + public function getAddTypeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['add_type']) ? $data['add_type'] : ''); + $list = $this->getAddTypeList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getFeelTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['feel']) ? $data['feel'] : ''); + $list = $this->getFeelList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + protected function setStartTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setEndTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setSignStartTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setSignEndTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + + + + public function user() + { + return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + public function admin() + { + return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + + /** 更新或新增后判断 + * @param $classes_activity_id + * @return void + */ + public function update_classes($classes_activity_id){ +// $this->updateStatus($classes_activity_id); + } + + + /** 更新或新增前判断 + * @param $classes_activity_id + * @return void + */ + public function update_check(&$params,$row=null){ + + + + + + + + + + + if($row){ + //统一时间格式成时间戳 + if( is_string($row["start_time"]))$row["start_time"]=strtotime($row["start_time"]); + if( is_string($row["end_time"]))$row["end_time"]=strtotime($row["end_time"]); + if( is_string($row["sign_start_time"]))$row["sign_start_time"]=strtotime($row["sign_start_time"]); + if( is_string($row["sign_end_time"]))$row["sign_end_time"]=strtotime($row["sign_end_time"]); + } + + + +//开始和结束时间不能为空 + if(!empty($params["time"]) && !empty($params["sign_time"])){ + + $time = $params["time"]; + + + $split_line = " - "; + $time_arr = explode($split_line,$time); + $params["start_time"] = $time_arr[0] ; + $params["end_time"] = $time_arr[1]; + unset($params["time"]); + + $start_time = $params["start_time"]; + $end_time = $params["end_time"]; + + if(empty($start_time) || empty($end_time)){ + throw new \Exception("请选择活动开始和结束时间".$time); + } + //转化时间戳 + $start_time = $params["start_time"] && !is_numeric($params["start_time"]) ? strtotime($params["start_time"]) : $params["start_time"]; + $end_time = $params["end_time"] && !is_numeric($params["end_time"]) ? strtotime($params["end_time"]) : $params["end_time"]; + //结束时间不能小于开始时间 + if($end_time<=$start_time){ + throw new \Exception("活动结束时间不能小于开始时间"); + } + + + + + + + //开始和结束时间不能为空 + $time = $params["sign_time"]; + + $split_line = " - "; + $time_arr = explode($split_line,$time); + $params["sign_start_time"] = $time_arr[0] ; + $params["sign_end_time"] = $time_arr[1]; + unset($params["sign_time"]); + + $sign_start_time = $params["sign_start_time"]; + $sign_end_time = $params["sign_end_time"]; + + if(empty($sign_start_time) || empty($sign_end_time)){ + throw new \Exception("请选择报名开始和结束时间".$time); + } + //转化时间戳 + $sign_start_time = $params["sign_start_time"] && !is_numeric($params["sign_start_time"]) ? strtotime($params["sign_start_time"]) : $params["sign_start_time"]; + $sign_end_time = $params["sign_end_time"] && !is_numeric($params["sign_end_time"]) ? strtotime($params["sign_end_time"]) : $params["sign_end_time"]; + //结束时间不能小于开始时间 + if($sign_end_time<=$sign_start_time){ + throw new \Exception("报名结束时间不能小于开始时间"); + } + + + //两个时间区间段之间不能有任何交集 $start_time $end_time ,$sign_start_time $sign_end_time + //直接判断两个时间段之间是否有交集:分几种情况:1.两个时间段有交集 2.两个时间段没有交集 3.第一个时间段在第二个时间段内 4.第二个时间段在第一个时间段内 只有情况2合理 + if(($start_time<=$sign_start_time && $sign_start_time<=$end_time) || + ($start_time<=$sign_end_time && $sign_end_time<=$end_time) || + ($sign_start_time<=$start_time && $end_time<=$sign_end_time) || + ($sign_start_time>=$start_time && $sign_end_time<=$end_time)){ + throw new \Exception("报名时间段和活动开始时间段有交叉请修改"); + } + + //报名时间必须早于开始时间 + if($sign_start_time>$start_time){ + throw new \Exception("报名时间必须早于开始时间"); + } + //新增时,报名时间需晚于当前时间 + $now_time = time(); + if(!$row && $now_time>$sign_start_time){ + throw new \Exception("报名时间必须是未来时间!"); + } + + + //活动开始和结束时间不能跨天 +// if(date('Y-m-d',$start_time)!=date('Y-m-d',$end_time)){ +// throw new \Exception("活动开始和结束时间不能跨天"); +// } + + //settlement_time 最后结算时间等于活动结束时间往后延长n秒,n取配置 +// $activity_end_settle = config("site.activity_end_settle") ?:0; +// $params["settlement_time"] = $end_time + $activity_end_settle; +// +// $activity_end_sales = config("site.activity_end_sales") ?:0; +// $params["after_sales_time"] = $end_time + $activity_end_sales; + + + }else{ + if(!$row && empty($params["time"])) throw new \Exception("请选择活动开始和结束时间"); + if(!$row && empty($params["sign_time"])) throw new \Exception("请选择报名开始和结束时间"); + if($row){ + if(empty($params["time"])){ + $params["start_time"] = $row["start_time"]; + $params["end_time"] = $row["end_time"]; + $start_time = $params["start_time"] && !is_numeric($params["start_time"]) ? strtotime($params["start_time"]) : $params["start_time"]; + $end_time = $params["end_time"] && !is_numeric($params["end_time"]) ? strtotime($params["end_time"]) : $params["end_time"]; + } + if(empty($params["sign_time"])){ + $params["sign_start_time"] = $row["sign_start_time"]; + $params["sign_end_time"] = $row["sign_end_time"]; + $sign_start_time = $params["sign_start_time"] && !is_numeric($params["sign_start_time"]) ? strtotime($params["sign_start_time"]) : $params["sign_start_time"]; + $sign_end_time = $params["sign_end_time"] && !is_numeric($params["sign_end_time"]) ? strtotime($params["sign_end_time"]) : $params["sign_end_time"]; + } + } + } + + + + + + $rule = [ + 'user_id'=>'require', + 'title'=>'require', + 'images'=>'require', +// 'headimage' => 'require', + 'address' => 'require', + 'address_detail' => 'require', + 'longitude' => 'require', + 'latitude' => 'require', +// 'province' => 'require', +// 'city' => 'require', +// 'district' => 'require', +// 'address_city' => 'require', +// 'type' => 'require', + 'stock' => 'require', +// 'address_type' => 'require', + 'content' => 'require', + 'cate_ids' => 'require', + 'price' => 'require', + + + 'start_time' => 'require', + 'end_time' => 'require', + 'sign_start_time' => 'require', + 'sign_end_time' => 'require', +// 'refund_id' => 'require', + + + ]; + + + $rule_msg = [ + "user_id.require"=>'发布用户必填', + "title.require"=>'标题必填', + "images.require"=>'轮播图必填', +// "headimage.require"=>'课程头图必填', + + 'address.require' => '地址必填', + 'address_detail.require' => '详细地址必填', + 'longitude.require' => '经度必填', + 'latitude.require' => '纬度必填', +// 'province.require' => '省编号必填', +// 'city.require' => '市编号必填', +// 'district.require' => '县区编号必填', +// +// 'address_city.require' => '城市选择必填', +// 'type.require' => '地点类型必填', + 'stock.require'=> '活动限制人数必填', +// 'address_type.require'=> '地址类型必填', + 'content.require'=> '活动详情必填', + 'cate_ids.require'=> '平台分类必填', + 'price.require'=> '售价必填', + + + + 'start_time.require' => '活动开始时间必填', + 'end_time.require' => '活动结束时间必填', + 'sign_start_time.require' => '报名开始时间必填', + 'sign_end_time.require' => '报名结束时间必填', + +// 'refund_id.require' => '退款策略必填', + ]; + + self::check($params,$rule,$rule_msg); + + if ($params["content"]) { + $params["content"] = htmlspecialchars_decode($params["content"]); + + // 过滤掉禁止自动换行属性:text-wrap-mode: nowrap; + $pattern = '/text-wrap-mode\s*:\s*nowrap\s*(?:;|\n)/i'; // 匹配 text-wrap-mode: nowrap 后接分号或换行符 + $params["content"] = preg_replace($pattern, '', $params["content"]); +} + + + + + + + $images = is_array($params["images"]) ? $params["images"] : explode(",",$params["images"]); + //轮播图至少3张 + if(count($images) < 3 || count($images) > 5){ + throw new \Exception("轮播图至少3张,最多5张"); + } + foreach ($images as $image){ + if(!$image) throw new \Exception("轮播图不能为空"); + } + + //发活动是否需要实名认证 +// if(config("site.activity_realname_switch")){ +// //查询是否实名认证 +// $real_name_info = (new \app\common\model\cardocr\Card)->checkRealname($params["user_id"]); +// if($real_name_info["status"]!=1) throw new \Exception("请先实名认证",1001100); +// } + + + + + + if($params["price"]>0){ + if(empty($params["refund_id"])) throw new \Exception("退款策略必填"); + $refund_id = $params["refund_id"]; + $refund = Refund::where("id",$refund_id) ->find(); + + if(!$refund){ + throw new \Exception("退款策略不存在"); + } + $paid_activity_min_price = config("site.paid_activity_min_price"); + if($params["price"]<$paid_activity_min_price){ + throw new \Exception("活动售价不能低于".$paid_activity_min_price."元"); + } + + + } + if($params["price"]<0)$params["price"]=0; + + + + + $user_id = $params["user_id"]; + $user = User::where("id",$user_id)->find(); + if(!$user){ + throw new \Exception("发布用户不存在"); + } + + + + if($row){ +// //活动限制人数不能小于销量 +// if($params["stock"]<$row["sale"]){ +// throw new \Exception("活动限制人数不能小于已参与人数!"); +// } + + + //修改 +// $title = self::where("id","<>",$row["id"])->where("status","not in","-1,5")->where("title",$params["title"])->find(); +// if($title) throw new \Exception("活动名不允许重复"); + + }else{ + //新增 + //不在已结束和已取消的活动名title不允许重复 +// $title = self::where("status","not in","-1,5")->where("title",$params["title"])->find(); +// if($title) throw new \Exception("活动名不允许重复"); + } + + + + + + //如果价格为零,记录免费状态 + if($params["price"]==0){ + $params["feel"] = '1'; + }else{ + $params["feel"] = '0'; + //得到当前的微信手续费百分比 + $activity_withdrawal_scale = config("site.activity_withdrawal_scale"); + $activity_withdrawal_scale_100 = bcmul($activity_withdrawal_scale,100,2); + //当前售价对应手续费不得低于0.01 + //计算当前售价手续费 + $fee = bcmul($params["price"],$activity_withdrawal_scale,3); + if($fee<0.01){ + throw new \Exception("当前售价手续费{$fee}按{$activity_withdrawal_scale_100}%低于0.01,请提高售价或设为免费!"); + } + } + + $now_time = time(); + //根据时间区间,设定录入的活动初始状态:1=未开始,2=报名中,3=待开始,4=进行中,5=已结束 + //时间在报名开始时间之前为1=未开始 + //时间在报名区间之内为2=报名中 + //时间在开始时间之前,在报名结束时间之后为3=待开始 + //时间在开始时间之后,在结束时间之前为4=进行中 + //时间在结束时间之后为5=已结束 + //已取消则不更新状态 +// +// if(!$row || $row["status"]!='-1'){ +// if($now_time<$sign_start_time){ +// $params["status"] = '1'; +// } else if($now_time>=$sign_start_time && $now_time<=$sign_end_time){ +// $params["status"] = '2'; +// } else if($now_time>$sign_end_time && $now_time<$start_time){ +// $params["status"] = '3'; +// } else if($now_time>=$start_time && $now_time<=$end_time){ +// $params["status"] = '4'; +// } else if($now_time>$end_time){ +// $params["status"] = '5'; +// } +// } +// +// if(isset($params["auth_status"])){ +// if(!in_array($params["auth_status"],[1,2])) throw new \Exception("{$params["title"]}请填写审核结果"); +// $params["auth_time"] = time(); +// if($params["auth_status"] == 2 && empty($params["reason"])) throw new \Exception("{$params["title"]}请填写审核失败原因"); +// +// //后台新增: 新增审核失败,状态则为已取消 +// if($params["auth_status"] == 2){ +// +//// $params["status"] = '-1'; +//// $params["cancel_type"] = '1'; +// if(!$row){ +// //新增审核 +// }else{ +// //编辑审核 +// if($row["auth_status"] != 0 && $row["auth_status"] != $params["auth_status"]){ +// throw new \Exception("{$params["title"]}您已审核不允许修改审核结果"); +// } +// } +// +// } +// $auth = \app\admin\library\Auth::instance(); +// //审核id为后台登录id +// $params["admin_id"] = $auth->id; +// }else{ +// //前台提交 +//// $params["auth_status"] = 0; +// +// +// } + + + //判断新增身份 + if(!$row){ +// if(isset($params["auth_status"])){ +// //总后台 +// $params["add_type"] = '2'; +// $params["add_id"] = $params["admin_id"]; +// }else{ + //用户 + $params["add_type"] = '1'; + $params["add_id"] = $params["user_id"]; + +// } + } + +// if(!isset($params["auth_status"]) &&$row){ +// //用户端不允许修改 +//// throw new \Exception("{$params["title"]}审核通过的活动只允许手动关闭,不允许修改!"); +// //允许提交的字段 +// $allowField = [ +// "title", +// "cate_ids", +// "image", +// "images", +// "address_detail", +// "address", +// "longitude", +// "latitude", +//// "price", +// "stock", +// "content", +//// "refund_id", +// "show", +// "platform", +// ]; +// //非允许提交的字段去掉 +// $params = array_intersect_key($params, array_flip($allowField)); +// +// +// } +// if(!isset($params["auth_status"])){ +// //前台提交 +// $params["auth_status"] = 0; +// } +// $params["fee_scale"] = config("site.activity_withdrawal_scale"); + + + } + + /** 删除前判断 + * @param $id + * @param $params + * @param $row + * @return void + */ + public function updateCheck($id,$params=[],$row=null){ + + } + + + + /** + * 获取所有活动列表 + */ + public static function getVaildList($params,$count=false) { + extract($params); + $a = (new self)->getWithAlisaName().'.'; + $with = ['user']; +// if (isset($has_shop) && $has_shop) { +// $with[] = 'shop'; +// } + + + + + + $cate_list = Cate::where("status",'1')->column("name","id"); +// $label_list = Label::where("status",'1')->column("name","id"); +// $type_list = Type::where("status",'1')->column("name","id"); + $selfetch = self::with($with)->where("{$a}show", '=', '1'); + + + + $order = $order?? 'normal'; + $per_page = $limit ?? 10; + + + $field = "{$a}start_time,{$a}end_time,{$a}sign_start_time,{$a}sign_end_time,{$a}id,{$a}user_id,{$a}title,{$a}images,{$a}province,{$a}city,{$a}district,{$a}address,{$a}address_detail,{$a}longitude,{$a}latitude,{$a}stock,{$a}price,{$a}weigh,{$a}createtime,{$a}feel"; + + //得到距离 + if (isset($latitude) && isset($longitude) && $latitude && $longitude) { + $field .= ', '.getDistanceBuilder($latitude, $longitude,$a); + }else{ + $field .= ', 0 as distance'; + } + + //得到每个 + + + $selfetch = $selfetch->field($field); + if (isset($keywords) && $keywords) { + //查询分类名获得分类id + $keywords_cate_ids = Cate::where("name",'like', '%' . $keywords . '%')->column("id"); + + if($keywords_cate_ids){ + $keywords_cate_ids = implode("|",$keywords_cate_ids); + $selfetch = $selfetch->where(function ($query)use($a,$keywords_cate_ids,$keywords){ + $query->whereRaw(" {$a}cate_ids REGEXP '({$keywords_cate_ids})'") + ->whereOr("{$a}title|{$a}address|{$a}address_detail|{$a}address_city", 'like', '%' . $keywords . '%'); + }); + +// $selfetch = $selfetch->whereOr( function ($query)use($a,$keywords_cate_ids){ +// $query->whereRaw(" {$a}cate_ids REGEXP '({$keywords_cate_ids})'") +// ->where("{$a}show", '=', '1'); +// }); + }else{ + $selfetch = $selfetch->where("{$a}title|{$a}address|{$a}address_detail|{$a}address_city", 'like', '%' . $keywords . '%'); + } + + + } + + + if(isset($start_time) && isset($end_time) && ($end_time || $start_time)) { + if($start_time){ + $selfetch = $selfetch->where("{$a}start_time", '>=', $start_time); + } + if($end_time){ + $selfetch = $selfetch->where("{$a}end_time", '<=', $end_time); + } + } + + + if(isset($sign_start_time) && isset($sign_end_time) && ($sign_end_time || $sign_start_time)) { + if($sign_start_time){ + $selfetch = $selfetch->where("{$a}sign_start_time", '>=', $sign_start_time); + } + if($sign_end_time){ + $selfetch = $selfetch->where("{$a}sign_end_time", '<=', $sign_end_time); + } + } + + + + // is_expire 是否查过期:1只查过期,2只查不过期,0全查 + if(isset($is_expire) && $is_expire) { + if($is_expire == 1){ + $selfetch = $selfetch->where("{$a}end_time", '<', time()); + }else{ + $selfetch = $selfetch->where("{$a}end_time", '>=', time()); + } + + } + + + +// if (isset($manystore_id) && $manystore_id) { +// $selfetch = $selfetch->where("{$a}manystore_id", 'in', ''.$manystore_id); +// } +// +// if (isset($shop_id) && $shop_id) { +// $selfetch = $selfetch->where("{$a}shop_id", 'in', ''.$shop_id); +// } + + if (isset($user_id) && $user_id) { + $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$user_id); + } + + if (isset($my) && $my && isset($my_user_id) && $my_user_id) { + $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$my_user_id); + } + if($my ==1 && empty($my_user_id)){ + $selfetch = $selfetch->where("{$a}user_id", 'in', [-3]); + } + + + +// if (isset($teacher_id) && $teacher_id) { +// $selfetch = $selfetch->where("{$a}teacher_id", 'in', ''.$teacher_id); +// } + +// if (isset($type) && $type) { +// $selfetch = $selfetch->where("{$a}type", 'in', ''.$type); +// } + +// if (isset($address_type) && $address_type) { +// $selfetch = $selfetch->where("{$a}address_type", 'in', ''.$address_type); +// } + + +// if (isset($recommend) && $recommend) { +// $selfetch = $selfetch->where("{$a}recommend", 'in', ''.$recommend); +// } +// +// +// if (isset($hot) && $hot) { +// $selfetch = $selfetch->where("{$a}hot", 'in', ''.$hot); +// } +// +// +// if (isset($new) && $new) { +// $selfetch = $selfetch->where("{$a}new", 'in', ''.$new); +// } + + if (isset($feel) && $feel) { + $selfetch = $selfetch->where("{$a}feel", 'in', ''.$feel); + } + +//// //设置订单信息 +// if(isset($auth_status) && $auth_status !=='' && $auth_status !==null){ +// $selfetch = $selfetch->where("{$a}auth_status", 'in', ''.$auth_status); +// } +// +// //设置订单信息 +// if(isset($status) && $status !=='' && $status !==null){ +// $selfetch = $selfetch->where("{$a}status", 'in', ''.$status); +// } + + + + //区域搜索 + if (isset($province) && $province) { + $selfetch = $selfetch->where("{$a}province", 'in', ''.$province); + } + + + if (isset($city) && $city) { + $selfetch = $selfetch->where("{$a}city", 'in', ''.$city); + } + + if (isset($district) && $district) { + $selfetch = $selfetch->where("{$a}district", 'in', ''.$district); + } + + + + + + + + + + +// if (isset($platform) && $platform) { +// $platform = implode("|",explode(',',$platform)); +// $selfetch = $selfetch->whereRaw(" {$a}platform REGEXP '({$platform})'"); +// } +// +// if (isset($classes_type) && $classes_type) { +// $classes_type = implode("|",explode(',',$classes_type)); +// $selfetch = $selfetch->whereRaw(" {$a}classes_type REGEXP '({$classes_type})'"); +// } + + + + + if (isset($cate_ids) && $cate_ids) { + $cate_ids = implode("|",explode(',',$cate_ids)); + $selfetch = $selfetch->whereRaw(" {$a}cate_ids REGEXP '({$cate_ids})'"); + } +// +// if (isset($classes_label_ids) && $classes_label_ids) { +// $classes_label_ids = implode("|",explode(',',$classes_label_ids)); +// $selfetch = $selfetch->whereRaw(" {$a}classes_label_ids REGEXP '({$classes_label_ids})'"); +// } + $collect_classes_lib_ids = [-1]; + //需登录查询条件: + if(isset($my_user_id) && $my_user_id){ + //得到我收藏的课程ids + $collect_classes_lib_ids = Collect::where("user_id",$my_user_id)->column("classes_activity_id"); + //专查我的收藏 + if(isset($collect) && $collect){ + $selfetch = $selfetch->where("{$a}id","in",$collect_classes_lib_ids); + } + + } + + if(isset($order) && $order == "distance"){ + $selfetch = $selfetch->where("{$a}longitude","not null") + ->where("{$a}latitude","not null") + ->where("{$a}longitude","<>","") + ->where("{$a}latitude","<>","") + ->where("{$a}longitude","<>","null") + ->where("{$a}latitude","<>","null"); + } + + + + + + //排序 + switch ($order) { + case "normal": //综合排序(推薦優先) + $selfetch = $selfetch->order("{$a}weigh desc,{$a}start_time desc,{$a}id desc"); + break; + case "distance": //距离优先 权重 + $selfetch = $selfetch->order("distance asc,{$a}weigh desc"); + break; +// case "hot": //熱門优先 +// $selfetch = $selfetch->order("{$a}hot desc,{$a}recommend desc,{$a}weigh desc,{$a}verification_num desc,{$a}sale desc,{$a}sign_num desc"); +// break; +// +// case "new": //平台最新优先 +// $selfetch = $selfetch->order("{$a}new desc,{$a}id desc,{$a}weigh desc,{$a}verification_num desc,{$a}sale desc,{$a}sign_num desc"); +// break; +// +// case "recommend": //推薦优先 +// $selfetch = $selfetch->order("{$a}recommend desc,{$a}weigh desc,{$a}verification_num desc,{$a}sale desc,{$a}sign_num desc"); +// break; +// +// case "sale": //銷量优先 +// $selfetch = $selfetch->order("{$a}sale desc,{$a}verification_num desc,{$a}sign_num desc,{$a}recommend desc,{$a}weigh desc"); +// break; + +// case "views": //浏览量优先 +// $selfetch = $selfetch->order("{$a}views desc,{$a}recommend desc,{$a}weigh desc,{$a}verification_num desc,{$a}sale desc"); +// break; +// case "collect": //收藏量优先 +// $selfetch = $selfetch->order("{$a}collect desc,{$a}recommend desc,{$a}weigh desc,{$a}verification_num desc,{$a}sale desc"); +// break; + default: + throw new \Exception("不支持的排序类型"); + } + + if(isset($nearby) && $nearby) { +// throw new \Exception("现版本不支持"); + $selfetch = $selfetch->having("distance <= {$nearby}"); + } + if($count){ + $total = $selfetch->count(); + return $total; + } + + + + + $selfetch = $selfetch->page($page,$limit)->select(); + + + foreach ($selfetch as $row) { + +// $row->getRelation('manystore')->visible(['nickname']); + $row->getRelation('user')->visible(['nickname','avatar']); + } + $rows = $selfetch; +// $total = $selfetch->total(); + + + + //额外附加数据 + foreach ($rows as &$row) { //迭代器魔术方法遍历,填值自动引用传值 +// //设置是否已收藏 +// $row->is_collect = in_array($row->id,$collect_classes_lib_ids) ? 1 : 0; +// +// if($row->is_collect){ +// $row["collect"] = Collect::where("user_id",$my_user_id)->where("classes_activity_id",$row->id)->find(); +// } + + $classes_cate_ids = $row['cate_ids']; + $classes_cate = []; + foreach (explode(",", $classes_cate_ids) as $classes_cate_id){ + if(isset($cate_list[$classes_cate_id]))$classes_cate[] = $cate_list[$classes_cate_id]; + } + $row['classes_cate'] = $classes_cate; + + +// $row['join_info'] = self::getJoininfo( $row["id"],$row["stock"],10); + + + } + $result = array("data" => $rows); + return $result; + } + + + + + /** 课程详情 + * @param $id + * @throws \think\exception\DbException + */ + public function detail($id,$user_id=0,$oper_type='user',$trans=false){ +// //更新课程状态 +// $this->updateStatus($id); + $self = $this->get($id,['user']); + + //只查user的名字 +// $self->getRelation('user')->visible(['nickname']); + + //是否收藏 +// $self['is_collect'] = 0; + //是否购买 +// $self['have_buy'] = 0; + //是否是拥有者 + $self['is_owner'] = $self['user_id'] == $user_id ? 1 : 0; + +// if($user_id){ +// //判断是否收藏 +//// $self['is_collect'] = Collect::where("user_id",$user_id)->where("classes_activity_id",$id)->count() ? 1:0 ; +// +// //判断用户是否已报名 +//// $self['have_buy'] = Order::where("activity_id",$id) +//// ->where("user_id",$user_id) +//// ->where("status","not in",["-3","6","9"]) +//// ->count() ? 1 : 0 ; +// //即非购买者,也非拥有者,则隐藏图片字段 +// if(!$self['have_buy'] && $self["user_id"] != $user_id){ +// //隐藏敏感字段 +// $self["image"] = null; +// } +// +// }else{ +// //隐藏敏感字段 +// $self["image"] = null; +// } + + // +// $this->setViews($id,$user_id,$oper_type,$user_id,$trans); + $self->getRelation('user')->visible(['nickname','realname','mobile','avatar']); + //参与人数 = 虚拟人数 + 平台人数 + + + + $cate_list = Cate::where("status",'1')->column("name","id"); + $classes_cate_ids = $self['cate_ids']; + $classes_cate = []; + foreach (explode(",", $classes_cate_ids) as $classes_cate_id){ + if(isset($cate_list[$classes_cate_id]))$classes_cate[] = $cate_list[$classes_cate_id]; + } + $self['classes_cate'] = $classes_cate; + + + $self['sign_time'] = "{$self["sign_start_time_text"]} - {$self["sign_end_time_text"]}"; + $self['time'] = "{$self["start_time_text"]} - {$self["end_time_text"]}"; + +// $self['join_info'] = self::getJoininfo($id,$self["stock"],10); + +// $self['some_people'] = self::getSomePeople($id); + + //退款政策 + $self['refund_info'] = Refund::where("id",$self["refund_id"])->find(); + +// $self['refund_desc'] = $this->refund_desc($id,$order_id=0); + +// //只退百分之50的起始时间点 +// $return_50 = 0; +// if($self['refund_info']){ +// switch ($self['refund_info']['status']){ +// case "7" : //前12小时退 +// $return_50 = $self["start_time"] - 12*3600; +// break; +// case "9" : //前24小时退 +// $return_50 = $self["start_time"] - 24*3600; +// break; +// case "11" : //前48小时退 +// $return_50 = $self["start_time"] - 48*3600; +// break; +// +// } +// +// } +// +// +// $self["return_50"] = $return_50; +// $self["last_time"] = $self["after_sales_time"] ?: $self["end_time"] + config("site.activity_end_sales"); + return $self; + } +// +// /**设置浏览量 +// * @param $id +// * @param int $user_id +// * @param bool $check +// * @param bool $trans +// * @throws \Exception +// */ +// public function setViews($id,$user_id,$oper_type='user',$oper_id=0,$trans=false){ +// $classes_lib = self::where("id",$id)->find(); +// if(!$classes_lib)throw new \Exception("找不到活动!"); +// //判断逻辑 +// if($trans){ +// self::beginTrans(); +// } +// +// try{ +// //事务逻辑 +// $classes_lib->views = $classes_lib->views + 1; +// //查询是否已收藏 +// $classes_lib->save(); +// +// +// //调用事件 +// $data = ['activity' => $classes_lib,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; +// \think\Hook::listen('new_activity_view_after', $data); +// +// +// if($trans){ +// self::commitTrans(); +// } +// }catch (\Exception $e){ +// if($trans){ +// self::rollbackTrans(); +// } +// throw new \Exception($e->getMessage()); +// } +// return $classes_lib; +// } +// + + +// +// +// /**设置收藏 +// * @param $id +// * @param int $user_id +// * @param int $collect 0取消收藏 1收藏 +// * @param bool $check +// * @param bool $trans +// * @throws \Exception +// */ +// public function collect($id,$user_id,$collect,$oper_type='user',$oper_id=0,$trans=false){ +// $classes_lib = self::where("id",$id)->find(); +// if(!$classes_lib)throw new \Exception("找不到活动!"); +// //判断逻辑 +// if($trans){ +// self::beginTrans(); +// } +// +// try{ +// //事务逻辑 +// $where = [ +// "user_id"=>$user_id, +// "classes_activity_id"=>$id, +//// "weigh"=>$classes_lib["weigh"], +// ]; +// //查询是否已收藏 +// $res1 = Collect::where($where)->find(); +// if($collect){ +// if(!$res1){ +// $where["weigh"] = $classes_lib["weigh"]; +// +// //未收藏,添加收藏 +// $res1 = new Collect(); +// $res1->allowField(true)->save($where); +// } +// +// self::update_classes($classes_lib["id"]); +// //调用事件 +// $data = ['activity' => $classes_lib,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; +// \think\Hook::listen('new_activity_collect_success_after', $data); +// +// }else{ +// +// unset($where["weigh"]); +// //取消收藏 +// $res1 = Collect::where($where)->delete(); +// self::update_classes($classes_lib["id"]); +// //调用事件 +// $data = ['activity' => $classes_lib,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; +// \think\Hook::listen('new_activity_collect_cancel_after', $data); +// +// +// } +// +// +// if($trans){ +// self::commitTrans(); +// } +// }catch (\Exception $e){ +// if($trans){ +// self::rollbackTrans(); +// } +// throw new \Exception($e->getMessage()); +// } +// $where["is_collect"] = $collect; +// return $where; +// } +// +// + + + + public static function orderInfoSync($classes_lib_id){ + $classes_lib = self::get($classes_lib_id); + if($classes_lib){ + //查询所有课程订单更新课程单信息 + $order = \app\common\model\school\activity\order\OrderDetail::where("activity_id",$classes_lib_id)->select(); + foreach ($order as $row){ + $update = $classes_lib->toArray(); + $update_data = $row->checkAssemblyParameters($update,["id","price","createtime"]); + $row->save($update_data); + } +// \app\common\model\school\activity\order\Order::where("activity_id",$classes_lib_id)->update(["fee_scale"=>$classes_lib["fee_scale"]]); + + } + + } + + + + + + /** 新增活动 + * @param $params + * @param $trans + * @return $this + * @throws \Exception + */ + public function add($params,$user_id,$oper_type='user',$oper_id=0,$trans=false){ + + if (empty($params)) { + throw new \Exception(__('Parameter %s can not be empty', '')); + } + if($user_id)$params["user_id"] = $user_id; + + +//判断逻辑 + if($trans){ + self::beginTrans(); + } + $res = true; + try{ + +// //是否采用模型验证 +// if ($this->modelValidate) { +// $name = str_replace("\\model\\", "\\validate\\", get_class($this)); +// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; +// $this->validateFailException()->validate($validate); +// } + $row = new self; + $this->update_check($params,null); + $result = $row->allowField(true)->save($params); + $this->update_classes($row["id"]); +// $row->reason = ""; +// //调用审核事件触发 +// $data = ['activity' => $row,"user_id"=>$params["user_id"],"oper_type"=>$oper_type,"oper_id"=>$oper_id]; +// \think\Hook::listen('new_activity_auth_need_after', $data); + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage()); + } + return $row; + } + + + + + + +// /*** 下单详情 +// * @param $id +// * @param $limit +// * @return void +// * @throws \think\db\exception\DataNotFoundException +// * @throws \think\db\exception\ModelNotFoundException +// * @throws \think\exception\DbException +// */ +// public static function getJoininfo($id,$stock,$limit=10) +// { +// $users = []; +// //人数 +// $people_number = Order::where("activity_id",$id)->where("status","in",[2,3,4,9])->order("id","desc")->sum("num"); +// //查询已支付用户列表,取前10 -3=已取消,0=待支付,2=已报名,3=核销中,4=售后中,5=退款结算中,6=已退款,9=已完成 +// $user_ids = Order::where("activity_id",$id)->where("status","in",[2,3,4,9])->order("id","desc")->limit($limit)->column("user_id"); +// if($user_ids){ +// $users = User::where("id","in",$user_ids)->field("id,nickname,avatar")->select(); +// } +// //百分比:人数$people_number 除以 库存$stock * 100 百分比取整,需判断掉除零异常 +// $percent = 0; +// try{ +// $percent = intval(($people_number/$stock)*100); +// }catch (\Exception $e){ +// $percent = 0; +// } +// +// return compact("users","people_number","percent","stock"); +// } + + + + +// +// /*** 下单片段 +// * @param $id +// * @param $limit +// * @return void +// * @throws \think\db\exception\DataNotFoundException +// * @throws \think\db\exception\ModelNotFoundException +// * @throws \think\exception\DbException +// */ +// public static function getSomePeople($id,$limit=3) +// { +// $as = (new OrderCode)->getWithAlisaName(); +// $peoples = OrderCode::with("activityorder") +// ->where("activityorder.status","not in", ['-3','0',"5","6"]) +// ->where("{$as}.activity_id",$id) +// ->order("{$as}.id","desc") +// ->limit($limit)->select(); +// +// return compact("peoples"); +// } + + + + + public function getActivityAuthIds($user_id,$vaild=false) + { + + if(!$vaild){ + $activity_ids = self::where("user_id",$user_id)->column("id"); + }else{ + //只要审核通过且未结束和取消的 + $activity_ids = self::where("user_id",$user_id)->where("auth_status","in",["1"])->where("status","in",["1","2","3","4"])->column("id"); + } + return $activity_ids; + + } + + public static function getActivityInfo($user_id) + { + //我参与的活动数量 + $join_num = Order::where("user_id",$user_id)->where("status","in",["2","3","9"])->count("activity_id"); + + //我发布的活动数量 + $release_num = self::where("user_id",$user_id)->where("status","not in",["-1"])->count(); + return compact("join_num","release_num"); + } + + + + + + + + + /** 编辑 + * @param $image + * @param $trans + * + * @throws \Exception + */ + public function edit($id,$params,$user_id,$oper_type='user',$oper_id=0,$trans=false){ + + $row = self::where("user_id",$user_id)->where("id",$id)->find(); + if (!$row) { + throw new \Exception(__('No Results were found')); + } + +//判断逻辑 + if($trans){ + self::beginTrans(); + } + $res = true; + try{ + + unset($params["id"]); + unset($params["user_id"]); + + $this->update_check($params,$row); + $result = $row->allowField(true)->save($params); + $this->update_classes($row["id"]); + + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); + } + return $row; + } + + + + + + + + /** 通用删除(后台api版本) + * @param $params + * @param $trans + * @return $this + * @throws \Exception + */ + public function del($ids = null,$user_id,$oper_type='user',$oper_id=0,$trans=false){ + if (empty($ids)) { + throw new \Exception(__('Parameter %s can not be empty', 'ids')); + } +//判断逻辑 + $pk = $this->getPk(); + $list = $this->where("user_id", '=', $user_id)->where($pk, 'in', $ids)->select(); + $count = 0; + if($trans){ + self::beginTrans(); + } + $res = true; + try{ + foreach ($list as $item) { + $count += $item->delete(); + } + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); + } + return $count; + } + + + + + + +}