Index.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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 operator()
  25. {
  26. $province = input('province', '', 'trim'); //省
  27. $city = input('city', '', 'trim'); //市
  28. $area = input('area', '', 'trim'); //区
  29. $keyword = input('keyword', '', 'trim'); //关键字
  30. $where['status'] = 1;
  31. if ($province) {
  32. $where['province'] = $province;
  33. }
  34. if ($city) {
  35. $where['city'] = $city;
  36. }
  37. if ($area) {
  38. $where['area'] = $area;
  39. }
  40. if ($keyword !== '') {
  41. $where['name|mobile'] = ['like', '%'.$keyword.'%'];
  42. }
  43. $list = Db::name('operator')->field('id, name, mobile, avatar, province, city, area')->where($where)
  44. ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select();
  45. $list = list_domain_image($list, ['avatar']);
  46. $this->success('接线员', $list);
  47. }
  48. //价格走势
  49. public function pricetrend()
  50. {
  51. $info = Db::name('platform_info')->field('title, content')->where(['type' => 2])->find();
  52. $this->success('价格走势', $info);
  53. }
  54. //精选推荐列表
  55. public function mark()
  56. {
  57. $province = input('province', '', 'trim'); //省
  58. $keyword = input('keyword', '', 'trim'); //关键字
  59. $where['endtime'] = ['gt', time()];
  60. $where['status'] = 1;
  61. if ($province) {
  62. $where['province'] = $province;
  63. }
  64. if ($keyword !== '') {
  65. $where['name|pig_type|pig_breed_type|province|city|area|address'] = ['like', '%'.$keyword.'%'];
  66. }
  67. $list = Db::name('mark')->field('id, name, image, pig_type, heft, price, province, city, area')
  68. ->where($where)->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select();
  69. $list = list_domain_image($list, ['image']);
  70. $mark_bid = Db::name('mark_bid');
  71. foreach ($list as &$v) {
  72. $v['bid_count'] = $mark_bid->where(['mark_id' => $v['id']])->count('id');
  73. }
  74. $this->success('精选推荐列表', $list);
  75. }
  76. //招标详情
  77. public function markinfo()
  78. {
  79. $id = input('id', 0, 'intval');
  80. if (!$id) {
  81. $this->error('参数缺失');
  82. }
  83. $info = Db::name('mark')->find($id);
  84. if (!$info) {
  85. $this->error('数据不存在');
  86. }
  87. $info = info_domain_image($info, ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  88. $info['createtime'] = date('Y-m-d H:i:s', $info['createtime']);
  89. $info['remaintime'] = $info['endtime'] - time() > 0 ? $info['endtime'] - time() : 0; //投标剩余时间
  90. $info['again_bid'] = process_time($info['again_bid']); //再次投标间隔时间处理
  91. $this->success('招标详情', $info);
  92. }
  93. //投标
  94. public function markbid()
  95. {
  96. $id = input('id', 0, 'intval'); //招标id
  97. $price = input('price', '', 'trim'); //报价/斤
  98. $number = input('number', 0, 'intval'); //购买数量
  99. $pig_pulling_time = input('pig_pulling_time', '', 'strtotime'); //预计拉猪时间
  100. if (!$id) {
  101. $this->error('参数缺失');
  102. }
  103. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price <= 0) {
  104. $this->error('请输入正确报价');
  105. }
  106. if ($number <= 0) {
  107. $this->error('请输入购买数量');
  108. }
  109. if ($pig_pulling_time < time()) {
  110. $this->error('请选择正确拉猪时间');
  111. }
  112. if ($this->auth->is_auth != 2) {
  113. $this->error('请先完成实名认证');
  114. }
  115. $info = Db::name('mark')->find($id);
  116. if (!$info) {
  117. $this->error('招标信息不存在');
  118. }
  119. if ($info['status'] != 1) {
  120. $this->error('招标已经结束');
  121. }
  122. if ($info['endtime'] < time()) {
  123. $this->error('招标已经结束');
  124. }
  125. //查询是否投过标
  126. $bid_info = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->order('createtime', 'desc')->find();
  127. if ($bid_info) {
  128. if ($price <= $bid_info['price']) {
  129. $this->error('价格不能低于上次报价');
  130. }
  131. if ($info['again_bid'] > 0) {
  132. if (time() - $bid_info['updatetime'] < $info['again_bid']) {
  133. $this->error('您刚投标过,请稍等一会');
  134. }
  135. }
  136. }
  137. $data['user_id'] = $this->auth->id;
  138. $data['mark_id'] = $id;
  139. $data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  140. $data['price'] = $price;
  141. $data['number'] = $number;
  142. $data['pig_pulling_time'] = $pig_pulling_time;
  143. $data['province'] = $info['province'];
  144. $data['city'] = $info['city'];
  145. $data['area'] = $info['area'];
  146. $data['createtime'] = time();
  147. $data['updatetime'] = time();
  148. //开启事务
  149. Db::startTrans();
  150. //添加投标记录
  151. $rs = Db::name('mark_bid_record')->insertGetId($data);
  152. if (!$rs) {
  153. Db::rollback();
  154. $this->error('投标失败');
  155. }
  156. if ($bid_info) {
  157. //已经投标过, 更新实时投标数据
  158. $_data['order_sn'] = $data['order_sn'];
  159. $_data['price'] = $price;
  160. $_data['number'] = $number;
  161. $_data['pig_pulling_time'] = $pig_pulling_time;
  162. $_data['updatetime'] = time();
  163. $result = Db::name('mark_bid')->where(['id' => $bid_info['id'], 'user_id' => $this->auth->id, 'price' => $bid_info['price']])->setField($_data);
  164. } else {
  165. $result = Db::name('mark_bid')->insertGetId($data);
  166. }
  167. if (!$result) {
  168. Db::rollback();
  169. $this->error('投标失败');
  170. }
  171. $rt = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->count('id');
  172. if ($rt != 1) {
  173. Db::rollback();
  174. $this->error('投标失败');
  175. }
  176. Db::commit();
  177. $this->success('投标成功');
  178. }
  179. //猪只类型
  180. public function pigbreedtype()
  181. {
  182. $list = Db::name('pig_breed_type')->field('id, name')->order('weigh', 'desc')->select();
  183. $this->success('猪只类型', $list);
  184. }
  185. //立即投标筛选列表
  186. public function marklist()
  187. {
  188. $pig_breed_type = input('pig_breed_type', '', 'trim'); //猪只类型
  189. $province = input('province', '', 'trim'); //省
  190. $city = input('city', '', 'trim'); //市
  191. $area = input('area', '', 'trim'); //区
  192. if (!$pig_breed_type) {
  193. $this->error('请选择猪只类型');
  194. }
  195. if (!$province && !$city && !$area) {
  196. $this->error('请选择地区');
  197. }
  198. $where['pig_breed_type'] = $pig_breed_type;
  199. $where['endtime'] = ['gt', time()];
  200. $where['status'] = 1;
  201. if ($province) {
  202. $where['province'] = $province;
  203. }
  204. if ($city) {
  205. $where['city'] = $city;
  206. }
  207. if ($area) {
  208. $where['area'] = $area;
  209. }
  210. $list = Db::name('mark')->field('id, area, pig_type, heft, number, price')
  211. ->where($where)->order('createtime', 'desc')->select();
  212. $this->success('立即投标筛选列表', $list);
  213. }
  214. //立即投标页面备注
  215. public function bidremark()
  216. {
  217. $info = Db::name('platform_info')->field('content')->where(['type' => 3])->find();
  218. $this->success('立即投标页面备注', $info);
  219. }
  220. //投标管理列表
  221. public function bidlist()
  222. {
  223. $type = input('type', 1, 'intval'); //类型 1全部 2竞标中 3=中标 4=未中标
  224. $time = input('time', '', 'strtotime'); //时间
  225. $province = input('province', '', 'trim'); //省
  226. $city = input('city', '', 'trim'); //市
  227. $area = input('area', '', 'trim'); //区
  228. $where['user_id'] = $this->auth->id;
  229. if ($type > 1) {
  230. $where['status'] = $type - 2; //状态:0=竞标中,1=中标,2=未中标
  231. }
  232. if (!$time) {
  233. $time = strtotime(date('Y-m-d 0:0:0', time()));
  234. }
  235. $where['createtime'] = ['between', [$time, $time + 86400]];
  236. if ($province) {
  237. $where['province'] = $province;
  238. }
  239. if ($city) {
  240. $where['city'] = $city;
  241. }
  242. if ($area) {
  243. $where['area'] = $area;
  244. }
  245. $list = Db::name('mark_bid')->where($where)
  246. ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
  247. $mark = Db::name('mark');
  248. $mark_bid = Db::name('mark_bid');
  249. foreach ($list as &$v) {
  250. $v['pig_pulling_time'] = date('Y-m-d H:i:s', $v['pig_pulling_time']);
  251. //排名
  252. $v['ranking'] = $mark_bid->where(['mark_id' => $v['mark_id'], 'price' => ['egt', $v['price']]])->count('id');
  253. $v['mark'] = $mark->find($v['mark_id']);
  254. $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  255. $v['mark']['endtime'] = date('Y-m-d H:i:s', $v['mark']['endtime']);
  256. }
  257. $this->success('投标管理列表', $list);
  258. }
  259. //投标记录
  260. public function bidrecord()
  261. {
  262. $id = input('id', 0, 'intval'); //招标id
  263. if (!$id) {
  264. $this->error('参数缺失');
  265. }
  266. $info = Db::name('mark')->find($id);
  267. if (!$info) {
  268. $this->error('招标信息不存在');
  269. }
  270. $list = Db::name('mark_bid')->field('id, price, number, createtime')
  271. ->where(['user_id' => $this->auth->id, 'mark_id' => $id])
  272. ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
  273. foreach ($list as &$v) {
  274. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  275. }
  276. $this->success('投标记录', $list);
  277. }
  278. //投标详情
  279. public function bidinfo()
  280. {
  281. $id = input('id', 0, 'intval'); //投标记录id
  282. if (!$id) {
  283. $this->error('参数缺失');
  284. }
  285. $where['user_id'] = $this->auth->id;
  286. $where['id'] = $id;
  287. $info = Db::name('mark_bid')->where($where)->find();
  288. if (!$info) {
  289. $this->error('记录不存在');
  290. }
  291. $mark = Db::name('mark');
  292. $info['pig_pulling_time'] = date('Y-m-d H:i:s', $info['pig_pulling_time']);
  293. $info['mark'] = $mark->find($info['mark_id']);
  294. $info['mark'] = info_domain_image($info['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  295. $info['mark']['endtime'] = date('Y-m-d H:i:s', $info['mark']['endtime']);
  296. $this->success('投标详情', $info);
  297. }
  298. //轮播图
  299. public function banner()
  300. {
  301. $list = Db::name('banner')->field('id, title, image, url')->order('weigh', 'desc')->select();
  302. $this->success('轮播图', $list);
  303. }
  304. //活动列表
  305. public function activelist() {
  306. $type = input('type', 0, 'intval'); //分类:1=休闲,2=中度
  307. $keyword = input('keyword', '', 'trim'); //关键字
  308. $where['signupendtime'] = ['gt', time()];
  309. $where['status'] = 0;
  310. if ($type) {
  311. $where['type'] = $type;
  312. }
  313. if ($keyword !== '') {
  314. $where['title|desc|remark|collectionplace|leader'] = ['like', '%'.$keyword.'%'];
  315. }
  316. $list = Db::name('active')->field('id, type, title, desc, remark, image, price, maxperson, currentperson, status')
  317. ->where($where)->page($this->page, $this->pagenum)->order('createtime', 'desc')->select();
  318. foreach ($list as &$v) {
  319. if ($v['maxperson'] <= $v['currentperson']) {
  320. $v['is_full'] = 1;
  321. } else {
  322. $v['is_full'] = 0;
  323. }
  324. }
  325. $this->success('活动列表', $list);
  326. }
  327. //活动详情
  328. public function activeinfo() {
  329. $id = input('id', 0, 'intval');
  330. if (!$id) {
  331. $this->error('参数缺失');
  332. }
  333. $info = Db::name('active')->find($id);
  334. if (!$info) {
  335. $this->error('数据不存在');
  336. }
  337. $info['starttime'] = date('Y-m-d H:i', $info['starttime']);
  338. $info['endtime'] = date('Y-m-d H:i', $info['endtime']);
  339. $info['collectiontime'] = date('Y-m-d H:i', $info['collectiontime']);
  340. $info['signupendtime'] = date('Y-m-d H:i', $info['signupendtime']);
  341. $info['refundendtime'] = date('Y-m-d H:i', $info['refundendtime']);
  342. //查询已报名列表
  343. $active_people = Db::name('active_people')->where(['active_id' => $id])->field('user_id, name, createtime')->select();
  344. $user = Db::name('user');
  345. foreach ($active_people as &$v) {
  346. $v['avatar'] = $user->where(['id' => $v['user_id']])->value('avatar');
  347. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  348. }
  349. $info['active_people'] = $active_people;
  350. $this->success('招标详情', $info);
  351. }
  352. //报名活动之前检查
  353. public function beforesignup() {
  354. $id = input('id', 0, 'intval'); //活动id
  355. if (!$id) {
  356. $this->error('请选择要报名的活动');
  357. }
  358. $info = Db::name('active')->find($id);
  359. if (!$info) {
  360. $this->error('活动不存在');
  361. }
  362. if ($info['signupendtime'] < time() || $info['status'] != 0) {
  363. $this->error('活动报名已经截止');
  364. }
  365. if ($info['currentperson'] >= $info['maxperson']) {
  366. $this->error('活动名额已满');
  367. }
  368. //检查自己信息是否完善
  369. if (!$this->auth->realname) {
  370. $this->success('请在个人资料中完善真实姓名', ['code' => 3]);
  371. }
  372. if (!$this->auth->idcard) {
  373. $this->success('请在个人资料中完善身份证号', ['code' => 3]);
  374. }
  375. if (!$this->auth->emergencycontact) {
  376. $this->success('请在个人资料中完善紧急联系人', ['code' => 3]);
  377. }
  378. if (!$this->auth->contactmobile) {
  379. $this->success('请在个人资料中完善紧急联系方式', ['code' => 3]);
  380. }
  381. $this->success('检查通过');
  382. }
  383. //报名活动
  384. public function signupactive() {
  385. //检查自己信息是否完善
  386. if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) {
  387. $this->success('请在个人资料中完善资料', ['code' => 3]);
  388. }
  389. $id = input('id', 0, 'intval'); //活动id
  390. //人员信息json串:
  391. // name姓名 credtype证件类型 idcard身份证号 mobile手机号 emergencycontact紧急联系人 contactmobile紧急联系方式
  392. // insurance保险 originalprice原价 vipprice会员价 coupon_id用户优惠券ID is_free是否使用免费次数:0=否,1=是
  393. // price小计 is_self是否本人:0=否,1=是
  394. $active_people = input('active_people', '', 'trim');
  395. $paytype = input('paytype', 0, 'intval'); //支付方式:0=余额,1=微信
  396. $total_price = input('total_price', 0, 'trim'); //总价格
  397. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $total_price) || $total_price < 0) {
  398. $this->error('合计价格错误');
  399. }
  400. if (!in_array($paytype, [0, 1])) {
  401. $this->error('支付错误');
  402. }
  403. if ($total_price == 0 && $paytype != 0) {
  404. $this->error('请选择余额支付');
  405. }
  406. //检查活动信息
  407. if (!$id) {
  408. $this->error('请选择要报名的活动');
  409. }
  410. $info = Db::name('active')->find($id);
  411. if (!$info) {
  412. $this->error('活动不存在');
  413. }
  414. if ($info['signupendtime'] < time() || $info['status'] != 0) {
  415. $this->error('活动报名已经截止');
  416. }
  417. if ($info['currentperson'] >= $info['maxperson']) {
  418. $this->error('活动名额已满');
  419. }
  420. //检查人员信息
  421. if (!$active_people) {
  422. $this->error('请添加报名人员信息');
  423. }
  424. $active_people_arr = json_decode($active_people, true);
  425. if (!$active_people_arr) {
  426. $this->error('请添加报名人员信息');
  427. }
  428. if ($info['currentperson'] + count($active_people_arr) > $info['maxperson']) {
  429. $this->error('活动名额不足');
  430. }
  431. //会员信息
  432. $vip_info = Db::name('vip')->find($this->auth->maxlevel);
  433. if (!$vip_info) {
  434. $this->error('会员信息缺失,请联系管理员');
  435. }
  436. $_data = [];
  437. $total_amount = 0; //总价格验证
  438. $active_people = Db::name('active_people'); //报名人员表
  439. $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
  440. $user_coupon = Db::name('user_coupon');
  441. foreach ($active_people_arr as $k => &$v) {
  442. $data = [];
  443. //判断是否报名过
  444. $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id');
  445. if ($count) {
  446. $this->error($v['name'] . $v['idcard'] . '已报名过该活动');
  447. break;
  448. }
  449. $count2 = $active_people_modify->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => 0])->count('id');
  450. if ($count2) {
  451. $this->error($v['name'] . $v['idcard'] . '已提交过修改,请等待审核');
  452. break;
  453. }
  454. //判断证件类型和保险
  455. if (!$v['credtype'] || iconv_strlen($v['credtype'], 'utf-8') > 50) {
  456. $this->error('证件类型错误');
  457. break;
  458. }
  459. if (!$v['insurance'] || iconv_strlen($v['insurance'], 'utf-8') > 50) {
  460. $this->error('保险信息错误');
  461. break;
  462. }
  463. //判断用户信息
  464. if ($v['is_self'] && $k == 0) {
  465. //判断用户信息
  466. 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) {
  467. $this->error('本人信息错误');
  468. break;
  469. }
  470. //本人判断年龄 价格
  471. if ($info['maxage'] > 0) {
  472. $age = $this->idcardage($this->auth->idcard);
  473. if ($age < $info['minage'] || $age > $info['maxage']) {
  474. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  475. break;
  476. }
  477. }
  478. if ($v['is_free'] == 1) { //使用免费次数
  479. if ($info['is_free'] != 1) {
  480. $this->error('活动暂不支持免费体验');
  481. break;
  482. }
  483. if ($this->auth->freenumber <= 0) {
  484. $this->error('您的免费次数不足');
  485. }
  486. if ($v['vipprice'] != 0 || $v['price'] != 0) {
  487. $this->error($this->auth->realname . '价格错误');
  488. break;
  489. }
  490. if ($v['coupon_id']) {
  491. $this->error('使用免费体验,无法使用优惠券');
  492. break;
  493. }
  494. } else { //不使用免费次数
  495. //会员价和优惠券是否可以叠加使用:0=否,1=是
  496. if ($info['is_overlying'] == 0 && $v['vipprice'] != $info['price'] && $v['coupon_id']) {
  497. $this->error('该活动不支持会员价和优惠券同时使用');
  498. break;
  499. }
  500. //计算会员价, 会员价优先顺序: 生日 > 女生特权日 > 会员价格
  501. $birthday = date('md', $this->auth->birthday);
  502. $now_day = date('md', time());
  503. if ($birthday == $now_day) {
  504. //生日折扣
  505. if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
  506. $this->error('会员生日折扣错误,请联系管理员');
  507. break;
  508. }
  509. $discount = $vip_info['birthdiscount'];
  510. } elseif ($info['girldiscount'] < 100 && $info['girldiscount'] > 0 && $this->auth->gender == 2) {
  511. //女生特权日折扣
  512. $discount = $info['girldiscount'];
  513. } else {
  514. //会员折扣
  515. if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
  516. $this->error('会员折扣错误,请联系管理员');
  517. break;
  518. }
  519. $discount = $vip_info['vipdiscount'];
  520. }
  521. $vipprice = $info['price'] * $discount / 100; //会员价
  522. //查询优惠券
  523. if ($v['coupon_id']) {
  524. $user_coupon_info = $user_coupon->where(['id' => $v['coupon_id'], 'user_id' => $this->auth->id])->find();
  525. if (!$user_coupon_info) {
  526. $this->error('优惠券不存在');
  527. }
  528. if ($user_coupon_info['status'] != 0) {
  529. $this->error('优惠券已使用');
  530. }
  531. if ($user_coupon_info['endtime'] < time()) {
  532. $this->error('优惠券已过期');
  533. }
  534. if ($user_coupon_info['type'] == 1) {
  535. //打折券
  536. if ($user_coupon_info['money'] < 0 || $user_coupon_info['money'] > 100) {
  537. $this->error('优惠券折扣错误,请联系管理员');
  538. break;
  539. }
  540. } else {
  541. //抵扣券
  542. //会员价和优惠券是否可以叠加使用:0=否,1=是
  543. if ($info['is_overlying'] == 0) {
  544. if ($info['price'] < $user_coupon_info['minmoney']) {
  545. $this->error('优惠券使用条件不满足');
  546. break;
  547. }
  548. } else {
  549. if ($vipprice < $user_coupon_info['minmoney']) {
  550. $this->error('优惠券使用条件不满足');
  551. break;
  552. }
  553. }
  554. }
  555. }
  556. //判断价格
  557. //会员价和优惠券是否可以叠加使用:0=否,1=是
  558. if ($info['is_overlying'] == 0) {
  559. if ($v['coupon_id']) { //使用优惠券
  560. if ($v['vipprice'] != $info['price']) {
  561. $this->error('会员价显示错误');
  562. break;
  563. }
  564. if ($user_coupon_info['type'] == 1) {
  565. //打折券
  566. $price = $info['price'] * $user_coupon_info['money'] / 100;
  567. } else {
  568. //抵扣券
  569. $price = $info['price'] - $user_coupon_info['money'];
  570. }
  571. } else {
  572. $price = $vipprice;
  573. }
  574. } else {
  575. if ($vipprice != $v['vipprice']) {
  576. $this->error('会员价显示错误');
  577. break;
  578. }
  579. if ($v['coupon_id']) { //使用优惠券
  580. if ($user_coupon_info['type'] == 1) {
  581. //打折券
  582. $price = $vipprice * $user_coupon_info['money'] / 100;
  583. } else {
  584. //抵扣券
  585. $price = $vipprice - $user_coupon_info['money'];
  586. }
  587. } else {
  588. $price = $vipprice;
  589. }
  590. }
  591. //判断小计
  592. if ($price != $v['price']) {
  593. $this->error('小计显示错误');
  594. break;
  595. }
  596. $data['vipprice'] = $v['vipprice']; //会员价
  597. $data['coupon_id'] = $v['coupon_id']; //优惠券id
  598. if ($v['coupon_id']) {
  599. $data['coupontype'] = $user_coupon_info['type'];
  600. $data['couponprice'] = $user_coupon_info['money'];
  601. }
  602. }
  603. $data['name'] = $this->auth->realname;
  604. $data['idcard'] = $this->auth->idcard;
  605. $data['mobile'] = $this->auth->mobile;
  606. $data['emergencycontact'] = $this->auth->emergencycontact;
  607. $data['contactmobile'] = $this->auth->contactmobile;
  608. } else {
  609. //帮人报名判断年龄 报名信息
  610. if ($info['maxage'] > 0) {
  611. $age = $this->idcardage($v['idcard']);
  612. if ($age < $info['minage'] || $age > $info['maxage']) {
  613. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  614. break;
  615. }
  616. }
  617. if (!$v['name'] || iconv_strlen($v['name'], 'utf-8') > 50) {
  618. $this->error('请输入正确姓名');
  619. break;
  620. }
  621. if (iconv_strlen($v['idcard'], 'utf-8') != 18) {
  622. $this->error('请输入正确身份证号');
  623. break;
  624. }
  625. if (!is_mobile($v['mobile'])) {
  626. $this->error('请输入正确手机号');
  627. break;
  628. }
  629. if (!$v['emergencycontact'] || iconv_strlen($v['emergencycontact'], 'utf-8') > 50) {
  630. $this->error('请输入紧急联系人');
  631. break;
  632. }
  633. if (!is_mobile($v['contactmobile'])) {
  634. $this->error('请输入正确紧急联系人方式');
  635. break;
  636. }
  637. //判断是否符合满几人减免一人费用
  638. //会员权限
  639. if ($vip_info['manypeople'] > 1 && $k == $vip_info['manypeople'] - 1) {
  640. if ($v['price'] != 0) {
  641. $this->error('小计显示错误');
  642. break;
  643. }
  644. } else {
  645. if ($v['price'] != $info['price']) {
  646. $this->error('小计显示错误');
  647. break;
  648. }
  649. }
  650. $data['name'] = $v['name'];
  651. $data['idcard'] = $v['idcard'];
  652. $data['mobile'] = $v['mobile'];
  653. $data['emergencycontact'] = $v['emergencycontact'];
  654. $data['contactmobile'] = $v['contactmobile'];
  655. $data['vipprice'] = $v['price']; //会员价
  656. }
  657. $data['active_id'] = $id;
  658. $data['user_id'] = $this->auth->id;
  659. $data['credtype'] = $v['credtype'];
  660. $data['insurance'] = $v['insurance'];
  661. $data['originalprice'] = $info['price'];
  662. $data['is_free'] = $v['is_free'];
  663. $data['price'] = $v['price']; //小计
  664. $data['is_self'] = $v['is_self'];
  665. $data['createtime'] = time();
  666. array_push($_data, $data);
  667. $total_amount += $v['price'];
  668. }
  669. if ($total_amount != $total_price) {
  670. $this->error('合计价格错误');
  671. }
  672. if ($paytype == 0) { //余额支付
  673. if ($this->auth->money < $total_amount) {
  674. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  675. }
  676. }
  677. //构建订单信息
  678. $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  679. $order_data['active_id'] = $id;
  680. $order_data['user_id'] = $this->auth->id;
  681. $order_data['paytype'] = $paytype;
  682. $order_data['price'] = $total_amount;
  683. $order_data['number'] = count($active_people_arr);
  684. $order_data['status'] = $paytype == 1 ? 0 : 1;
  685. $order_data['createtime'] = time();
  686. //开始事务
  687. Db::startTrans();
  688. //修改活动表数据
  689. $active_rs = Db::name('active')->where(['id' => $id, 'currentperson' => $info['currentperson']])->setField('currentperson', $info['currentperson'] + count($active_people));
  690. if (!$active_rs) {
  691. Db::rollback();
  692. $this->error('网络延迟,请稍后再试');
  693. }
  694. //添加订单
  695. $rs = Db::name('active_order')->insertGetId($order_data);
  696. if (!$rs) {
  697. Db::rollback();
  698. $this->error('网络延迟,请稍后再试');
  699. }
  700. //添加人员信息
  701. foreach ($_data as &$v) {
  702. $v['order_id'] = $rs;
  703. $rt = $active_people->insertGetId($v);
  704. if (!$rt) {
  705. Db::rollback();
  706. $this->error('网络延迟,请稍后再试');
  707. }
  708. }
  709. //扣除免费次数
  710. if ($info['is_free'] == 1 && $active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['is_free'] == 1) {
  711. $freenumber = $this->auth->freenumber - 1;
  712. $user_rs = Db::name('user')->where(['id' => $this->auth->id, 'freenumber' => $this->auth->freenumber])->setField('freenumber', $freenumber);
  713. if (!$user_rs) {
  714. Db::rollback();
  715. $this->error('网络延迟,请稍后再试');
  716. }
  717. }
  718. //扣款 支付方式:0=余额,1=微信
  719. if ($paytype == 0) {
  720. $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2);
  721. if ($res != 1) {
  722. Db::rollback();
  723. $this->error('余额资金异常,请联系管理员');
  724. }
  725. Db::commit();
  726. $this->success('报名成功');
  727. } else {
  728. //生成支付订单记录
  729. $rechar_order['user_id'] = $this->auth->id;
  730. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  731. $rechar_order['money'] = $total_amount;
  732. $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
  733. $rechar_order['pay_type'] = 'wechat';
  734. $rechar_order['relation_id'] = $rs;
  735. $rechar_order['createtime'] = time();
  736. $rechar_order['money'] = $total_amount;
  737. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  738. if (!$result) {
  739. Db::rollback();
  740. $this->error('网络延迟,请稍后再试');
  741. }
  742. //构建支付链接数据
  743. $wxData['body'] = '报名活动支付';
  744. $wxData['out_trade_no'] = $rechar_order['order_no'];
  745. $wxData['total_fee'] = $total_amount;
  746. // $wxData['total_fee'] = 0.01;
  747. $wxData['openid'] = $this->auth->openid;
  748. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  749. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  750. $doResult = $wxPay->WxPayJs($wxData);
  751. $this->success('微信支付参数返回成功', $doResult);
  752. }
  753. }
  754. //根据身份证号获取年龄
  755. public function idcardage($idcard = '') {
  756. //截取身份证里的出生日期
  757. $year = substr($idcard, 6, 4);
  758. $month = substr($idcard, 10, 2);
  759. $day = substr($idcard, 12, 2);
  760. //获取当前日期
  761. $current_year = date('Y');
  762. $current_month = date('m');
  763. $current_day = date('d');
  764. //计算年龄
  765. $age = $current_year - $year;//今年减去生日年
  766. if ($month > $current_month || ($month == $current_month && $day > $current_day)) {
  767. //如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  768. $age--;
  769. }
  770. return $age;
  771. }
  772. //私人订制类型
  773. public function personaltype() {
  774. $list = Db::name('personal_type')->field('id, name')->order('weigh', 'desc')->select();
  775. $this->success('私人订制类型', $list);
  776. }
  777. //私人订制活动类型
  778. public function personalactivetype() {
  779. $list = Db::name('personal_active_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
  780. $list = $this->getchildtype($list);
  781. $this->success('私人订制活动类型', $list);
  782. }
  783. //无限级私人订制活动类型
  784. public function getchildtype($list = [])
  785. {
  786. $complaint_type = Db::name('personal_active_type');
  787. foreach ($list as &$v) {
  788. $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
  789. if ($child) {
  790. $child = $this->getchildtype($child);
  791. }
  792. $v['child'] = $child;
  793. }
  794. return $list;
  795. }
  796. //车辆类型
  797. public function car() {
  798. $list = Db::name('car')->field('id, name, desc')->order('weigh', 'desc')->select();
  799. $this->success('车辆类型', $list);
  800. }
  801. //领队
  802. public function leader() {
  803. $list = Db::name('leader')->field('id, name')->order('weigh', 'desc')->select();
  804. $this->success('领队', $list);
  805. }
  806. //私人订制出行方向
  807. public function personaldirection() {
  808. $list = Db::name('personal_direction')->field('id, name')->order('weigh', 'desc')->select();
  809. $this->success('私人订制出行方向', $list);
  810. }
  811. //私人订制
  812. public function personalactive() {
  813. $type = input('type', '', 'trim'); //类型
  814. $number = input('number', 0, 'intval'); //出行人数
  815. $traveltime = input('traveltime', '', 'strtotime'); //出行时间
  816. $traveday = input('traveday', 0, 'intval'); //出行天数
  817. $activetype = input('activetype', '', 'trim'); //活动类型
  818. $car = input('car', '', 'trim'); //车辆
  819. $leader = input('leader', '', 'trim'); //领队
  820. $travedirection = input('travedirection', '', 'trim'); //出行方向
  821. $freerange = input('freerange', '', 'trim'); //空闲时段
  822. $remark = input('remark', '', 'trim'); //留言
  823. if (!$type || iconv_strlen($type, 'utf-8') > 50) {
  824. $this->error('请选择类型');
  825. }
  826. if ($number <= 0) {
  827. $this->error('请填写出行人数');
  828. }
  829. if ($traveltime < time()) {
  830. $this->error('请选择正确出行时间');
  831. }
  832. if ($traveday <= 0) {
  833. $this->error('请填写正确出行天数');
  834. }
  835. if (!$activetype || iconv_strlen($activetype, 'utf-8') > 50) {
  836. $this->error('请选择活动类型');
  837. }
  838. if ($car && iconv_strlen($car, 'utf-8') > 50) {
  839. $this->error('请选择车辆');
  840. }
  841. if ($leader && iconv_strlen($leader, 'utf-8') > 50) {
  842. $this->error('请选择领队');
  843. }
  844. if (!$travedirection || iconv_strlen($travedirection, 'utf-8') > 50) {
  845. $this->error('请选择出行方向');
  846. }
  847. if (!$freerange || iconv_strlen($freerange, 'utf-8') > 50) {
  848. $this->error('请选择空闲时段');
  849. }
  850. if (iconv_strlen($remark, 'utf-8') > 500) {
  851. $this->error('留言最多500字');
  852. }
  853. $data['user_id'] = $this->auth->id;
  854. $data['type'] = $type;
  855. $data['number'] = $number;
  856. $data['traveltime'] = $traveltime;
  857. $data['traveday'] = $traveday;
  858. $data['activetype'] = $activetype;
  859. $data['car'] = $car;
  860. $data['leader'] = $leader;
  861. $data['travedirection'] = $travedirection;
  862. $data['freerange'] = $freerange;
  863. $data['remark'] = $remark;
  864. $data['createtime'] = time();
  865. $rs = Db::name('personal_order')->insertGetId($data);
  866. if (!$rs) {
  867. $this->error('提交失败');
  868. }
  869. $this->success('提交成功');
  870. }
  871. //查询轮播图优惠券列表
  872. public function bannercoupon() {
  873. $list = Db::name('coupon')->field('id, title, desc, type, money')
  874. ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
  875. $user_coupon = Db::name('user_coupon');
  876. foreach ($list as &$v) {
  877. $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
  878. }
  879. $this->success('查询轮播图优惠券列表', $list);
  880. }
  881. //领取轮播图优惠券
  882. public function receivebannercoupon() {
  883. $id = input('id', 0, 'intval'); //优惠券id
  884. if (!$id) {
  885. $this->error('参数缺失');
  886. }
  887. $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
  888. if (!$info) {
  889. $this->error('优惠券不存在');
  890. }
  891. if ($info['status'] != 1) {
  892. $this->error('优惠券已下架');
  893. }
  894. //查询是否已领取
  895. $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  896. if ($count) {
  897. $this->error('您已经领取过了');
  898. }
  899. $data['user_id'] = $this->auth->id;
  900. $data['coupon_id'] = $id;
  901. $data['title'] = $info['title'];
  902. $data['desc'] = $info['desc'];
  903. $data['type'] = $info['type'];
  904. $data['money'] = $info['money'];
  905. $data['minmoney'] = $info['minmoney'];
  906. $data['purpose'] = $info['purpose'];
  907. $data['starttime'] = time();
  908. $data['endtime'] = time() + $info['effectiveday'] * 86400;
  909. $data['createtime'] = time();
  910. //开启事务
  911. Db::startTrans();
  912. //添加领取记录
  913. $rs = Db::name('user_coupon')->insertGetId($data);
  914. if (!$rs) {
  915. Db::rollback();
  916. $this->error('领取失败');
  917. }
  918. $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  919. if ($rt != 1) {
  920. Db::rollback();
  921. $this->error('领取失败');
  922. }
  923. Db::commit();
  924. $this->success('领取成功');
  925. }
  926. //体验会员列表
  927. public function experiencevip() {
  928. $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->select();
  929. $this->success('体验会员列表', $list);
  930. }
  931. //购买体验会员
  932. public function buyexperiencevip() {
  933. //检查是否已经开通体验会员
  934. if ($this->auth->experiencetime >= time()) {
  935. $this->error('您已开通体验会员,不能重复开通');
  936. }
  937. $id = input('id', 0, 'intval');
  938. if (!$id) {
  939. $this->error('参数缺失');
  940. }
  941. $info = Db::name('vip')->where(['id' => $id])->find();
  942. if (!$info) {
  943. $this->error('会员不存在');
  944. }
  945. if ($info['status'] != 1) {
  946. $this->error('体验会员已下架');
  947. }
  948. if ($info['price'] <= 0) {
  949. $this->error('会员价格异常');
  950. }
  951. //体验会员等级必须大于成长值会员
  952. if ($id <= $this->auth->maxlevel) {
  953. $this->error('请开通更高等级体验会员');
  954. }
  955. //判断余额
  956. if ($this->auth->money < $info['price']) {
  957. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  958. }
  959. $data['user_id'] = $this->auth->id;
  960. $data['vip_id'] = $id;
  961. $data['title'] = $info['title'];
  962. $data['level'] = $info['level'];
  963. $data['growthvalue'] = $info['growthvalue'];
  964. $data['free'] = $info['free'];
  965. $data['price'] = $info['price'];
  966. $data['endtime'] = time() + $info['day'] * 86400;
  967. $data['vipdiscount'] = $info['vipdiscount'];
  968. $data['birthdiscount'] = $info['birthdiscount'];
  969. $data['manypeople'] = $info['manypeople'];
  970. $data['createtime'] = time();
  971. //开启事务
  972. Db::startTrans();
  973. //添加开通记录
  974. $rs = Db::name('vip_log')->insertGetId($data);
  975. if (!$rs) {
  976. Db::rollback();
  977. $this->error('开通失败');
  978. }
  979. //扣除余额
  980. $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4);
  981. if ($result != 1) {
  982. Db::rollback();
  983. $this->error('资金异常,请联系管理员');
  984. }
  985. //成长值会员信息
  986. $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
  987. //修改用户表信息
  988. $user_data['experiencelevel'] = $id;
  989. $user_data['experiencetime'] = $data['endtime'];
  990. $user_data['maxlevel'] = $id;
  991. $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
  992. $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
  993. $rt = Db::name('user')->where([
  994. 'user_id' => $this->auth->id,
  995. 'experiencelevel' => $this->auth->experiencelevel,
  996. 'maxlevel' => $this->auth->maxlevel,
  997. 'freenumber' => $this->auth->freenumber])->setField($user_data);
  998. if (!$rt) {
  999. Db::rollback();
  1000. $this->error('开通失败');
  1001. }
  1002. Db::commit();
  1003. $this->success('开通成功');
  1004. }
  1005. }