Index.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
  4. use app\common\controller\Api;
  5. use function GuzzleHttp\Psr7\uri_for;
  6. use think\Db;
  7. use wxpay;
  8. /**
  9. * 首页接口
  10. */
  11. class Index extends Api
  12. {
  13. protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection'];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 首页
  17. *
  18. */
  19. public function index()
  20. {
  21. $this->success('请求成功');
  22. }
  23. //轮播图
  24. public function banner()
  25. {
  26. $list = Db::name('banner')->field('id, title, image, url')->order('weigh', 'desc')->select();
  27. $this->success('轮播图', $list);
  28. }
  29. //活动列表
  30. public function activelist() {
  31. $type = input('type', 0, 'intval'); //分类:1=休闲,2=中度
  32. $keyword = input('keyword', '', 'trim'); //关键字
  33. $where['signupendtime'] = ['gt', time()];
  34. $where['status'] = 0;
  35. if ($type) {
  36. $where['type'] = $type;
  37. }
  38. if ($keyword !== '') {
  39. $where['title|desc|remark|collectionplace|leader'] = ['like', '%'.$keyword.'%'];
  40. }
  41. $list = Db::name('active')->field('id, type, title, desc, remark, image, price, maxperson, currentperson, status')
  42. ->where($where)->page($this->page, $this->pagenum)->order('createtime', 'desc')->select();
  43. foreach ($list as &$v) {
  44. if ($v['maxperson'] <= $v['currentperson']) {
  45. $v['is_full'] = 1;
  46. } else {
  47. $v['is_full'] = 0;
  48. }
  49. }
  50. $this->success('活动列表', $list);
  51. }
  52. //活动详情
  53. public function activeinfo() {
  54. $id = input('id', 0, 'intval');
  55. if (!$id) {
  56. $this->error('参数缺失');
  57. }
  58. $info = Db::name('active')->find($id);
  59. if (!$info) {
  60. $this->error('数据不存在');
  61. }
  62. $info['starttime'] = date('Y-m-d H:i', $info['starttime']);
  63. $info['endtime'] = date('Y-m-d H:i', $info['endtime']);
  64. $info['collectiontime'] = date('Y-m-d H:i', $info['collectiontime']);
  65. $info['signupendtime'] = date('Y-m-d H:i', $info['signupendtime']);
  66. $info['refundendtime'] = date('Y-m-d H:i', $info['refundendtime']);
  67. //查询已报名列表
  68. $active_people = Db::name('active_people')->where(['active_id' => $id])->field('user_id, name, createtime')->select();
  69. $user = Db::name('user');
  70. foreach ($active_people as &$v) {
  71. $v['avatar'] = $user->where(['id' => $v['user_id']])->value('avatar');
  72. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  73. }
  74. $info['active_people'] = $active_people;
  75. $this->success('招标详情', $info);
  76. }
  77. //报名活动之前检查
  78. public function beforesignup() {
  79. $id = input('id', 0, 'intval'); //活动id
  80. if (!$id) {
  81. $this->error('请选择要报名的活动');
  82. }
  83. $info = Db::name('active')->find($id);
  84. if (!$info) {
  85. $this->error('活动不存在');
  86. }
  87. if ($info['signupendtime'] < time() || $info['status'] != 0) {
  88. $this->error('活动报名已经截止');
  89. }
  90. if ($info['currentperson'] >= $info['maxperson']) {
  91. $this->error('活动名额已满');
  92. }
  93. //检查自己信息是否完善
  94. if (!$this->auth->realname) {
  95. $this->success('请在个人资料中完善真实姓名', ['code' => 3]);
  96. }
  97. if (!$this->auth->idcard) {
  98. $this->success('请在个人资料中完善身份证号', ['code' => 3]);
  99. }
  100. if (!$this->auth->emergencycontact) {
  101. $this->success('请在个人资料中完善紧急联系人', ['code' => 3]);
  102. }
  103. if (!$this->auth->contactmobile) {
  104. $this->success('请在个人资料中完善紧急联系方式', ['code' => 3]);
  105. }
  106. $this->success('检查通过');
  107. }
  108. //报名活动
  109. public function signupactive() {
  110. //检查自己信息是否完善
  111. if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) {
  112. $this->success('请在个人资料中完善资料', ['code' => 3]);
  113. }
  114. $id = input('id', 0, 'intval'); //活动id
  115. //人员信息json串:
  116. // name姓名 credtype证件类型 idcard身份证号 mobile手机号 emergencycontact紧急联系人 contactmobile紧急联系方式
  117. // insurance保险 originalprice原价 vipprice会员价 coupon_id用户优惠券ID is_free是否使用免费次数:0=否,1=是
  118. // price小计 is_self是否本人:0=否,1=是
  119. $active_people = input('active_people', '', 'trim');
  120. $paytype = input('paytype', 0, 'intval'); //支付方式:0=余额,1=微信
  121. $total_price = input('total_price', 0, 'trim'); //总价格
  122. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $total_price) || $total_price < 0) {
  123. $this->error('合计价格错误');
  124. }
  125. if (!in_array($paytype, [0, 1])) {
  126. $this->error('支付错误');
  127. }
  128. if ($total_price == 0 && $paytype != 0) {
  129. $this->error('请选择余额支付');
  130. }
  131. //检查活动信息
  132. if (!$id) {
  133. $this->error('请选择要报名的活动');
  134. }
  135. $info = Db::name('active')->find($id);
  136. if (!$info) {
  137. $this->error('活动不存在');
  138. }
  139. if ($info['signupendtime'] < time() || $info['status'] != 0) {
  140. $this->error('活动报名已经截止');
  141. }
  142. if ($info['currentperson'] >= $info['maxperson']) {
  143. $this->error('活动名额已满');
  144. }
  145. //检查人员信息
  146. if (!$active_people) {
  147. $this->error('请添加报名人员信息');
  148. }
  149. $active_people_arr = json_decode($active_people, true);
  150. if (!$active_people_arr) {
  151. $this->error('请添加报名人员信息');
  152. }
  153. if ($info['currentperson'] + count($active_people_arr) > $info['maxperson']) {
  154. $this->error('活动名额不足');
  155. }
  156. //会员信息
  157. $vip_info = Db::name('vip')->find($this->auth->maxlevel);
  158. if (!$vip_info) {
  159. $this->error('会员信息缺失,请联系管理员');
  160. }
  161. $_data = [];
  162. $total_amount = 0; //总价格验证
  163. $active_people = Db::name('active_people'); //报名人员表
  164. $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
  165. $user_coupon = Db::name('user_coupon');
  166. foreach ($active_people_arr as $k => &$v) {
  167. $data = [];
  168. //判断是否报名过
  169. $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id');
  170. if ($count) {
  171. $this->error($v['name'] . $v['idcard'] . '已报名过该活动');
  172. break;
  173. }
  174. $count2 = $active_people_modify->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => 0])->count('id');
  175. if ($count2) {
  176. $this->error($v['name'] . $v['idcard'] . '已提交过修改,请等待审核');
  177. break;
  178. }
  179. //判断证件类型和保险
  180. if (!$v['credtype'] || iconv_strlen($v['credtype'], 'utf-8') > 50) {
  181. $this->error('证件类型错误');
  182. break;
  183. }
  184. if (!$v['insurance'] || iconv_strlen($v['insurance'], 'utf-8') > 50) {
  185. $this->error('保险信息错误');
  186. break;
  187. }
  188. //判断用户信息
  189. if ($v['is_self'] && $k == 0) {
  190. //判断用户信息
  191. 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) {
  192. $this->error('本人信息错误');
  193. break;
  194. }
  195. //本人判断年龄 价格
  196. if ($info['maxage'] > 0) {
  197. $age = $this->idcardage($this->auth->idcard);
  198. if ($age < $info['minage'] || $age > $info['maxage']) {
  199. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  200. break;
  201. }
  202. }
  203. if ($v['is_free'] == 1) { //使用免费次数
  204. if ($info['is_free'] != 1) {
  205. $this->error('活动暂不支持免费体验');
  206. break;
  207. }
  208. if ($this->auth->freenumber <= 0) {
  209. $this->error('您的免费次数不足');
  210. }
  211. if ($v['vipprice'] != 0 || $v['price'] != 0) {
  212. $this->error($this->auth->realname . '价格错误');
  213. break;
  214. }
  215. if ($v['coupon_id']) {
  216. $this->error('使用免费体验,无法使用优惠券');
  217. break;
  218. }
  219. } else { //不使用免费次数
  220. //会员价和优惠券是否可以叠加使用:0=否,1=是
  221. if ($info['is_overlying'] == 0 && $v['vipprice'] != $info['price'] && $v['coupon_id']) {
  222. $this->error('该活动不支持会员价和优惠券同时使用');
  223. break;
  224. }
  225. //计算会员价, 会员价优先顺序: 生日 > 女生特权日 > 会员价格
  226. $birthday = date('md', $this->auth->birthday);
  227. $now_day = date('md', time());
  228. if ($birthday == $now_day) {
  229. //生日折扣
  230. if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
  231. $this->error('会员生日折扣错误,请联系管理员');
  232. break;
  233. }
  234. $discount = $vip_info['birthdiscount'];
  235. } elseif ($info['girldiscount'] < 100 && $info['girldiscount'] > 0 && $this->auth->gender == 2) {
  236. //女生特权日折扣
  237. $discount = $info['girldiscount'];
  238. } else {
  239. //会员折扣
  240. if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
  241. $this->error('会员折扣错误,请联系管理员');
  242. break;
  243. }
  244. $discount = $vip_info['vipdiscount'];
  245. }
  246. $vipprice = $info['price'] * $discount / 100; //会员价
  247. //查询优惠券
  248. if ($v['coupon_id']) {
  249. $user_coupon_info = $user_coupon->where(['id' => $v['coupon_id'], 'user_id' => $this->auth->id])->find();
  250. if (!$user_coupon_info) {
  251. $this->error('优惠券不存在');
  252. }
  253. if ($user_coupon_info['status'] != 0) {
  254. $this->error('优惠券已使用');
  255. }
  256. if ($user_coupon_info['endtime'] < time()) {
  257. $this->error('优惠券已过期');
  258. }
  259. if ($user_coupon_info['type'] == 1) {
  260. //打折券
  261. if ($user_coupon_info['money'] < 0 || $user_coupon_info['money'] > 100) {
  262. $this->error('优惠券折扣错误,请联系管理员');
  263. break;
  264. }
  265. } else {
  266. //抵扣券
  267. //会员价和优惠券是否可以叠加使用:0=否,1=是
  268. if ($info['is_overlying'] == 0) {
  269. if ($info['price'] < $user_coupon_info['minmoney']) {
  270. $this->error('优惠券使用条件不满足');
  271. break;
  272. }
  273. } else {
  274. if ($vipprice < $user_coupon_info['minmoney']) {
  275. $this->error('优惠券使用条件不满足');
  276. break;
  277. }
  278. }
  279. }
  280. }
  281. //判断价格
  282. //会员价和优惠券是否可以叠加使用:0=否,1=是
  283. if ($info['is_overlying'] == 0) {
  284. if ($v['coupon_id']) { //使用优惠券
  285. if ($v['vipprice'] != $info['price']) {
  286. $this->error('会员价显示错误');
  287. break;
  288. }
  289. if ($user_coupon_info['type'] == 1) {
  290. //打折券
  291. $price = $info['price'] * $user_coupon_info['money'] / 100;
  292. } else {
  293. //抵扣券
  294. $price = $info['price'] - $user_coupon_info['money'];
  295. }
  296. } else {
  297. $price = $vipprice;
  298. }
  299. } else {
  300. if ($vipprice != $v['vipprice']) {
  301. $this->error('会员价显示错误');
  302. break;
  303. }
  304. if ($v['coupon_id']) { //使用优惠券
  305. if ($user_coupon_info['type'] == 1) {
  306. //打折券
  307. $price = $vipprice * $user_coupon_info['money'] / 100;
  308. } else {
  309. //抵扣券
  310. $price = $vipprice - $user_coupon_info['money'];
  311. }
  312. } else {
  313. $price = $vipprice;
  314. }
  315. }
  316. //判断小计
  317. if ($price != $v['price']) {
  318. $this->error('小计显示错误');
  319. break;
  320. }
  321. $data['vipprice'] = $v['vipprice']; //会员价
  322. $data['coupon_id'] = $v['coupon_id']; //优惠券id
  323. if ($v['coupon_id']) {
  324. $data['coupontype'] = $user_coupon_info['type'];
  325. $data['couponprice'] = $user_coupon_info['money'];
  326. }
  327. }
  328. $data['name'] = $this->auth->realname;
  329. $data['idcard'] = $this->auth->idcard;
  330. $data['mobile'] = $this->auth->mobile;
  331. $data['emergencycontact'] = $this->auth->emergencycontact;
  332. $data['contactmobile'] = $this->auth->contactmobile;
  333. } else {
  334. //帮人报名判断年龄 报名信息
  335. if ($info['maxage'] > 0) {
  336. $age = $this->idcardage($v['idcard']);
  337. if ($age < $info['minage'] || $age > $info['maxage']) {
  338. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  339. break;
  340. }
  341. }
  342. if (!$v['name'] || iconv_strlen($v['name'], 'utf-8') > 50) {
  343. $this->error('请输入正确姓名');
  344. break;
  345. }
  346. if (iconv_strlen($v['idcard'], 'utf-8') != 18) {
  347. $this->error('请输入正确身份证号');
  348. break;
  349. }
  350. if (!is_mobile($v['mobile'])) {
  351. $this->error('请输入正确手机号');
  352. break;
  353. }
  354. if (!$v['emergencycontact'] || iconv_strlen($v['emergencycontact'], 'utf-8') > 50) {
  355. $this->error('请输入紧急联系人');
  356. break;
  357. }
  358. if (!is_mobile($v['contactmobile'])) {
  359. $this->error('请输入正确紧急联系人方式');
  360. break;
  361. }
  362. //判断是否符合满几人减免一人费用
  363. //会员权限
  364. if ($vip_info['manypeople'] > 1 && $k == $vip_info['manypeople'] - 1) {
  365. if ($v['price'] != 0) {
  366. $this->error('小计显示错误');
  367. break;
  368. }
  369. } else {
  370. if ($v['price'] != $info['price']) {
  371. $this->error('小计显示错误');
  372. break;
  373. }
  374. }
  375. $data['name'] = $v['name'];
  376. $data['idcard'] = $v['idcard'];
  377. $data['mobile'] = $v['mobile'];
  378. $data['emergencycontact'] = $v['emergencycontact'];
  379. $data['contactmobile'] = $v['contactmobile'];
  380. $data['vipprice'] = $v['price']; //会员价
  381. }
  382. $data['active_id'] = $id;
  383. $data['user_id'] = $this->auth->id;
  384. $data['credtype'] = $v['credtype'];
  385. $data['insurance'] = $v['insurance'];
  386. $data['originalprice'] = $info['price'];
  387. $data['is_free'] = $v['is_free'];
  388. $data['price'] = $v['price']; //小计
  389. $data['is_self'] = $v['is_self'];
  390. $data['createtime'] = time();
  391. array_push($_data, $data);
  392. $total_amount += $v['price'];
  393. }
  394. if ($total_amount != $total_price) {
  395. $this->error('合计价格错误');
  396. }
  397. if ($paytype == 0) { //余额支付
  398. if ($this->auth->money < $total_amount) {
  399. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  400. }
  401. }
  402. //构建订单信息
  403. $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  404. $order_data['active_id'] = $id;
  405. $order_data['user_id'] = $this->auth->id;
  406. $order_data['paytype'] = $paytype;
  407. $order_data['price'] = $total_amount;
  408. $order_data['number'] = count($active_people_arr);
  409. $order_data['status'] = $paytype == 1 ? 0 : 1;
  410. $order_data['createtime'] = time();
  411. //开始事务
  412. Db::startTrans();
  413. //修改活动表数据
  414. $active_rs = Db::name('active')->where(['id' => $id, 'currentperson' => $info['currentperson']])->setField('currentperson', $info['currentperson'] + count($active_people));
  415. if (!$active_rs) {
  416. Db::rollback();
  417. $this->error('网络延迟,请稍后再试');
  418. }
  419. //添加订单
  420. $rs = Db::name('active_order')->insertGetId($order_data);
  421. if (!$rs) {
  422. Db::rollback();
  423. $this->error('网络延迟,请稍后再试');
  424. }
  425. //添加人员信息
  426. foreach ($_data as &$v) {
  427. $v['order_id'] = $rs;
  428. $rt = $active_people->insertGetId($v);
  429. if (!$rt) {
  430. Db::rollback();
  431. $this->error('网络延迟,请稍后再试');
  432. }
  433. }
  434. //扣除免费次数
  435. if ($info['is_free'] == 1 && $active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['is_free'] == 1) {
  436. $freenumber = $this->auth->freenumber - 1;
  437. $user_rs = Db::name('user')->where(['id' => $this->auth->id, 'freenumber' => $this->auth->freenumber])->setField('freenumber', $freenumber);
  438. if (!$user_rs) {
  439. Db::rollback();
  440. $this->error('网络延迟,请稍后再试');
  441. }
  442. }
  443. //扣款 支付方式:0=余额,1=微信
  444. if ($paytype == 0) {
  445. $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2);
  446. if ($res != 1) {
  447. Db::rollback();
  448. $this->error('余额资金异常,请联系管理员');
  449. }
  450. Db::commit();
  451. $this->success('报名成功');
  452. } else {
  453. //生成支付订单记录
  454. $rechar_order['user_id'] = $this->auth->id;
  455. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  456. $rechar_order['money'] = $total_amount;
  457. $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
  458. $rechar_order['pay_type'] = 'wechat';
  459. $rechar_order['relation_id'] = $rs;
  460. $rechar_order['createtime'] = time();
  461. $rechar_order['money'] = $total_amount;
  462. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  463. if (!$result) {
  464. Db::rollback();
  465. $this->error('网络延迟,请稍后再试');
  466. }
  467. //构建支付链接数据
  468. $wxData['body'] = '报名活动支付';
  469. $wxData['out_trade_no'] = $rechar_order['order_no'];
  470. $wxData['total_fee'] = $total_amount;
  471. // $wxData['total_fee'] = 0.01;
  472. $wxData['openid'] = $this->auth->openid;
  473. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  474. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  475. $doResult = $wxPay->WxPayJs($wxData);
  476. $this->success('微信支付参数返回成功', $doResult);
  477. }
  478. }
  479. //根据身份证号获取年龄
  480. public function idcardage($idcard = '') {
  481. //截取身份证里的出生日期
  482. $year = substr($idcard, 6, 4);
  483. $month = substr($idcard, 10, 2);
  484. $day = substr($idcard, 12, 2);
  485. //获取当前日期
  486. $current_year = date('Y');
  487. $current_month = date('m');
  488. $current_day = date('d');
  489. //计算年龄
  490. $age = $current_year - $year;//今年减去生日年
  491. if ($month > $current_month || ($month == $current_month && $day > $current_day)) {
  492. //如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  493. $age--;
  494. }
  495. return $age;
  496. }
  497. //私人订制类型
  498. public function personaltype() {
  499. $list = Db::name('personal_type')->field('id, name')->order('weigh', 'desc')->select();
  500. $this->success('私人订制类型', $list);
  501. }
  502. //私人订制活动类型
  503. public function personalactivetype() {
  504. $list = Db::name('personal_active_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
  505. $list = $this->getchildtype($list);
  506. $this->success('私人订制活动类型', $list);
  507. }
  508. //无限级私人订制活动类型
  509. public function getchildtype($list = [])
  510. {
  511. $complaint_type = Db::name('personal_active_type');
  512. foreach ($list as &$v) {
  513. $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
  514. if ($child) {
  515. $child = $this->getchildtype($child);
  516. }
  517. $v['child'] = $child;
  518. }
  519. return $list;
  520. }
  521. //车辆类型
  522. public function car() {
  523. $list = Db::name('car')->field('id, name, desc')->order('weigh', 'desc')->select();
  524. $this->success('车辆类型', $list);
  525. }
  526. //领队
  527. public function leader() {
  528. $list = Db::name('leader')->field('id, name')->order('weigh', 'desc')->select();
  529. $this->success('领队', $list);
  530. }
  531. //私人订制出行方向
  532. public function personaldirection() {
  533. $list = Db::name('personal_direction')->field('id, name')->order('weigh', 'desc')->select();
  534. $this->success('私人订制出行方向', $list);
  535. }
  536. //私人订制
  537. public function personalactive() {
  538. $type = input('type', '', 'trim'); //类型
  539. $number = input('number', 0, 'intval'); //出行人数
  540. $traveltime = input('traveltime', '', 'strtotime'); //出行时间
  541. $traveday = input('traveday', 0, 'intval'); //出行天数
  542. $activetype = input('activetype', '', 'trim'); //活动类型
  543. $car = input('car', '', 'trim'); //车辆
  544. $leader = input('leader', '', 'trim'); //领队
  545. $travedirection = input('travedirection', '', 'trim'); //出行方向
  546. $freerange = input('freerange', '', 'trim'); //空闲时段
  547. $remark = input('remark', '', 'trim'); //留言
  548. if (!$type || iconv_strlen($type, 'utf-8') > 50) {
  549. $this->error('请选择类型');
  550. }
  551. if ($number <= 0) {
  552. $this->error('请填写出行人数');
  553. }
  554. if ($traveltime < time()) {
  555. $this->error('请选择正确出行时间');
  556. }
  557. if ($traveday <= 0) {
  558. $this->error('请填写正确出行天数');
  559. }
  560. if (!$activetype || iconv_strlen($activetype, 'utf-8') > 50) {
  561. $this->error('请选择活动类型');
  562. }
  563. if ($car && iconv_strlen($car, 'utf-8') > 50) {
  564. $this->error('请选择车辆');
  565. }
  566. if ($leader && iconv_strlen($leader, 'utf-8') > 50) {
  567. $this->error('请选择领队');
  568. }
  569. if (!$travedirection || iconv_strlen($travedirection, 'utf-8') > 50) {
  570. $this->error('请选择出行方向');
  571. }
  572. if (!$freerange || iconv_strlen($freerange, 'utf-8') > 50) {
  573. $this->error('请选择空闲时段');
  574. }
  575. if (iconv_strlen($remark, 'utf-8') > 500) {
  576. $this->error('留言最多500字');
  577. }
  578. $data['user_id'] = $this->auth->id;
  579. $data['type'] = $type;
  580. $data['number'] = $number;
  581. $data['traveltime'] = $traveltime;
  582. $data['traveday'] = $traveday;
  583. $data['activetype'] = $activetype;
  584. $data['car'] = $car;
  585. $data['leader'] = $leader;
  586. $data['travedirection'] = $travedirection;
  587. $data['freerange'] = $freerange;
  588. $data['remark'] = $remark;
  589. $data['createtime'] = time();
  590. $rs = Db::name('personal_order')->insertGetId($data);
  591. if (!$rs) {
  592. $this->error('提交失败');
  593. }
  594. $this->success('提交成功');
  595. }
  596. //查询轮播图优惠券列表
  597. public function bannercoupon() {
  598. $list = Db::name('coupon')->field('id, title, desc, type, money')
  599. ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
  600. $user_coupon = Db::name('user_coupon');
  601. foreach ($list as &$v) {
  602. $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
  603. }
  604. $this->success('查询轮播图优惠券列表', $list);
  605. }
  606. //领取轮播图优惠券
  607. public function receivebannercoupon() {
  608. $id = input('id', 0, 'intval'); //优惠券id
  609. if (!$id) {
  610. $this->error('参数缺失');
  611. }
  612. $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
  613. if (!$info) {
  614. $this->error('优惠券不存在');
  615. }
  616. if ($info['status'] != 1) {
  617. $this->error('优惠券已下架');
  618. }
  619. //查询是否已领取
  620. $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  621. if ($count) {
  622. $this->error('您已经领取过了');
  623. }
  624. $data['user_id'] = $this->auth->id;
  625. $data['coupon_id'] = $id;
  626. $data['title'] = $info['title'];
  627. $data['desc'] = $info['desc'];
  628. $data['type'] = $info['type'];
  629. $data['money'] = $info['money'];
  630. $data['minmoney'] = $info['minmoney'];
  631. $data['purpose'] = $info['purpose'];
  632. $data['starttime'] = time();
  633. $data['endtime'] = time() + $info['effectiveday'] * 86400;
  634. $data['createtime'] = time();
  635. //开启事务
  636. Db::startTrans();
  637. //添加领取记录
  638. $rs = Db::name('user_coupon')->insertGetId($data);
  639. if (!$rs) {
  640. Db::rollback();
  641. $this->error('领取失败');
  642. }
  643. $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  644. if ($rt != 1) {
  645. Db::rollback();
  646. $this->error('领取失败');
  647. }
  648. Db::commit();
  649. $this->success('领取成功');
  650. }
  651. //体验会员列表
  652. public function experiencevip() {
  653. $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->select();
  654. $this->success('体验会员列表', $list);
  655. }
  656. //购买体验会员
  657. public function buyexperiencevip() {
  658. //检查是否已经开通体验会员
  659. if ($this->auth->experiencetime >= time()) {
  660. $this->error('您已开通体验会员,不能重复开通');
  661. }
  662. $id = input('id', 0, 'intval');
  663. if (!$id) {
  664. $this->error('参数缺失');
  665. }
  666. $info = Db::name('vip')->where(['id' => $id])->find();
  667. if (!$info) {
  668. $this->error('会员不存在');
  669. }
  670. if ($info['status'] != 1) {
  671. $this->error('体验会员已下架');
  672. }
  673. if ($info['price'] <= 0) {
  674. $this->error('会员价格异常');
  675. }
  676. //体验会员等级必须大于成长值会员
  677. if ($id <= $this->auth->maxlevel) {
  678. $this->error('请开通更高等级体验会员');
  679. }
  680. //判断余额
  681. if ($this->auth->money < $info['price']) {
  682. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  683. }
  684. $data['user_id'] = $this->auth->id;
  685. $data['vip_id'] = $id;
  686. $data['title'] = $info['title'];
  687. $data['level'] = $info['level'];
  688. $data['growthvalue'] = $info['growthvalue'];
  689. $data['free'] = $info['free'];
  690. $data['price'] = $info['price'];
  691. $data['endtime'] = time() + $info['day'] * 86400;
  692. $data['vipdiscount'] = $info['vipdiscount'];
  693. $data['birthdiscount'] = $info['birthdiscount'];
  694. $data['manypeople'] = $info['manypeople'];
  695. $data['createtime'] = time();
  696. //开启事务
  697. Db::startTrans();
  698. //添加开通记录
  699. $rs = Db::name('vip_log')->insertGetId($data);
  700. if (!$rs) {
  701. Db::rollback();
  702. $this->error('开通失败');
  703. }
  704. //扣除余额
  705. $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4);
  706. if ($result != 1) {
  707. Db::rollback();
  708. $this->error('资金异常,请联系管理员');
  709. }
  710. //成长值会员信息
  711. $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
  712. //修改用户表信息
  713. $user_data['experiencelevel'] = $id;
  714. $user_data['experiencetime'] = $data['endtime'];
  715. $user_data['maxlevel'] = $id;
  716. $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
  717. $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
  718. $rt = Db::name('user')->where([
  719. 'user_id' => $this->auth->id,
  720. 'experiencelevel' => $this->auth->experiencelevel,
  721. 'maxlevel' => $this->auth->maxlevel,
  722. 'freenumber' => $this->auth->freenumber])->setField($user_data);
  723. if (!$rt) {
  724. Db::rollback();
  725. $this->error('开通失败');
  726. }
  727. Db::commit();
  728. $this->success('开通成功');
  729. }
  730. }