12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Think\Cache;
- use think\Db;
- use wxpay;
- use Qcloud\Cos\Client;
- use Qcloud\Cos\Exception\ServiceResponseException;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection', 'activeinfo'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- //轮播图
- public function banner()
- {
- $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 0])->order('weigh', 'desc')->select();
- $list = list_domain_image($list, ['image']);
- $this->success('轮播图', $list);
- }
- //活动列表
- public function activelist() {
- $type = input('type', 0, 'intval'); //分类:1=休闲,2=中度
- $keyword = input('keyword', '', 'trim'); //关键字
- // $where['signupendtime'] = ['gt', time()];
- $where['status'] = ['neq', 3];
- $where['showstatus'] = 1;
- 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, status')
- ->where($where)->page($this->page, $this->pagenum)->order('weigh, createtime desc')->select();
- $list = list_domain_image($list, ['image']);
- foreach ($list as &$v) {
- if ($v['maxperson'] <= $v['currentperson']) {
- $v['is_full'] = 1;
- } else {
- $v['is_full'] = 0;
- }
- $v['surplusperson'] = $v['maxperson'] - $v['currentperson'];
- }
- $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 = info_domain_image($info, ['image']);
- $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, 'status' => ['neq', 3]])->field('user_id, name, createtime')->select();
- $user = Db::name('user');
- foreach ($active_people as &$v) {
- $user_info = $user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
- $v['name'] = $user_info['nickname'];
- $v['avatar'] = $user_info['avatar'];
- $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
- }
- $info['active_people'] = $active_people;
- $info['customer_service'] = config('site.customer_service') ? config('site.customer_service') : ''; //客服电话
- $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['status'] == 2) {
- $this->error('活动已经结束');
- }
- if ($info['status'] == 3) {
- $this->error('活动已经取消');
- }
- if ($info['showstatus'] != 1) {
- $this->error('活动暂时不能报名');
- }
- if ($info['signupendtime'] < time()) {
- $this->error('活动报名已经截止');
- }
- if ($info['currentperson'] >= $info['maxperson']) {
- $this->error('活动名额已满');
- }
- //检查自己信息是否完善
- if (!$this->auth->realname) {
- $this->success('请在个人资料中完善真实姓名', ['code' => 3]);
- }
- if (!$this->auth->idcard) {
- $this->success('请在个人资料中完善身份证号', ['code' => 3]);
- }
- if (!$this->auth->emergencycontact) {
- $this->success('请在个人资料中完善紧急联系人', ['code' => 3]);
- }
- if (!$this->auth->contactmobile) {
- $this->success('请在个人资料中完善紧急联系方式', ['code' => 3]);
- }
- $this->success('检查通过');
- }
- //查询可用优惠券
- public function canusercoupon() {
- $price = input('price', '', 'trim'); //价格
- if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price < 0) {
- $this->error('价格错误');
- }
- $where['user_id'] = $this->auth->id;
- $where['endtime'] = ['egt', time()];
- $where['status'] = 0;
- $map = 'type = 1 or (type = 2 and minmoney <= '.$price.')';
- $list = Db::name('user_coupon')->field('id, title, desc, type, money, minmoney')->where($where)->where($map)->select();
- // p(\db()->getLastSql());
- $this->success('查询可用优惠券', $list);
- }
-
- //报名活动
- public function signupactive() {
- //检查自己信息是否完善
- if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) {
- $this->success('请在个人资料中完善资料', ['code' => 3]);
- }
- $id = input('id', 0, 'intval'); //活动id
- // $collectionplace = input('collectionplace', '', 'trim'); //集合地点
- //人员信息json串:
- // name姓名 credtype证件类型 idcard身份证号 mobile手机号 emergencycontact紧急联系人 contactmobile紧急联系方式
- // insurance保险 originalprice原价 vipprice会员价 coupon_id用户优惠券ID is_free是否使用免费次数:0=否,1=是
- // price小计 is_self是否本人:0=否,1=是 collectionplace集合地点
- $active_people = input('active_people', '', 'trim');
- $paytype = input('paytype', 0, 'intval'); //支付方式:0=余额,1=微信
- $total_price = input('total_price', 0, 'trim'); //总价格
- // if ($collectionplace === '' || iconv_strlen($collectionplace, 'utf-8') > 255) {
- // $this->error('请选择集合地点');
- // }
- 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['status'] == 2) {
- $this->error('活动已经结束');
- }
- if ($info['status'] == 3) {
- $this->error('活动已经取消');
- }
- if ($info['showstatus'] != 1) {
- $this->error('活动暂时不能报名');
- }
- if ($info['signupendtime'] < time()) {
- $this->error('活动报名已经截止');
- }
- if ($info['currentperson'] >= $info['maxperson']) {
- $this->error('活动名额已满');
- }
- //检查人员信息
- if (!$active_people) {
- $this->error('请添加报名人员信息');
- }
- $active_people_arr = json_decode($active_people, true);
- if (!$active_people_arr) {
- $this->error('请添加报名人员信息');
- }
- if ($info['currentperson'] + count($active_people_arr) > $info['maxperson']) {
- $this->error('活动名额不足');
- }
- //会员信息
- $vip_info = Db::name('vip')->find($this->auth->maxlevel);
- if (!$vip_info) {
- $this->error('会员信息缺失,请联系管理员');
- }
- $_data = [];
- $total_amount = 0; //总价格验证
- $active_people = Db::name('active_people'); //报名人员表
- $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
- $user_coupon = Db::name('user_coupon');
- foreach ($active_people_arr as $k => &$v) {
- $data = [];
- //检查信息
- 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;
- }
- //判断是否报名过
- $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => ['neq', 3]])->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['collectionplace'] === '' || iconv_strlen($v['collectionplace'] , 'utf-8') > 255) {
- $this->error($v['name'] . '请选择集合地点');
- break;
- }
- //判断用户信息
- if ($v['is_self'] && $k == 0) {
- //判断用户信息
- if ($v['name'] != $this->auth->realname || $v['idcard'] != $this->auth->idcard || $v['mobile'] != $this->auth->mobile || $v['emergencycontact'] != $this->auth->emergencycontact || $v['contactmobile'] != $this->auth->contactmobile) {
- $this->error('本人信息错误');
- break;
- }
- //本人判断年龄 价格
- 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 ($this->auth->freenumber <= 0) {
- $this->error('您的免费次数不足');
- break;
- }
- //检查当月是否用过免费次数
- $month_time = strtotime(date('Y-m-1', time()));
- $count = $active_people->where(['user_id' => $this->auth->id, 'is_free' => 1, 'createtime' => ['egt', $month_time]])->count('id');
- if ($count) {
- $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', strtotime($this->auth->birthday));
- $now_day = date('md', $info['starttime']); //活动当天生日
- if ($birthday == $now_day) {
- //生日折扣
- 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 {
- //会员折扣
- if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
- $this->error('会员折扣错误,请联系管理员');
- break;
- }
- $discount = $vip_info['vipdiscount'];
- }
- $vipprice = number_format($info['price'] * $discount / 100, 2, '.', ''); //会员价
- //查询优惠券
- 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) {
- //打折券
- $coupon_price = number_format($info['price'] * (100 - $user_coupon_info['money']) / 100, 2, '.', '');
- $price = number_format($info['price'] - $coupon_price, 2, '.', '');
- } else {
- //抵扣券
- $price = number_format($info['price'] - $user_coupon_info['money'], 2, '.', '');
- }
- } else {
- $price = $vipprice;
- }
- } else {
- if ($vipprice != $v['vipprice']) {
- $this->error('会员价显示错误');
- break;
- }
- if ($v['coupon_id']) { //使用优惠券
- if ($user_coupon_info['type'] == 1) {
- //打折券
- $coupon_price = number_format($vipprice * (100 - $user_coupon_info['money']) / 100, 2, '.', '');
- $price = number_format($vipprice - $coupon_price, 2, '.', '');
- } else {
- //抵扣券
- $price = number_format($vipprice - $user_coupon_info['money'], 2, '.', '');
- }
- } 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 ($vip_info['manypeople'] > 1 && $k == $vip_info['manypeople'] - 1) {
- if ($v['price'] != 0) {
- $this->error('小计显示错误');
- break;
- }
- } else {
- 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'] = $v['price']; //会员价
- }
- $data['active_id'] = $id;
- $data['user_id'] = $this->auth->id;
- $data['collectionplace'] = $v['collectionplace'];
- $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->success('您的余额不足,请先去充值', ['code' => 2]);
- }
- }
- //构建订单信息
- $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
- $order_data['active_id'] = $id;
- $order_data['user_id'] = $this->auth->id;
- // $order_data['collectionplace'] = $collectionplace;
- $order_data['paytype'] = $paytype;
- $order_data['price'] = $total_amount;
- $order_data['number'] = count($active_people_arr);
- $order_data['status'] = $paytype == 1 ? 0 : 1;
- $order_data['createtime'] = time();
- //构建活动信息
- $active_data['currentperson'] = $info['currentperson'] + count($active_people_arr);
- if ($info['currentperson'] + count($active_people_arr) >= $info['minperson'] && $info['status'] == 0) {
- $active_data['status'] = 1;
- }
- //开始事务
- Db::startTrans();
- //修改活动表数据
- $active_rs = Db::name('active')->where(['id' => $id, 'status' => $info['status'],'currentperson' => $info['currentperson']])->setField($active_data);
- if (!$active_rs) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- //添加订单
- $rs = Db::name('active_order')->insertGetId($order_data);
- if (!$rs) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- //添加人员信息
- foreach ($_data as &$v) {
- $v['order_id'] = $rs;
- $v['status'] = $order_data['status'];
- $rt = $active_people->insertGetId($v);
- if (!$rt) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- }
- //扣除免费次数
- if ($info['is_free'] == 1 && $active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['is_free'] == 1) {
- $freenumber = $this->auth->freenumber - 1;
- $user_rs = Db::name('user')->where(['id' => $this->auth->id, 'freenumber' => $this->auth->freenumber])->setField('freenumber', $freenumber);
- if (!$user_rs) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- }
- //扣除优惠券
- if ($active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['coupon_id']) {
- $user_coupon_rs = Db::name('user_coupon')->where(['id' => $active_people_arr[0]['coupon_id'], 'user_id' => $this->auth->id, 'status' => 0])->setField(['active_id' => $id, 'order_id' => $rs, 'status' => 1]);
- if (!$user_coupon_rs) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- }
- //扣款 支付方式:0=余额,1=微信
- if ($paytype == 0) {
- $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2, $rs);
- if ($res != 1) {
- Db::rollback();
- $this->error('余额资金异常,请联系管理员');
- }
- //给上级发送优惠券
- if ($this->auth->pre_user_id) {
- //查询报名活动优惠券
- $invite_coupon = Db::name('coupon')->where(['purpose' => 5, 'status' => 1])->order('weigh desc, id desc')->find();
- if ($invite_coupon) {
- $invite_coupon_data = [
- 'user_id' => $this->auth->pre_user_id,
- 'coupon_id' => $invite_coupon['id'],
- 'title' => $invite_coupon['title'],
- 'desc' => $invite_coupon['desc'],
- 'type' => $invite_coupon['type'],
- 'money' => $invite_coupon['money'],
- 'minmoney' => $invite_coupon['minmoney'],
- 'purpose' => $invite_coupon['purpose'],
- 'starttime' => time(),
- 'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
- 'active_id' => $id,
- 'order_id' => $rs,
- 'createtime' => time()
- ];
- $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
- if (!$invite_coupon_rs) {
- Db::rollback();
- $this->error('发放优惠券失败');
- }
- }
- }
- //发送消息
- $data = [
- 'user_id' => $this->auth->id,
- 'type' => 1,
- 'title' => '活动通知',
- 'content' => '您已成功报名' . $info['title'] . '活动',
- 'createtime' => time()
- ];
- $sys_rs = Db::name('sys_msg')->insertGetId($data);
- if (!$sys_rs) {
- 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();
- $result = Db::name('rechar_order')->insertGetId($rechar_order);
- if (!$result) {
- Db::rollback();
- $this->error('网络延迟,请稍后再试');
- }
- Db::commit();
- //构建支付链接数据
- $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 car() {
- $list = Db::name('car')->field('id, name, desc')->order('weigh', 'desc')->select();
- $this->success('车辆类型', $list);
- }
- //领队
- public function leader() {
- $list = Db::name('leader')->field('id, name')->order('weigh', 'desc')->select();
- $this->success('领队', $list);
- }
-
- //私人订制出行方向
- public function personaldirection() {
- $list = Db::name('personal_direction')->field('id, name')->order('weigh', 'desc')->select();
- $this->success('私人订制出行方向', $list);
- }
- //私人订制
- public function personalactive() {
- $type = input('type', '', 'trim'); //类型
- $number = input('number', 0, 'intval'); //出行人数
- $traveltime = input('traveltime', '', 'strtotime'); //出行时间
- $traveday = input('traveday', 0, 'intval'); //出行天数
- $activetype = input('activetype', '', 'trim'); //活动类型
- $car = input('car', '', 'trim'); //车辆
- $leader = input('leader', '', 'trim'); //领队
- $travedirection = input('travedirection', '', 'trim'); //出行方向
- $freerange = input('freerange', '', 'trim'); //空闲时段
- $remark = input('remark', '', 'trim'); //留言
- if (!$type || iconv_strlen($type, 'utf-8') > 50) {
- $this->error('请选择类型');
- }
- if ($number <= 0) {
- $this->error('请填写出行人数');
- }
- if ($traveltime < time()) {
- $this->error('请选择正确出行时间');
- }
- if ($traveday <= 0) {
- $this->error('请填写正确出行天数');
- }
- if (!$activetype || iconv_strlen($activetype, 'utf-8') > 50) {
- $this->error('请选择活动类型');
- }
- if ($car && iconv_strlen($car, 'utf-8') > 50) {
- $this->error('请选择车辆');
- }
- if ($leader && iconv_strlen($leader, 'utf-8') > 50) {
- $this->error('请选择领队');
- }
- if (!$travedirection || iconv_strlen($travedirection, 'utf-8') > 50) {
- $this->error('请选择出行方向');
- }
- if (!$freerange || iconv_strlen($freerange, 'utf-8') > 50) {
- $this->error('请选择空闲时段');
- }
- if (iconv_strlen($remark, 'utf-8') > 500) {
- $this->error('留言最多500字');
- }
- $data['user_id'] = $this->auth->id;
- $data['type'] = $type;
- $data['number'] = $number;
- $data['traveltime'] = $traveltime;
- $data['traveday'] = $traveday;
- $data['activetype'] = $activetype;
- $data['car'] = $car;
- $data['leader'] = $leader;
- $data['travedirection'] = $travedirection;
- $data['freerange'] = $freerange;
- $data['remark'] = $remark;
- $data['createtime'] = time();
- $rs = Db::name('personal_order')->insertGetId($data);
- if (!$rs) {
- $this->error('提交失败');
- }
- $this->success('提交成功');
- }
- //查询轮播图优惠券列表
- public function bannercoupon() {
- $list = Db::name('coupon')->field('id, title, desc, type, money')
- ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
- $user_coupon = Db::name('user_coupon');
- foreach ($list as &$v) {
- $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
- }
- $this->success('查询轮播图优惠券列表', $list);
- }
- //领取轮播图优惠券
- public function receivebannercoupon() {
- $id = input('id', 0, 'intval'); //优惠券id
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
- if (!$info) {
- $this->error('优惠券不存在');
- }
- if ($info['status'] != 1) {
- $this->error('优惠券已下架');
- }
- //查询是否已领取
- $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
- if ($count) {
- $this->error('您已经领取过了');
- }
- $data['user_id'] = $this->auth->id;
- $data['coupon_id'] = $id;
- $data['title'] = $info['title'];
- $data['desc'] = $info['desc'];
- $data['type'] = $info['type'];
- $data['money'] = $info['money'];
- $data['minmoney'] = $info['minmoney'];
- $data['purpose'] = $info['purpose'];
- $data['starttime'] = time();
- $data['endtime'] = time() + $info['effectiveday'] * 86400;
- $data['createtime'] = time();
- //开启事务
- Db::startTrans();
- //添加领取记录
- $rs = Db::name('user_coupon')->insertGetId($data);
- if (!$rs) {
- Db::rollback();
- $this->error('领取失败');
- }
- $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
- if ($rt != 1) {
- Db::rollback();
- $this->error('领取失败');
- }
- Db::commit();
- $this->success('领取成功');
- }
-
- //体验会员列表
- public function experiencevip() {
- $where = [];
- if ($this->auth->maxlevel != 5) {
- $where['id'] = ['neq', 5];
- }
- $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->where($where)->select();
- $vip_privilege = Db::name('vip_privilege');
- foreach ($list as &$v) {
- $v['vip_privilege'] = $vip_privilege->field('id, title, desc')
- ->where(['vip_id' => $v['id']])->order('weigh desc')->select();
- }
- $this->success('体验会员列表', $list);
- }
- //购买体验会员
- public function buyexperiencevip() {
- //检查是否已经开通体验会员
- if ($this->auth->experiencetime >= time()) {
- $this->error('您已开通体验会员,不能重复开通');
- }
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('vip')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('会员不存在');
- }
- if ($info['status'] != 1) {
- $this->error('体验会员已下架');
- }
- if ($info['price'] <= 0) {
- $this->error('会员价格异常');
- }
- //体验会员等级必须大于成长值会员
- if ($id <= $this->auth->maxlevel) {
- $this->error('请开通更高等级体验会员');
- }
- //判断余额
- if ($this->auth->money < $info['price']) {
- $this->success('您的余额不足,请先去充值', ['code' => 2]);
- }
- $data['user_id'] = $this->auth->id;
- $data['vip_id'] = $id;
- $data['title'] = $info['title'];
- $data['level'] = $info['level'];
- $data['growthvalue'] = $info['growthvalue'];
- $data['free'] = $info['free'];
- $data['price'] = $info['price'];
- $data['endtime'] = time() + $info['day'] * 86400;
- $data['vipdiscount'] = $info['vipdiscount'];
- $data['birthdiscount'] = $info['birthdiscount'];
- $data['manypeople'] = $info['manypeople'];
- $data['createtime'] = time();
- //开启事务
- Db::startTrans();
- //添加开通记录
- $rs = Db::name('vip_log')->insertGetId($data);
- if (!$rs) {
- Db::rollback();
- $this->error('开通失败');
- }
- //扣除余额
- $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4, $rs);
- if ($result != 1) {
- Db::rollback();
- $this->error('资金异常,请联系管理员');
- }
- //成长值会员信息
- $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
- //修改用户表信息
- $user_data['experiencelevel'] = $id;
- $user_data['experiencetime'] = $data['endtime'];
- $user_data['maxlevel'] = $id;
- $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
- $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
- $rt = Db::name('user')->where([
- 'id' => $this->auth->id,
- 'experiencelevel' => $this->auth->experiencelevel,
- 'maxlevel' => $this->auth->maxlevel,
- 'freenumber' => $this->auth->freenumber])->setField($user_data);
- if (!$rt) {
- Db::rollback();
- $this->error('开通失败');
- }
- Db::commit();
- $this->success('开通成功');
- }
- //获取活动分享链接
- public function activelink() {
- $id = input('id', 0, 'intval'); //活动id
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('active')->find($id);
- if (!$info) {
- $this->error('活动不存在');
- }
- if ($info['status'] == 2) {
- $this->error('活动已结束');
- }
- if ($info['status'] == 3) {
- $this->error('活动已取消');
- }
- if ($info['showstatus'] != 1) {
- $this->error('活动暂时不能报名');
- }
- $access_token = Cache::get('access_token');
- if (!$access_token) {
- //获取$access_token
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxchatpay.app_id').'&secret='.config('wxchatpay.app_secret');
- $result = file_get_contents($url);
- $result = json_decode($result, true);
- $access_token = $result['access_token'];
- //缓存
- Cache::set('access_token', $access_token, 7000);
- }
- if (!$access_token) {
- $this->error('参数缺失');
- }
- $data['page_url'] = 'pages/home/detail?id='.$id.'&code='.$this->auth->invite_no;
- $data['page_title'] = $info['title'];
- $data = json_encode($data, 320);
- $url = 'https://api.weixin.qq.com/wxa/genwxashortlink?access_token='.$access_token;
- $rs = httpRequest($url, 'POST', $data);
- $rs = json_decode($rs, true);
- if ($rs['errcode'] != 0) {
- $this->error('网络延迟');
- }
- $this->success('分享链接', $rs['link']);
- }
- //生成小程序邀请二维码
- public function getqrcode($id = 0) {
- $access_token = Cache::get('access_token');
- // $access_token = '';
- if (!$access_token) {
- //获取$access_token
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxchatpay.app_id').'&secret='.config('wxchatpay.app_secret');
- // $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx326ed0bf442d2773&secret=33609a3bc45bb407f0b26816158405b8';
- $result = file_get_contents($url);
- $result = json_decode($result, true);
- $access_token = $result['access_token'];
- //缓存
- Cache::set('access_token', $access_token, 7000);
- }
- if (!$access_token) {
- $this->error('参数缺失');
- }
- $data['scene'] = 'id='.$id.'&code='.$this->auth->invite_no;
- // $data['scene'] = 'id=AVwvR&code='.$this->auth->invite_no;
- $data['page'] = 'pages/home/detail';
- // $data['page'] = 'pages/product/product';
- $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
- $ch = curl_init($url);
- $timeout = 6000;
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- $ret = curl_exec($ch);
- curl_close($ch);
- if (is_array($ret)) {
- return '';
- }
- if (json_decode($ret)) {
- $this->error('生成失败');
- }
- $secretId = "AKIDhDTSBdoTs0rS4bx3rQijSu61f3B2cv3y"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
- $secretKey = "f3A1btufAOL2SbT4ORDiwtZy7yYooY1D"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
- $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
- $cosClient = new Client(
- array(
- 'region' => $region,
- 'schema' => 'https', //协议头部,默认为http
- 'credentials'=> array(
- 'secretId' => $secretId ,
- 'secretKey' => $secretKey)));
- // $local_path = "/Users/xxx/Desktop/exampleobject.txt"; //保存到用户本地路径
- $path = "qrcode/"; // 二维码文件流存放位置
- $fileName = time() . rand(10000,99999) . ".png";
- $result = $cosClient->putObject(array(
- 'Bucket' => 'fireflytra-1309974405', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
- 'Key' => $path . $fileName,//'exampleobject',
- 'Body' => $ret,//fopen($local_path, 'rb'),
- ));
- // 请求成功
- return 'https://' . $result['Location'];
- // //上传到阿里云oss
- // require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/autoload.php';
- // require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/src/OSS/OssClient.php';
- // $config = C('ALIOSS_CONFIG');
- //
- // $oss = new \OSS\OssClient($config['KEY_ID'], $config['KEY_SECRET'], $config['END_POINT']);
- //
- // $path = "shopqrcode/"; // 二维码文件流存放位置
- // $fileName = time() . rand(10000,99999) . ".png";
- //
- // // 上传到oss
- // $result = $oss->putObject($config['BUCKET'], $path . $fileName, $ret);
- //
- // // 获取图片url地址
- // $oss_url = json_decode(json_encode($result), true);
- //
- // return $oss_url['oss-request-url'];
- }
- //生成活动海报
- public function activeposter() {
- // $poster = Db::name('poster')->find(1);
- // p($poster);die;
- $id = input('id', 0, 'intval'); //活动id
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('active')->find($id);
- if (!$info) {
- $this->error('活动不存在');
- }
- if ($info['status'] == 2) {
- $this->error('活动已结束');
- }
- if ($info['status'] == 3) {
- $this->error('活动已取消');
- }
- if ($info['showstatus'] != 1) {
- $this->error('活动暂时不能报名');
- }
- $data = [
- [
- "left" => "4px",
- "top" => "4px",
- "type" => "img",
- "width" => "310px",
- "height" => "235px",
- "src" => one_domain_image($info['image']) //主图
- ],
- [
- "left" => "100px",
- "top" => "347px",
- "type" => "img",
- "width" => "115px",
- "height" => "115px",
- "src" => $this->getqrcode($id) //小程序二维码'https://fireflytra-1309974405.cos.ap-beijing.myqcloud.com/qrcode/165405491386733.png'
- ]
- ];
- //处理标题字符
- $child = [
- "left" => "11px",
- "top" => "253px",
- "type" => "nickname",
- "width" => "296px",
- "height" => "50px",
- "size" => "16px",
- "color" => "#000",
- "content" => mb_substr($info['title'], 0, 14)
- ];
- array_push($data, $child);
- if (iconv_strlen($info['title'], 'utf-8') > 14) {
- $child = [
- "left" => "11px",
- "top" => "285px",
- "type" => "nickname",
- "width" => "296px",
- "height" => "50px",
- "size" => "16px",
- "color" => "#000",
- "content" => mb_substr($info['title'], 14, 14)
- ];
- if (iconv_strlen($info['title'], 'utf-8') <= 28) {
- $child['content'] = mb_substr($info['title'], 14, 14);
- } else {
- $child['content'] = mb_substr($info['title'], 14, 11) . '...';
- }
- array_push($data, $child);
- }
- //添加价格
- $child = [
- "left" => "11px",
- "top" => "318px",
- "type" => "nickname",
- "width" => "296px",
- "height" => "50px",
- "size" => "16px",
- "color" => "#FF0000",
- "content" => $info['price'] . '元'
- ];
- array_push($data, $child);
- $data = json_encode($data, 320);
- $poster = [
- 'id' => 1,
- 'title' => '测试',
- 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
- 'bg_image' => '/assets/img/bg.png',
- 'data' => $data,
- 'status' => 'normal',
- 'weigh' => 0,
- 'createtime' => 1653993709,
- 'updatetime' => 1653994259,
- ];
- $image = new \addons\poster\library\Image();
- $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
- if (!$imgurl) {
- $this->error('生成海报出错');
- }
- $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
- $this->success('', $imgurl);
- }
-
- //查询帮报名过的人员信息
- public function getpeopleinfo() {
- $name = input('name', '', 'trim'); //名称
- if (!$name) {
- $this->success('信息', (object)[]);
- }
- $info = Db::name('active_people')->field('name, idcard, mobile, emergencycontact, contactmobile')->where(['user_id' => $this->auth->id, 'name' => $name])->find();
- if (!$info) {
- $info = (object)[];
- }
- $this->success('信息', $info);
- }
- }
|