Index.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 = json_decode($active_people, true);
  425. if (!$active_people) {
  426. $this->error('请添加报名人员信息');
  427. }
  428. if ($info['currentperson'] + count($active_people) > $info['maxperson']) {
  429. $this->error('活动名额不足');
  430. }
  431. $_data = [];
  432. $total_amount = 0; //总价格验证
  433. $active_people = Db::name('active_people'); //报名人员表
  434. $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
  435. $vip = Db::name('vip');
  436. $user_coupon = Db::name('user_coupon');
  437. foreach ($active_people as &$v) {
  438. $data = [];
  439. //判断是否报名过
  440. $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id');
  441. if ($count) {
  442. $this->error($v['name'] . $v['idcard'] . '已报名过该活动');
  443. break;
  444. }
  445. $count2 = $active_people_modify->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => 0])->count('id');
  446. if ($count2) {
  447. $this->error($v['name'] . $v['idcard'] . '已提交过修改,请等待审核');
  448. break;
  449. }
  450. //判断证件类型和保险
  451. if (!$v['credtype'] || iconv_strlen($v['credtype'], 'utf-8') > 50) {
  452. $this->error('证件类型错误');
  453. break;
  454. }
  455. if (!$v['insurance'] || iconv_strlen($v['insurance'], 'utf-8') > 50) {
  456. $this->error('保险信息错误');
  457. break;
  458. }
  459. //判断用户信息
  460. if ($v['is_self']) {
  461. //本人判断年龄 价格
  462. if ($info['maxage'] > 0) {
  463. $age = $this->idcardage($this->auth->idcard);
  464. if ($age < $info['minage'] || $age > $info['maxage']) {
  465. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  466. break;
  467. }
  468. }
  469. if ($v['is_free'] == 1) { //使用免费次数
  470. if ($info['is_free'] != 1) {
  471. $this->error('活动暂不支持免费体验');
  472. break;
  473. }
  474. if ($v['vipprice'] != 0 || $v['price'] != 0) {
  475. $this->error($this->auth->realname . '价格错误');
  476. break;
  477. }
  478. if ($v['coupon_id']) {
  479. $this->error('使用免费体验,无法使用优惠券');
  480. break;
  481. }
  482. } else { //不使用免费次数
  483. //会员价和优惠券是否可以叠加使用:0=否,1=是
  484. if ($info['is_overlying'] == 0 && $v['vipprice'] != $info['price'] && $v['coupon_id']) {
  485. $this->error('该活动不支持会员价和优惠券同时使用');
  486. break;
  487. }
  488. //计算会员价, 会员价优先顺序: 生日 > 女生特权日 > 会员价格
  489. $birthday = date('md', $this->auth->birthday);
  490. $now_day = date('md', time());
  491. if ($birthday == $now_day) {
  492. //生日折扣
  493. $vip_info = $vip->find($this->auth->maxlevel);
  494. if (!$vip_info) {
  495. $this->error('会员信息缺失,请联系管理员');
  496. break;
  497. }
  498. if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
  499. $this->error('会员生日折扣错误,请联系管理员');
  500. break;
  501. }
  502. $discount = $vip_info['birthdiscount'];
  503. } elseif ($info['girldiscount'] < 100 && $info['girldiscount'] > 0 && $this->auth->gender == 2) {
  504. //女生特权日折扣
  505. $discount = $info['girldiscount'];
  506. } else {
  507. //会员折扣
  508. $vip_info = $vip->find($this->auth->maxlevel);
  509. if (!$vip_info) {
  510. $this->error('会员信息缺失,请联系管理员');
  511. break;
  512. }
  513. if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
  514. $this->error('会员折扣错误,请联系管理员');
  515. break;
  516. }
  517. $discount = $vip_info['vipdiscount'];
  518. }
  519. $vipprice = $info['price'] * $discount / 100; //会员价
  520. //查询优惠券
  521. if ($v['coupon_id']) {
  522. $user_coupon_info = $user_coupon->where(['id' => $v['coupon_id'], 'user_id' => $this->auth->id])->find();
  523. if (!$user_coupon_info) {
  524. $this->error('优惠券不存在');
  525. }
  526. if ($user_coupon_info['status'] != 0) {
  527. $this->error('优惠券已使用');
  528. }
  529. if ($user_coupon_info['endtime'] < time()) {
  530. $this->error('优惠券已过期');
  531. }
  532. if ($user_coupon_info['type'] == 1) {
  533. //打折券
  534. if ($user_coupon_info['money'] < 0 || $user_coupon_info['money'] > 100) {
  535. $this->error('优惠券折扣错误,请联系管理员');
  536. break;
  537. }
  538. } else {
  539. //抵扣券
  540. //会员价和优惠券是否可以叠加使用:0=否,1=是
  541. if ($info['is_overlying'] == 0) {
  542. if ($info['price'] < $user_coupon_info['minmoney']) {
  543. $this->error('优惠券使用条件不满足');
  544. break;
  545. }
  546. } else {
  547. if ($vipprice < $user_coupon_info['minmoney']) {
  548. $this->error('优惠券使用条件不满足');
  549. break;
  550. }
  551. }
  552. }
  553. }
  554. //判断价格
  555. //会员价和优惠券是否可以叠加使用:0=否,1=是
  556. if ($info['is_overlying'] == 0) {
  557. if ($v['coupon_id']) { //使用优惠券
  558. if ($v['vipprice'] != $info['price']) {
  559. $this->error('会员价显示错误');
  560. break;
  561. }
  562. if ($user_coupon_info['type'] == 1) {
  563. //打折券
  564. $price = $info['price'] * $user_coupon_info['money'] / 100;
  565. } else {
  566. //抵扣券
  567. $price = $info['price'] - $user_coupon_info['money'];
  568. }
  569. } else {
  570. $price = $vipprice;
  571. }
  572. } else {
  573. if ($vipprice != $v['vipprice']) {
  574. $this->error('会员价显示错误');
  575. break;
  576. }
  577. if ($v['coupon_id']) { //使用优惠券
  578. if ($user_coupon_info['type'] == 1) {
  579. //打折券
  580. $price = $vipprice * $user_coupon_info['money'] / 100;
  581. } else {
  582. //抵扣券
  583. $price = $vipprice - $user_coupon_info['money'];
  584. }
  585. } else {
  586. $price = $vipprice;
  587. }
  588. }
  589. //判断小计
  590. if ($price != $v['price']) {
  591. $this->error('小计显示错误');
  592. break;
  593. }
  594. $data['vipprice'] = $v['vipprice']; //会员价
  595. $data['coupon_id'] = $v['coupon_id']; //优惠券id
  596. if ($v['coupon_id']) {
  597. $data['coupontype'] = $user_coupon_info['type'];
  598. $data['couponprice'] = $user_coupon_info['money'];
  599. }
  600. }
  601. $data['name'] = $this->auth->realname;
  602. $data['idcard'] = $this->auth->idcard;
  603. $data['mobile'] = $this->auth->mobile;
  604. $data['emergencycontact'] = $this->auth->emergencycontact;
  605. $data['contactmobile'] = $this->auth->contactmobile;
  606. } else {
  607. //帮人报名判断年龄 报名信息
  608. if ($info['maxage'] > 0) {
  609. $age = $this->idcardage($v['idcard']);
  610. if ($age < $info['minage'] || $age > $info['maxage']) {
  611. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  612. break;
  613. }
  614. }
  615. if (!$v['name'] || iconv_strlen($v['name'], 'utf-8') > 50) {
  616. $this->error('请输入正确姓名');
  617. break;
  618. }
  619. if (iconv_strlen($v['idcard'], 'utf-8') != 18) {
  620. $this->error('请输入正确身份证号');
  621. break;
  622. }
  623. if (!is_mobile($v['mobile'])) {
  624. $this->error('请输入正确手机号');
  625. break;
  626. }
  627. if (!$v['emergencycontact'] || iconv_strlen($v['emergencycontact'], 'utf-8') > 50) {
  628. $this->error('请输入紧急联系人');
  629. break;
  630. }
  631. if (!is_mobile($v['contactmobile'])) {
  632. $this->error('请输入正确紧急联系人方式');
  633. break;
  634. }
  635. if ($v['price'] != $info['price']) {
  636. $this->error('小计显示错误');
  637. break;
  638. }
  639. $data['name'] = $v['name'];
  640. $data['idcard'] = $v['idcard'];
  641. $data['mobile'] = $v['mobile'];
  642. $data['emergencycontact'] = $v['emergencycontact'];
  643. $data['contactmobile'] = $v['contactmobile'];
  644. $data['vipprice'] = $info['price']; //会员价
  645. }
  646. $data['active_id'] = $id;
  647. $data['user_id'] = $this->auth->id;
  648. $data['credtype'] = $v['credtype'];
  649. $data['insurance'] = $v['insurance'];
  650. $data['originalprice'] = $info['price'];
  651. $data['is_free'] = $v['is_free'];
  652. $data['price'] = $v['price']; //小计
  653. $data['is_self'] = $v['is_self'];
  654. $data['createtime'] = time();
  655. array_push($_data, $data);
  656. $total_amount += $v['price'];
  657. }
  658. if ($total_amount != $total_price) {
  659. $this->error('合计价格错误');
  660. }
  661. if ($paytype == 0) { //余额支付
  662. if ($this->auth->money < $total_amount) {
  663. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  664. }
  665. }
  666. //构建订单信息
  667. $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  668. $order_data['active_id'] = $id;
  669. $order_data['user_id'] = $this->auth->id;
  670. $order_data['paytype'] = $paytype;
  671. $order_data['price'] = $total_amount;
  672. $order_data['number'] = count($active_people);
  673. $order_data['status'] = $paytype == 1 ? 0 : 1;
  674. $order_data['createtime'] = time();
  675. //开始事务
  676. Db::startTrans();
  677. //修改活动表数据
  678. $active_rs = Db::name('active')->where(['id' => $id, 'currentperson' => $info['currentperson']])->setField('currentperson', $info['currentperson'] + count($active_people));
  679. if (!$active_rs) {
  680. Db::rollback();
  681. $this->error('网络延迟,请稍后再试');
  682. }
  683. //添加订单
  684. $rs = Db::name('active_order')->insertGetId($order_data);
  685. if (!$rs) {
  686. Db::rollback();
  687. $this->error('网络延迟,请稍后再试');
  688. }
  689. //添加人员信息
  690. foreach ($_data as &$v) {
  691. $v['order_id'] = $rs;
  692. $rt = $active_people->insertGetId($v);
  693. if (!$rt) {
  694. Db::rollback();
  695. $this->error('网络延迟,请稍后再试');
  696. }
  697. }
  698. //扣款 支付方式:0=余额,1=微信
  699. if ($paytype == 0) {
  700. $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2);
  701. if ($res != 1) {
  702. Db::rollback();
  703. $this->error('余额资金异常,请联系管理员');
  704. }
  705. Db::commit();
  706. $this->success('报名成功');
  707. } else {
  708. //生成支付订单记录
  709. $rechar_order['user_id'] = $this->auth->id;
  710. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  711. $rechar_order['money'] = $total_amount;
  712. $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
  713. $rechar_order['pay_type'] = 'wechat';
  714. $rechar_order['relation_id'] = $rs;
  715. $rechar_order['createtime'] = time();
  716. $rechar_order['money'] = $total_amount;
  717. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  718. if (!$result) {
  719. Db::rollback();
  720. $this->error('网络延迟,请稍后再试');
  721. }
  722. //构建支付链接数据
  723. $wxData['body'] = '报名活动支付';
  724. $wxData['out_trade_no'] = $rechar_order['order_no'];
  725. $wxData['total_fee'] = $total_amount;
  726. // $wxData['total_fee'] = 0.01;
  727. $wxData['openid'] = $this->auth->openid;
  728. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  729. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  730. $doResult = $wxPay->WxPayJs($wxData);
  731. $this->success('微信支付参数返回成功', $doResult);
  732. }
  733. }
  734. //根据身份证号获取年龄
  735. public function idcardage($idcard = '') {
  736. //截取身份证里的出生日期
  737. $year = substr($idcard, 6, 4);
  738. $month = substr($idcard, 10, 2);
  739. $day = substr($idcard, 12, 2);
  740. //获取当前日期
  741. $current_year = date('Y');
  742. $current_month = date('m');
  743. $current_day = date('d');
  744. //计算年龄
  745. $age = $current_year - $year;//今年减去生日年
  746. if ($month > $current_month || ($month == $current_month && $day > $current_day)) {
  747. //如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  748. $age--;
  749. }
  750. return $age;
  751. }
  752. //私人订制类型
  753. public function personaltype() {
  754. $list = Db::name('personal_type')->field('id, name')->order('weigh', 'desc')->select();
  755. $this->success('私人订制类型', $list);
  756. }
  757. //私人订制活动类型
  758. public function personalactivetype() {
  759. $list = Db::name('personal_active_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
  760. $list = $this->getchildtype($list);
  761. $this->success('私人订制活动类型', $list);
  762. }
  763. //无限级私人订制活动类型
  764. public function getchildtype($list = [])
  765. {
  766. $complaint_type = Db::name('personal_active_type');
  767. foreach ($list as &$v) {
  768. $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
  769. if ($child) {
  770. $child = $this->getchildtype($child);
  771. }
  772. $v['child'] = $child;
  773. }
  774. return $list;
  775. }
  776. //车辆类型
  777. public function car() {
  778. $list = Db::name('car')->field('id, name, desc')->order('weigh', 'desc')->select();
  779. $this->success('车辆类型', $list);
  780. }
  781. //领队
  782. public function leader() {
  783. $list = Db::name('leader')->field('id, name')->order('weigh', 'desc')->select();
  784. $this->success('领队', $list);
  785. }
  786. //私人订制出行方向
  787. public function personaldirection() {
  788. $list = Db::name('personal_direction')->field('id, name')->order('weigh', 'desc')->select();
  789. $this->success('私人订制出行方向', $list);
  790. }
  791. //私人订制
  792. public function personalactive() {
  793. $type = input('type', '', 'trim'); //类型
  794. $number = input('number', 0, 'intval'); //出行人数
  795. $traveltime = input('traveltime', '', 'strtotime'); //出行时间
  796. $traveday = input('traveday', 0, 'intval'); //出行天数
  797. $activetype = input('activetype', '', 'trim'); //活动类型
  798. $car = input('car', '', 'trim'); //车辆
  799. $leader = input('leader', '', 'trim'); //领队
  800. $travedirection = input('travedirection', '', 'trim'); //出行方向
  801. $freerange = input('freerange', '', 'trim'); //空闲时段
  802. $remark = input('remark', '', 'trim'); //留言
  803. if (!$type || iconv_strlen($type, 'utf-8') > 50) {
  804. $this->error('请选择类型');
  805. }
  806. if ($number <= 0) {
  807. $this->error('请填写出行人数');
  808. }
  809. if ($traveltime < time()) {
  810. $this->error('请选择正确出行时间');
  811. }
  812. if ($traveday <= 0) {
  813. $this->error('请填写正确出行天数');
  814. }
  815. if (!$activetype || iconv_strlen($activetype, 'utf-8') > 50) {
  816. $this->error('请选择活动类型');
  817. }
  818. if ($car && iconv_strlen($car, 'utf-8') > 50) {
  819. $this->error('请选择车辆');
  820. }
  821. if ($leader && iconv_strlen($leader, 'utf-8') > 50) {
  822. $this->error('请选择领队');
  823. }
  824. if (!$travedirection || iconv_strlen($travedirection, 'utf-8') > 50) {
  825. $this->error('请选择出行方向');
  826. }
  827. if (!$freerange || iconv_strlen($freerange, 'utf-8') > 50) {
  828. $this->error('请选择空闲时段');
  829. }
  830. if (iconv_strlen($remark, 'utf-8') > 500) {
  831. $this->error('留言最多500字');
  832. }
  833. $data['user_id'] = $this->auth->id;
  834. $data['type'] = $type;
  835. $data['number'] = $number;
  836. $data['traveltime'] = $traveltime;
  837. $data['traveday'] = $traveday;
  838. $data['activetype'] = $activetype;
  839. $data['car'] = $car;
  840. $data['leader'] = $leader;
  841. $data['travedirection'] = $travedirection;
  842. $data['freerange'] = $freerange;
  843. $data['remark'] = $remark;
  844. $data['createtime'] = time();
  845. $rs = Db::name('personal_order')->insertGetId($data);
  846. if (!$rs) {
  847. $this->error('提交失败');
  848. }
  849. $this->success('提交成功');
  850. }
  851. //查询轮播图优惠券列表
  852. public function bannercoupon() {
  853. $list = Db::name('coupon')->field('id, title, desc, type, money')
  854. ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
  855. $user_coupon = Db::name('user_coupon');
  856. foreach ($list as &$v) {
  857. $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
  858. }
  859. $this->success('查询轮播图优惠券列表', $list);
  860. }
  861. //领取轮播图优惠券
  862. public function receivebannercoupon() {
  863. $id = input('id', 0, 'intval'); //优惠券id
  864. if (!$id) {
  865. $this->error('参数缺失');
  866. }
  867. $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
  868. if (!$info) {
  869. $this->error('优惠券不存在');
  870. }
  871. if ($info['status'] != 1) {
  872. $this->error('优惠券已下架');
  873. }
  874. //查询是否已领取
  875. $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  876. if ($count) {
  877. $this->error('您已经领取过了');
  878. }
  879. $data['user_id'] = $this->auth->id;
  880. $data['coupon_id'] = $id;
  881. $data['title'] = $info['title'];
  882. $data['desc'] = $info['desc'];
  883. $data['type'] = $info['type'];
  884. $data['money'] = $info['money'];
  885. $data['minmoney'] = $info['minmoney'];
  886. $data['purpose'] = $info['purpose'];
  887. $data['starttime'] = time();
  888. $data['endtime'] = time() + $info['effectiveday'] * 86400;
  889. $data['createtime'] = time();
  890. //开启事务
  891. Db::startTrans();
  892. //添加领取记录
  893. $rs = Db::name('user_coupon')->insertGetId($data);
  894. if (!$rs) {
  895. Db::rollback();
  896. $this->error('领取失败');
  897. }
  898. $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  899. if ($rt != 1) {
  900. Db::rollback();
  901. $this->error('领取失败');
  902. }
  903. Db::commit();
  904. $this->success('领取成功');
  905. }
  906. //体验会员列表
  907. public function experiencevip() {
  908. $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->select();
  909. $this->success('体验会员列表', $list);
  910. }
  911. //购买体验会员
  912. public function buyexperiencevip() {
  913. //检查是否已经开通体验会员
  914. if ($this->auth->experiencetime >= time()) {
  915. $this->error('您已开通体验会员,不能重复开通');
  916. }
  917. $id = input('id', 0, 'intval');
  918. if (!$id) {
  919. $this->error('参数缺失');
  920. }
  921. $info = Db::name('vip')->where(['id' => $id])->find();
  922. if (!$info) {
  923. $this->error('会员不存在');
  924. }
  925. if ($info['status'] != 1) {
  926. $this->error('体验会员已下架');
  927. }
  928. //体验会员等级必须大于成长值会员
  929. if ($id <= $this->auth->maxlevel) {
  930. $this->error('请开通更高等级体验会员');
  931. }
  932. //判断余额
  933. if ($this->auth->money < $info['price']) {
  934. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  935. }
  936. $data['user_id'] = $this->auth->id;
  937. $data['vip_id'] = $id;
  938. $data['title'] = $info['title'];
  939. $data['level'] = $info['level'];
  940. $data['growthvalue'] = $info['growthvalue'];
  941. $data['free'] = $info['free'];
  942. $data['price'] = $info['price'];
  943. $data['endtime'] = time() + $info['day'] * 86400;
  944. $data['vipdiscount'] = $info['vipdiscount'];
  945. $data['birthdiscount'] = $info['birthdiscount'];
  946. $data['manypeople'] = $info['manypeople'];
  947. $data['createtime'] = time();
  948. //开启事务
  949. Db::startTrans();
  950. //添加领取记录
  951. $rs = Db::name('user_coupon')->insertGetId($data);
  952. if (!$rs) {
  953. Db::rollback();
  954. $this->error('领取失败');
  955. }
  956. $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  957. if ($rt != 1) {
  958. Db::rollback();
  959. $this->error('领取失败');
  960. }
  961. Db::commit();
  962. $this->success('领取成功');
  963. }
  964. }