belongsTo('app\\common\\model\\user\\User'); } /** * 关联活动记录表 * @return \think\model\relation\BelongsTo */ public function activity() { return $this->belongsTo('app\\common\\model\\branch\\Activity', 'activity_id', 'activity_id'); } public function branch() { return $this->belongsTo('app\\common\\model\\branch\\Branch', 'branch_id', 'branch_id'); } /** * 支付状态 */ public function getPayStatusTextAttr($value, $data) { if($data["pay_status"] == 20){ $pay_status = "已支付"; }else{ $pay_status = "未支付"; } return $pay_status; } /** * 支付方式 */ public function getPayTypeTextAttr($value, $data) { $pay_type=""; if($data["pay_type"] == 20){ $pay_type = "微信支付"; }elseif($data["pay_type"] == 10){ $pay_type = "余额支付"; } return $pay_type; } /** * 报名状态 */ public function getStatusTextAttr($value, $data) { $status = '报名失败'; if ($data["status"] == 1) { $status = "报名成功"; } else { if ($data['pay_price'] && $data['pay_status'] == 10) { $status = "待支付活动费用"; } } return $status; } /** * 详情 */ public static function detail($where, $with = ['user']) { !is_array($where) && $where = ['order_id' => (int)$where]; return (new static())->where(array_merge(['is_delete' => 0, 'status' => 1], $where))->with($with)->find(); } /** * 待支付详情 */ public static function getPayDetail($orderNo) { $model = new static(); return $model->where(['order_no' => $orderNo, 'pay_status' => 10])->with(['user'])->find(); } /** * 新增用户记录 * @param $user_id * @param $data * @return bool */ public static function add($data) { $model = new static; $model->save(array_merge([ 'is_delete' => 0, 'app_id' => $model::$app_id ], $data)); return $model['order_id']; } /** * 获取报名数量 */ public static function getRegNum($activity_id) { return (new static())->where('activity_id', '=', $activity_id) ->where('status', '=', 1) ->where('is_delete', '=', 0) ->count(); } /** * 获取签到数量 */ public static function getVerifyNum($activity_id) { return (new static())->where('activity_id', '=', $activity_id) ->where('is_verify', '=', 1) ->where('is_delete', '=', 0) ->count(); } /** * 生成订单号 */ public function orderNo() { return OrderService::createOrderNo(); } /** * 获取报名总数 (可指定某天) */ public function getUserData($startDate = null, $endDate = null, $type, $branch_id = 0) { $model = $this->alias('u') ->join('branch_member', 'u.user_id = branch_member.user_id', 'left'); !is_null($startDate) && $model = $model->where('pay_time', '>=', strtotime($startDate)); if (is_null($endDate)) { !is_null($startDate) && $model = $model->where('pay_time', '<', strtotime($startDate) + 86400); } else { $model = $model->where('pay_time', '<', strtotime($endDate) + 86400); } if ($branch_id > 0) { $model = $model->where('branch_member.branch_id', '=', $branch_id); } $model = $model->where('u.is_delete', '=', 0) ->where('pay_status', '=', 20); if ($type == 'user_total') { // 订单数量 return $model->count(); } else if ($type == 'total_price') { // 订单总金额 return $model->sum('pay_price'); } return 0; } //判断用户是否报名 public static function isReg($user_id, $activity_id) { return !!(new static())->where('user_id', '=', $user_id) ->where('status', '=', 1) ->where('user_id <> reg_user_id') ->where('activity_id', '=', $activity_id) ->count(); } //判断帮报的用户是否报名 public static function isRegByFriend($mobile, $activity_id) { return !!(new static())->where('mobile', '=', $mobile) ->where('status', '=', 1) ->where('is_friend', '=', 1) ->where('activity_id', '=', $activity_id) ->count(); } //判断用户是否签到 public static function isVerify($user_id, $activity_id) { return !!(new static())->where('user_id', '=', $user_id) ->where('is_verify', '=', 1) ->where('activity_id', '=', $activity_id) ->count(); } /** * 获取某天的总报名费 * 结束时间不传则查一天 */ public function getTotalPrice($startDate = null, $endDate = null, $branch_id) { $model = $this->alias('u') ->join('branch_member', 'u.user_id = branch_member.user_id', 'left'); !is_null($startDate) && $model = $model->where('pay_time', '>=', strtotime($startDate)); if (is_null($endDate)) { !is_null($startDate) && $model = $model->where('pay_time', '<', strtotime($startDate) + 86400); } else { $model = $model->where('pay_time', '<', strtotime($endDate) + 86400); } return $model->where('pay_status', '=', 20) ->where('branch_member.branch_id', '=', $branch_id) ->where('u.is_delete', '=', 0) ->sum('pay_price'); } /** * 会员排行榜(报名活跃度) */ public function getUserRankList($date, $branch_id, $limit = 7) { return $this->alias('A') ->join('branch_member B', 'A.user_id=B.user_id') ->join('user C', 'C.user_id=A.user_id') ->field('count(A.order_id) as total,C.nickName,C.avatarUrl,A.*') ->when($date, function ($query, $date) { getModelTime($query, $date, 'A.create_time'); }) ->where('B.branch_id', '=', $branch_id) ->where('A.is_delete', '=', 0) ->group('A.user_id') ->order('total DESC') ->limit($limit) ->select(); } }