|
@@ -6,6 +6,7 @@ use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
|
|
|
use app\common\controller\Api;
|
|
|
use function GuzzleHttp\Psr7\uri_for;
|
|
|
use think\Db;
|
|
|
+use wxpay;
|
|
|
|
|
|
|
|
|
* 首页接口
|
|
@@ -416,8 +417,421 @@ class Index extends Api
|
|
|
$this->success('招标详情', $info);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function beforesignup() {
|
|
|
+ $id = input('id', 0, 'intval');
|
|
|
+ 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');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $active_people = input('active_people', '', 'trim');
|
|
|
+ $paytype = input('paytype', 0, 'intval');
|
|
|
+ $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 {
|
|
|
+
|
|
|
+ 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 {
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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'];
|
|
|
+ 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('网络延迟,请稍后再试');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ $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['openid'] = $this->auth->openid;
|
|
|
|
|
|
+
|
|
|
+ $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;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|