Index.php 32 KB

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