Index.php 33 KB

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