success('请求成功'); } //接线员 public function operator() { $province = input('province', '', 'trim'); //省 $city = input('city', '', 'trim'); //市 $area = input('area', '', 'trim'); //区 $keyword = input('keyword', '', 'trim'); //关键字 $where['status'] = 1; if ($province) { $where['province'] = $province; } if ($city) { $where['city'] = $city; } if ($area) { $where['area'] = $area; } if ($keyword !== '') { $where['name|mobile'] = ['like', '%'.$keyword.'%']; } $list = Db::name('operator')->field('id, name, mobile, avatar, province, city, area')->where($where) ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select(); $list = list_domain_image($list, ['avatar']); $this->success('接线员', $list); } //价格走势 public function pricetrend() { $info = Db::name('platform_info')->field('title, content')->where(['type' => 2])->find(); $this->success('价格走势', $info); } //精选推荐列表 public function mark() { $province = input('province', '', 'trim'); //省 $keyword = input('keyword', '', 'trim'); //关键字 $where['endtime'] = ['gt', time()]; $where['status'] = 1; if ($province) { $where['province'] = $province; } if ($keyword !== '') { $where['name|pig_type|pig_breed_type|province|city|area|address'] = ['like', '%'.$keyword.'%']; } $list = Db::name('mark')->field('id, name, image, pig_type, heft, price, province, city, area') ->where($where)->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select(); $list = list_domain_image($list, ['image']); $mark_bid = Db::name('mark_bid'); foreach ($list as &$v) { $v['bid_count'] = $mark_bid->where(['mark_id' => $v['id']])->count('id'); } $this->success('精选推荐列表', $list); } //招标详情 public function markinfo() { $id = input('id', 0, 'intval'); if (!$id) { $this->error('参数缺失'); } $info = Db::name('mark')->find($id); if (!$info) { $this->error('数据不存在'); } $info = info_domain_image($info, ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']); $info['createtime'] = date('Y-m-d H:i:s', $info['createtime']); $info['remaintime'] = $info['endtime'] - time() > 0 ? $info['endtime'] - time() : 0; //投标剩余时间 $info['again_bid'] = process_time($info['again_bid']); //再次投标间隔时间处理 $this->success('招标详情', $info); } //投标 public function markbid() { $id = input('id', 0, 'intval'); //招标id $price = input('price', '', 'trim'); //报价/斤 $number = input('number', 0, 'intval'); //购买数量 $pig_pulling_time = input('pig_pulling_time', '', 'strtotime'); //预计拉猪时间 if (!$id) { $this->error('参数缺失'); } if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price <= 0) { $this->error('请输入正确报价'); } if ($number <= 0) { $this->error('请输入购买数量'); } if ($pig_pulling_time < time()) { $this->error('请选择正确拉猪时间'); } if ($this->auth->is_auth != 2) { $this->error('请先完成实名认证'); } $info = Db::name('mark')->find($id); if (!$info) { $this->error('招标信息不存在'); } if ($info['status'] != 1) { $this->error('招标已经结束'); } if ($info['endtime'] < time()) { $this->error('招标已经结束'); } //查询是否投过标 $bid_info = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->order('createtime', 'desc')->find(); if ($bid_info) { if ($price <= $bid_info['price']) { $this->error('价格不能低于上次报价'); } if ($info['again_bid'] > 0) { if (time() - $bid_info['updatetime'] < $info['again_bid']) { $this->error('您刚投标过,请稍等一会'); } } } $data['user_id'] = $this->auth->id; $data['mark_id'] = $id; $data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999); $data['price'] = $price; $data['number'] = $number; $data['pig_pulling_time'] = $pig_pulling_time; $data['province'] = $info['province']; $data['city'] = $info['city']; $data['area'] = $info['area']; $data['createtime'] = time(); $data['updatetime'] = time(); //开启事务 Db::startTrans(); //添加投标记录 $rs = Db::name('mark_bid_record')->insertGetId($data); if (!$rs) { Db::rollback(); $this->error('投标失败'); } if ($bid_info) { //已经投标过, 更新实时投标数据 $_data['order_sn'] = $data['order_sn']; $_data['price'] = $price; $_data['number'] = $number; $_data['pig_pulling_time'] = $pig_pulling_time; $_data['updatetime'] = time(); $result = Db::name('mark_bid')->where(['id' => $bid_info['id'], 'user_id' => $this->auth->id, 'price' => $bid_info['price']])->setField($_data); } else { $result = Db::name('mark_bid')->insertGetId($data); } if (!$result) { Db::rollback(); $this->error('投标失败'); } $rt = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->count('id'); if ($rt != 1) { Db::rollback(); $this->error('投标失败'); } Db::commit(); $this->success('投标成功'); } //猪只类型 public function pigbreedtype() { $list = Db::name('pig_breed_type')->field('id, name')->order('weigh', 'desc')->select(); $this->success('猪只类型', $list); } //立即投标筛选列表 public function marklist() { $pig_breed_type = input('pig_breed_type', '', 'trim'); //猪只类型 $province = input('province', '', 'trim'); //省 $city = input('city', '', 'trim'); //市 $area = input('area', '', 'trim'); //区 if (!$pig_breed_type) { $this->error('请选择猪只类型'); } if (!$province && !$city && !$area) { $this->error('请选择地区'); } $where['pig_breed_type'] = $pig_breed_type; $where['endtime'] = ['gt', time()]; $where['status'] = 1; if ($province) { $where['province'] = $province; } if ($city) { $where['city'] = $city; } if ($area) { $where['area'] = $area; } $list = Db::name('mark')->field('id, area, pig_type, heft, number, price') ->where($where)->order('createtime', 'desc')->select(); $this->success('立即投标筛选列表', $list); } //立即投标页面备注 public function bidremark() { $info = Db::name('platform_info')->field('content')->where(['type' => 3])->find(); $this->success('立即投标页面备注', $info); } //投标管理列表 public function bidlist() { $type = input('type', 1, 'intval'); //类型 1全部 2竞标中 3=中标 4=未中标 $time = input('time', '', 'strtotime'); //时间 $province = input('province', '', 'trim'); //省 $city = input('city', '', 'trim'); //市 $area = input('area', '', 'trim'); //区 $where['user_id'] = $this->auth->id; if ($type > 1) { $where['status'] = $type - 2; //状态:0=竞标中,1=中标,2=未中标 } if (!$time) { $time = strtotime(date('Y-m-d 0:0:0', time())); } $where['createtime'] = ['between', [$time, $time + 86400]]; if ($province) { $where['province'] = $province; } if ($city) { $where['city'] = $city; } if ($area) { $where['area'] = $area; } $list = Db::name('mark_bid')->where($where) ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select(); $mark = Db::name('mark'); $mark_bid = Db::name('mark_bid'); foreach ($list as &$v) { $v['pig_pulling_time'] = date('Y-m-d H:i:s', $v['pig_pulling_time']); //排名 $v['ranking'] = $mark_bid->where(['mark_id' => $v['mark_id'], 'price' => ['egt', $v['price']]])->count('id'); $v['mark'] = $mark->find($v['mark_id']); $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']); $v['mark']['endtime'] = date('Y-m-d H:i:s', $v['mark']['endtime']); } $this->success('投标管理列表', $list); } //投标记录 public function bidrecord() { $id = input('id', 0, 'intval'); //招标id if (!$id) { $this->error('参数缺失'); } $info = Db::name('mark')->find($id); if (!$info) { $this->error('招标信息不存在'); } $list = Db::name('mark_bid')->field('id, price, number, createtime') ->where(['user_id' => $this->auth->id, 'mark_id' => $id]) ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select(); foreach ($list as &$v) { $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']); } $this->success('投标记录', $list); } //投标详情 public function bidinfo() { $id = input('id', 0, 'intval'); //投标记录id if (!$id) { $this->error('参数缺失'); } $where['user_id'] = $this->auth->id; $where['id'] = $id; $info = Db::name('mark_bid')->where($where)->find(); if (!$info) { $this->error('记录不存在'); } $mark = Db::name('mark'); $info['pig_pulling_time'] = date('Y-m-d H:i:s', $info['pig_pulling_time']); $info['mark'] = $mark->find($info['mark_id']); $info['mark'] = info_domain_image($info['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']); $info['mark']['endtime'] = date('Y-m-d H:i:s', $info['mark']['endtime']); $this->success('投标详情', $info); } //轮播图 public function banner() { $list = Db::name('banner')->field('id, title, image, url')->order('weigh', 'desc')->select(); $this->success('轮播图', $list); } //活动列表 public function activelist() { $type = input('type', 0, 'intval'); //分类:1=休闲,2=中度 $keyword = input('keyword', '', 'trim'); //关键字 $where['signupendtime'] = ['gt', time()]; $where['status'] = 0; if ($type) { $where['type'] = $type; } if ($keyword !== '') { $where['title|desc|remark|collectionplace|leader'] = ['like', '%'.$keyword.'%']; } $list = Db::name('active')->field('id, type, title, desc, remark, image, price, maxperson, currentperson') ->where($where)->page($this->page, $this->pagenum)->order('createtime', 'desc')->select(); foreach ($list as &$v) { if ($v['maxperson'] <= $v['currentperson']) { $v['is_full'] = 1; } else { $v['is_full'] = 0; } } $this->success('活动列表', $list); } //活动详情 public function activeinfo() { $id = input('id', 0, 'intval'); if (!$id) { $this->error('参数缺失'); } $info = Db::name('active')->find($id); if (!$info) { $this->error('数据不存在'); } $info['starttime'] = date('Y-m-d H:i', $info['starttime']); $info['endtime'] = date('Y-m-d H:i', $info['endtime']); $info['collectiontime'] = date('Y-m-d H:i', $info['collectiontime']); $info['signupendtime'] = date('Y-m-d H:i', $info['signupendtime']); $info['refundendtime'] = date('Y-m-d H:i', $info['refundendtime']); //查询已报名列表 $active_people = Db::name('active_people')->where(['active_id' => $id])->field('user_id, name, createtime')->select(); $user = Db::name('user'); foreach ($active_people as &$v) { $v['avatar'] = $user->where(['id' => $v['user_id']])->value('avatar'); $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']); } $info['active_people'] = $active_people; $this->success('招标详情', $info); } //报名活动之前检查 public function beforesignup() { $id = input('id', 0, 'intval'); //活动id if (!$id) { $this->error('请选择要报名的活动'); } $info = Db::name('active')->find($id); if (!$info) { $this->error('活动不存在'); } if ($info['signupendtime'] < time() || $info['status'] != 0) { $this->error('活动报名已经截止'); } if ($info['currentperson'] >= $info['maxperson']) { $this->error('活动名额已满'); } //检查自己信息是否完善 if (!$this->auth->realname) { $this->error('请在个人资料中完善真实姓名', '', 5); } if (!$this->auth->idcard) { $this->error('请在个人资料中完善身份证号', '', 5); } if (!$this->auth->emergencycontact) { $this->error('请在个人资料中完善紧急联系人', '', 5); } if (!$this->auth->contactmobile) { $this->error('请在个人资料中完善紧急联系方式', '', 5); } $this->success('检查通过'); } //报名活动 public function signupactive() { //检查自己信息是否完善 if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) { $this->error('请在个人资料中完善资料', '', 5); } $id = input('id', 0, 'intval'); //活动id //人员信息json串: // name姓名 credtype证件类型 idcard身份证号 mobile手机号 emergencycontact紧急联系人 contactmobile紧急联系方式 // insurance保险 originalprice原价 vipprice会员价 coupon_id用户优惠券ID is_free是否使用免费次数:0=否,1=是 // price小计 is_self是否本人:0=否,1=是 $active_people = input('active_people', '', 'trim'); $paytype = input('paytype', 0, 'intval'); //支付方式:0=余额,1=微信 $total_price = input('total_price', 0, 'trim'); //总价格 if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $total_price) || $total_price < 0) { $this->error('合计价格错误'); } if (!in_array($paytype, [0, 1])) { $this->error('支付错误'); } if ($total_price == 0 && $paytype != 0) { $this->error('请选择余额支付'); } //检查活动信息 if (!$id) { $this->error('请选择要报名的活动'); } $info = Db::name('active')->find($id); if (!$info) { $this->error('活动不存在'); } if ($info['signupendtime'] < time() || $info['status'] != 0) { $this->error('活动报名已经截止'); } if ($info['currentperson'] >= $info['maxperson']) { $this->error('活动名额已满'); } //检查人员信息 if (!$active_people) { $this->error('请添加报名人员信息'); } $active_people = json_decode($active_people, true); if (!$active_people) { $this->error('请添加报名人员信息'); } if ($info['currentperson'] + count($active_people) > $info['maxperson']) { $this->error('活动名额不足'); } $_data = []; $total_amount = 0; //总价格验证 $active_people = Db::name('active_people'); //报名人员表 $active_people_modify = Db::name('active_people_modify'); //报名修改信息表 $vip = Db::name('vip'); $user_coupon = Db::name('user_coupon'); foreach ($active_people as &$v) { $data = []; //判断是否报名过 $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id'); if ($count) { $this->error($v['name'] . $v['idcard'] . '已报名过该活动'); break; } $count2 = $active_people_modify->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => 0])->count('id'); if ($count2) { $this->error($v['name'] . $v['idcard'] . '已提交过修改,请等待审核'); break; } //判断证件类型和保险 if (!$v['credtype'] || iconv_strlen($v['credtype'], 'utf-8') > 50) { $this->error('证件类型错误'); break; } if (!$v['insurance'] || iconv_strlen($v['insurance'], 'utf-8') > 50) { $this->error('保险信息错误'); break; } //判断用户信息 if ($v['is_self']) { //本人判断年龄 价格 if ($info['maxage'] > 0) { $age = $this->idcardage($this->auth->idcard); if ($age < $info['minage'] || $age > $info['maxage']) { $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']); break; } } if ($v['is_free'] == 1) { //使用免费次数 if ($info['is_free'] != 1) { $this->error('活动暂不支持免费体验'); break; } if ($v['vipprice'] != 0 || $v['price'] != 0) { $this->error($this->auth->realname . '价格错误'); break; } if ($v['coupon_id']) { $this->error('使用免费体验,无法使用优惠券'); break; } } else { //不使用免费次数 //会员价和优惠券是否可以叠加使用:0=否,1=是 if ($info['is_overlying'] == 0 && $v['vipprice'] != $info['price'] && $v['coupon_id']) { $this->error('该活动不支持会员价和优惠券同时使用'); break; } //计算会员价, 会员价优先顺序: 生日 > 女生特权日 > 会员价格 $birthday = date('md', $this->auth->birthday); $now_day = date('md', time()); if ($birthday == $now_day) { //生日折扣 $vip_info = $vip->find($this->auth->maxlevel); if (!$vip_info) { $this->error('会员信息缺失,请联系管理员'); break; } if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) { $this->error('会员生日折扣错误,请联系管理员'); break; } $discount = $vip_info['birthdiscount']; } elseif ($info['girldiscount'] < 100 && $info['girldiscount'] > 0 && $this->auth->gender == 2) { //女生特权日折扣 $discount = $info['girldiscount']; } else { //会员折扣 $vip_info = $vip->find($this->auth->maxlevel); if (!$vip_info) { $this->error('会员信息缺失,请联系管理员'); break; } if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) { $this->error('会员折扣错误,请联系管理员'); break; } $discount = $vip_info['vipdiscount']; } $vipprice = $info['price'] * $discount / 100; //会员价 //查询优惠券 if ($v['coupon_id']) { $user_coupon_info = $user_coupon->where(['id' => $v['coupon_id'], 'user_id' => $this->auth->id])->find(); if (!$user_coupon_info) { $this->error('优惠券不存在'); } if ($user_coupon_info['status'] != 0) { $this->error('优惠券已使用'); } if ($user_coupon_info['endtime'] < time()) { $this->error('优惠券已过期'); } if ($user_coupon_info['type'] == 1) { //打折券 if ($user_coupon_info['money'] < 0 || $user_coupon_info['money'] > 100) { $this->error('优惠券折扣错误,请联系管理员'); break; } } else { //抵扣券 //会员价和优惠券是否可以叠加使用:0=否,1=是 if ($info['is_overlying'] == 0) { if ($info['price'] < $user_coupon_info['minmoney']) { $this->error('优惠券使用条件不满足'); break; } } else { if ($vipprice < $user_coupon_info['minmoney']) { $this->error('优惠券使用条件不满足'); break; } } } } //判断价格 //会员价和优惠券是否可以叠加使用:0=否,1=是 if ($info['is_overlying'] == 0) { if ($v['coupon_id']) { //使用优惠券 if ($v['vipprice'] != $info['price']) { $this->error('会员价显示错误'); break; } if ($user_coupon_info['type'] == 1) { //打折券 $price = $info['price'] * $user_coupon_info['money'] / 100; } else { //抵扣券 $price = $info['price'] - $user_coupon_info['money']; } } else { $price = $vipprice; } } else { if ($vipprice != $v['vipprice']) { $this->error('会员价显示错误'); break; } if ($v['coupon_id']) { //使用优惠券 if ($user_coupon_info['type'] == 1) { //打折券 $price = $vipprice * $user_coupon_info['money'] / 100; } else { //抵扣券 $price = $vipprice - $user_coupon_info['money']; } } else { $price = $vipprice; } } //判断小计 if ($price != $v['price']) { $this->error('小计显示错误'); break; } $data['vipprice'] = $v['vipprice']; //会员价 $data['coupon_id'] = $v['coupon_id']; //优惠券id if ($v['coupon_id']) { $data['coupontype'] = $user_coupon_info['type']; $data['couponprice'] = $user_coupon_info['money']; } } $data['name'] = $this->auth->realname; $data['idcard'] = $this->auth->idcard; $data['mobile'] = $this->auth->mobile; $data['emergencycontact'] = $this->auth->emergencycontact; $data['contactmobile'] = $this->auth->contactmobile; } else { //帮人报名判断年龄 报名信息 if ($info['maxage'] > 0) { $age = $this->idcardage($v['idcard']); if ($age < $info['minage'] || $age > $info['maxage']) { $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']); break; } } if (!$v['name'] || iconv_strlen($v['name'], 'utf-8') > 50) { $this->error('请输入正确姓名'); break; } if (iconv_strlen($v['idcard'], 'utf-8') != 18) { $this->error('请输入正确身份证号'); break; } if (!is_mobile($v['mobile'])) { $this->error('请输入正确手机号'); break; } if (!$v['emergencycontact'] || iconv_strlen($v['emergencycontact'], 'utf-8') > 50) { $this->error('请输入紧急联系人'); break; } if (!is_mobile($v['contactmobile'])) { $this->error('请输入正确紧急联系人方式'); break; } if ($v['price'] != $info['price']) { $this->error('小计显示错误'); break; } $data['name'] = $v['name']; $data['idcard'] = $v['idcard']; $data['mobile'] = $v['mobile']; $data['emergencycontact'] = $v['emergencycontact']; $data['contactmobile'] = $v['contactmobile']; $data['vipprice'] = $info['price']; //会员价 } $data['active_id'] = $id; $data['user_id'] = $this->auth->id; $data['credtype'] = $v['credtype']; $data['insurance'] = $v['insurance']; $data['originalprice'] = $info['price']; $data['is_free'] = $v['is_free']; $data['price'] = $v['price']; //小计 $data['is_self'] = $v['is_self']; $data['createtime'] = time(); array_push($_data, $data); $total_amount += $v['price']; } if ($total_amount != $total_price) { $this->error('合计价格错误'); } if ($paytype == 0) { //余额支付 if ($this->auth->money < $total_amount) { $this->error('余额不足,请先去充值'); } } //构建订单信息 $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999); $order_data['active_id'] = $id; $order_data['user_id'] = $this->auth->id; $order_data['paytype'] = $paytype; $order_data['price'] = $total_amount; $order_data['number'] = count($active_people); $order_data['status'] = $paytype == 1 ? 0 : 1; $order_data['createtime'] = time(); //开始事务 Db::startTrans(); //添加订单 $rs = Db::name('active_order')->insertGetId($order_data); if (!$rs) { Db::rollback(); $this->error('网络延迟,请稍后再试'); } //添加人员信息 foreach ($_data as &$v) { $v['order_id'] = $rs; $rt = $active_people->insertGetId($v); if (!$rt) { Db::rollback(); $this->error('网络延迟,请稍后再试'); } } //扣款 支付方式:0=余额,1=微信 if ($paytype == 0) { $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2); if ($res != 1) { Db::rollback(); $this->error('余额资金异常,请联系管理员'); } Db::commit(); $this->success('报名成功'); } else { //生成支付订单记录 $rechar_order['user_id'] = $this->auth->id; $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号 $rechar_order['money'] = $total_amount; $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员 $rechar_order['pay_type'] = 'wechat'; $rechar_order['relation_id'] = $rs; $rechar_order['createtime'] = time(); $rechar_order['money'] = $total_amount; $result = Db::name('rechar_order')->insertGetId($rechar_order); if (!$result) { Db::rollback(); $this->error('网络延迟,请稍后再试'); } //构建支付链接数据 $wxData['body'] = '报名活动支付'; $wxData['out_trade_no'] = $rechar_order['order_no']; $wxData['total_fee'] = $total_amount; // $wxData['total_fee'] = 0.01; $wxData['openid'] = $this->auth->openid; // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php'); $wxPay = new wxpay\WxPay(config('wxchatpay')); $doResult = $wxPay->WxPayJs($wxData); $this->success('微信支付参数返回成功', $doResult); } } //根据身份证号获取年龄 public function idcardage($idcard = '') { //截取身份证里的出生日期 $year = substr($idcard, 6, 4); $month = substr($idcard, 10, 2); $day = substr($idcard, 12, 2); //获取当前日期 $current_year = date('Y'); $current_month = date('m'); $current_day = date('d'); //计算年龄 $age = $current_year - $year;//今年减去生日年 if ($month > $current_month || ($month == $current_month && $day > $current_day)) { //如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁 $age--; } return $age; } //私人订制类型 public function personaltype() { $list = Db::name('personal_type')->field('id, name')->order('weigh', 'desc')->select(); $this->success('私人订制类型', $list); } //私人订制活动类型 public function personalactivetype() { $list = Db::name('personal_active_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select(); $list = $this->getchildtype($list); $this->success('私人订制活动类型', $list); } //无限级私人订制活动类型 public function getchildtype($list = []) { $complaint_type = Db::name('personal_active_type'); foreach ($list as &$v) { $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select(); if ($child) { $child = $this->getchildtype($child); } $v['child'] = $child; } return $list; } //私人订制 public function personalactive() { } }