Index.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Think\Cache;
  5. use think\Db;
  6. use wxpay;
  7. use Qcloud\Cos\Client;
  8. use Qcloud\Cos\Exception\ServiceResponseException;
  9. /**
  10. * 首页接口
  11. */
  12. class Index extends Api
  13. {
  14. protected $noNeedLogin = ['banner', 'activelist', 'personaltype', 'personalactivetype', 'car', 'leader', 'personaldirection', 'activeinfo', 'position', 'gamelist'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 首页
  18. *
  19. */
  20. public function index()
  21. {
  22. $this->success('请求成功');
  23. }
  24. //轮播图
  25. public function banner()
  26. {
  27. $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 0])->order('weigh', 'desc')->select();
  28. $list = list_domain_image($list, ['image']);
  29. $this->success('轮播图', $list);
  30. }
  31. //活动列表
  32. public function activelist() {
  33. $type = input('type', 0, 'intval'); //分类:1=休闲,2=中度
  34. $keyword = input('keyword', '', 'trim'); //关键字
  35. // $where['signupendtime'] = ['gt', time()];
  36. $where['status'] = ['neq', 3];
  37. $where['showstatus'] = 1;
  38. if ($type) {
  39. $where['type'] = $type;
  40. }
  41. if ($keyword !== '') {
  42. $where['title|desc|remark|collectionplace|leader'] = ['like', '%'.$keyword.'%'];
  43. }
  44. $list = Db::name('active')->field('id, type, title, desc, remark, image, price, maxperson, currentperson, status')
  45. ->where($where)->page($this->page, $this->pagenum)->order('weigh, createtime desc')->select();
  46. $list = list_domain_image($list, ['image']);
  47. foreach ($list as &$v) {
  48. if ($v['maxperson'] <= $v['currentperson']) {
  49. $v['is_full'] = 1;
  50. } else {
  51. $v['is_full'] = 0;
  52. }
  53. $v['surplusperson'] = $v['maxperson'] - $v['currentperson'];
  54. }
  55. $this->success('活动列表', $list);
  56. }
  57. //活动详情
  58. public function activeinfo() {
  59. $id = input('id', 0, 'intval');
  60. if (!$id) {
  61. $this->error('参数缺失');
  62. }
  63. $info = Db::name('active')->find($id);
  64. if (!$info) {
  65. $this->error('数据不存在');
  66. }
  67. $info = info_domain_image($info, ['image']);
  68. $info['starttime'] = date('Y-m-d H:i', $info['starttime']);
  69. $info['endtime'] = date('Y-m-d H:i', $info['endtime']);
  70. $info['collectiontime'] = date('Y-m-d H:i', $info['collectiontime']);
  71. $info['signupendtime'] = date('Y-m-d H:i', $info['signupendtime']);
  72. $info['refundendtime'] = date('Y-m-d H:i', $info['refundendtime']);
  73. //查询已报名列表
  74. $active_people = Db::name('active_people')->where(['active_id' => $id, 'status' => ['neq', 3]])->field('user_id, name, createtime')->select();
  75. $user = Db::name('user');
  76. foreach ($active_people as &$v) {
  77. $user_info = $user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  78. $v['name'] = $user_info['nickname'];
  79. $v['avatar'] = $user_info['avatar'];
  80. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  81. }
  82. $info['active_people'] = $active_people;
  83. $info['customer_service'] = config('site.customer_service') ? config('site.customer_service') : ''; //客服电话
  84. $this->success('活动详情', $info);
  85. }
  86. //报名活动之前检查
  87. public function beforesignup() {
  88. $id = input('id', 0, 'intval'); //活动id
  89. if (!$id) {
  90. $this->error('请选择要报名的活动');
  91. }
  92. $info = Db::name('active')->find($id);
  93. if (!$info) {
  94. $this->error('活动不存在');
  95. }
  96. if ($info['status'] == 2) {
  97. $this->error('活动已经结束');
  98. }
  99. if ($info['status'] == 3) {
  100. $this->error('活动已经取消');
  101. }
  102. if ($info['showstatus'] != 1) {
  103. $this->error('活动暂时不能报名');
  104. }
  105. if ($info['signupendtime'] < time()) {
  106. $this->error('活动报名已经截止');
  107. }
  108. if ($info['currentperson'] >= $info['maxperson']) {
  109. $this->error('活动名额已满');
  110. }
  111. //检查自己信息是否完善
  112. if (!$this->auth->realname) {
  113. $this->success('请在个人资料中完善真实姓名', ['code' => 3]);
  114. }
  115. if (!$this->auth->idcard) {
  116. $this->success('请在个人资料中完善身份证号', ['code' => 3]);
  117. }
  118. if (!$this->auth->emergencycontact) {
  119. $this->success('请在个人资料中完善紧急联系人', ['code' => 3]);
  120. }
  121. if (!$this->auth->contactmobile) {
  122. $this->success('请在个人资料中完善紧急联系方式', ['code' => 3]);
  123. }
  124. $this->success('检查通过');
  125. }
  126. //查询可用优惠券
  127. public function canusercoupon() {
  128. $price = input('price', '', 'trim'); //价格
  129. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price < 0) {
  130. $this->error('价格错误');
  131. }
  132. $where['user_id'] = $this->auth->id;
  133. $where['endtime'] = ['egt', time()];
  134. $where['status'] = 0;
  135. $map = 'type = 1 or (type = 2 and minmoney <= '.$price.')';
  136. $list = Db::name('user_coupon')->field('id, title, desc, type, money, minmoney')->where($where)->where($map)->select();
  137. // p(\db()->getLastSql());
  138. $this->success('查询可用优惠券', $list);
  139. }
  140. //报名活动
  141. public function signupactive() {
  142. //检查自己信息是否完善
  143. if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) {
  144. $this->success('请在个人资料中完善资料', ['code' => 3]);
  145. }
  146. $id = input('id', 0, 'intval'); //活动id
  147. // $collectionplace = input('collectionplace', '', 'trim'); //集合地点
  148. //人员信息json串:
  149. // name姓名 credtype证件类型 idcard身份证号 mobile手机号 emergencycontact紧急联系人 contactmobile紧急联系方式
  150. // insurance保险 originalprice原价 vipprice会员价 coupon_id用户优惠券ID is_free是否使用免费次数:0=否,1=是
  151. // price小计 is_self是否本人:0=否,1=是 collectionplace集合地点
  152. $active_people = input('active_people', '', 'trim');
  153. $paytype = input('paytype', 0, 'intval'); //支付方式:0=余额,1=微信
  154. $total_price = input('total_price', 0, 'trim'); //总价格
  155. // if ($collectionplace === '' || iconv_strlen($collectionplace, 'utf-8') > 255) {
  156. // $this->error('请选择集合地点');
  157. // }
  158. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $total_price) || $total_price < 0) {
  159. $this->error('合计价格错误');
  160. }
  161. if (!in_array($paytype, [0, 1])) {
  162. $this->error('支付错误');
  163. }
  164. if ($total_price == 0 && $paytype != 0) {
  165. $this->error('请选择余额支付');
  166. }
  167. //检查活动信息
  168. if (!$id) {
  169. $this->error('请选择要报名的活动');
  170. }
  171. $info = Db::name('active')->find($id);
  172. if (!$info) {
  173. $this->error('活动不存在');
  174. }
  175. if ($info['status'] == 2) {
  176. $this->error('活动已经结束');
  177. }
  178. if ($info['status'] == 3) {
  179. $this->error('活动已经取消');
  180. }
  181. if ($info['showstatus'] != 1) {
  182. $this->error('活动暂时不能报名');
  183. }
  184. if ($info['signupendtime'] < time()) {
  185. $this->error('活动报名已经截止');
  186. }
  187. if ($info['currentperson'] >= $info['maxperson']) {
  188. $this->error('活动名额已满');
  189. }
  190. //检查人员信息
  191. if (!$active_people) {
  192. $this->error('请添加报名人员信息');
  193. }
  194. $active_people_arr = json_decode($active_people, true);
  195. if (!$active_people_arr) {
  196. $this->error('请添加报名人员信息');
  197. }
  198. if ($info['currentperson'] + count($active_people_arr) > $info['maxperson']) {
  199. $this->error('活动名额不足');
  200. }
  201. //会员信息
  202. $vip_info = Db::name('vip')->find($this->auth->maxlevel);
  203. if (!$vip_info) {
  204. $this->error('会员信息缺失,请联系管理员');
  205. }
  206. $_data = [];
  207. $total_amount = 0; //总价格验证
  208. $active_people = Db::name('active_people'); //报名人员表
  209. $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
  210. $user_coupon = Db::name('user_coupon');
  211. foreach ($active_people_arr as $k => &$v) {
  212. $data = [];
  213. //检查信息
  214. if (!$v['name'] || iconv_strlen($v['name'], 'utf-8') > 50) {
  215. $this->error('请输入正确姓名');
  216. break;
  217. }
  218. if (iconv_strlen($v['idcard'], 'utf-8') != 18) {
  219. $this->error('请输入正确身份证号');
  220. break;
  221. }
  222. if (!is_mobile($v['mobile'])) {
  223. $this->error('请输入正确手机号');
  224. break;
  225. }
  226. if (!$v['emergencycontact'] || iconv_strlen($v['emergencycontact'], 'utf-8') > 50) {
  227. $this->error('请输入紧急联系人');
  228. break;
  229. }
  230. if (!is_mobile($v['contactmobile'])) {
  231. $this->error('请输入正确紧急联系人方式');
  232. break;
  233. }
  234. //判断是否报名过
  235. $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => ['neq', 3]])->count('id');
  236. if ($count) {
  237. $this->error($v['name'] . $v['idcard'] . '已报名过该活动');
  238. break;
  239. }
  240. $count2 = $active_people_modify->where(['active_id' => $id, 'idcard' => $v['idcard'], 'status' => 0])->count('id');
  241. if ($count2) {
  242. $this->error($v['name'] . $v['idcard'] . '已提交过修改,请等待审核');
  243. break;
  244. }
  245. //判断证件类型和保险
  246. if (!$v['credtype'] || iconv_strlen($v['credtype'], 'utf-8') > 50) {
  247. $this->error('证件类型错误');
  248. break;
  249. }
  250. if (!$v['insurance'] || iconv_strlen($v['insurance'], 'utf-8') > 50) {
  251. $this->error('保险信息错误');
  252. break;
  253. }
  254. //判断集合地点
  255. if ($v['collectionplace'] === '' || iconv_strlen($v['collectionplace'] , 'utf-8') > 255) {
  256. $this->error($v['name'] . '请选择集合地点');
  257. break;
  258. }
  259. //判断用户信息
  260. if ($v['is_self'] && $k == 0) {
  261. //判断用户信息
  262. 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) {
  263. $this->error('本人信息错误');
  264. break;
  265. }
  266. //本人判断年龄 价格
  267. if ($info['maxage'] > 0) {
  268. $age = $this->idcardage($this->auth->idcard);
  269. if ($age < $info['minage'] || $age > $info['maxage']) {
  270. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  271. break;
  272. }
  273. }
  274. if ($v['is_free'] == 1) { //使用免费次数
  275. if ($info['is_free'] != 1) {
  276. $this->error('活动暂不支持免费体验');
  277. break;
  278. }
  279. if ($this->auth->freenumber <= 0) {
  280. $this->error('您的免费次数不足');
  281. break;
  282. }
  283. //检查当月是否用过免费次数
  284. $month_time = strtotime(date('Y-m-1', time()));
  285. $count = $active_people->where(['user_id' => $this->auth->id, 'is_free' => 1, 'createtime' => ['egt', $month_time]])->count('id');
  286. if ($count) {
  287. $this->error('您当月已使用过免费次数');
  288. break;
  289. }
  290. if ($v['vipprice'] != 0 || $v['price'] != 0) {
  291. $this->error($this->auth->realname . '价格错误');
  292. break;
  293. }
  294. if ($v['coupon_id']) {
  295. $this->error('使用免费体验,无法使用优惠券');
  296. break;
  297. }
  298. } else { //不使用免费次数
  299. //会员价和优惠券是否可以叠加使用:0=否,1=是
  300. if ($info['is_overlying'] == 0 && $v['vipprice'] != $info['price'] && $v['coupon_id']) {
  301. $this->error('该活动不支持会员价和优惠券同时使用');
  302. break;
  303. }
  304. //计算会员价, 会员价优先顺序: 生日 > 女生特权日 > 会员价格
  305. $birthday = date('md', strtotime($this->auth->birthday));
  306. $now_day = date('md', $info['starttime']); //活动当天生日
  307. if ($birthday == $now_day) {
  308. //生日折扣
  309. if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
  310. $this->error('会员生日折扣错误,请联系管理员');
  311. break;
  312. }
  313. $discount = $vip_info['birthdiscount'];
  314. } elseif ($info['girldiscount'] < 100 && $info['girldiscount'] > 0 && $this->auth->gender == 2) {
  315. //女生特权日折扣
  316. $discount = $info['girldiscount'];
  317. } else {
  318. //会员折扣
  319. if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
  320. $this->error('会员折扣错误,请联系管理员');
  321. break;
  322. }
  323. $discount = $vip_info['vipdiscount'];
  324. }
  325. $vipprice = number_format($info['price'] * $discount / 100, 2, '.', ''); //会员价
  326. //查询优惠券
  327. if ($v['coupon_id']) {
  328. $user_coupon_info = $user_coupon->where(['id' => $v['coupon_id'], 'user_id' => $this->auth->id])->find();
  329. if (!$user_coupon_info) {
  330. $this->error('优惠券不存在');
  331. }
  332. if ($user_coupon_info['status'] != 0) {
  333. $this->error('优惠券已使用');
  334. }
  335. if ($user_coupon_info['endtime'] < time()) {
  336. $this->error('优惠券已过期');
  337. }
  338. if ($user_coupon_info['type'] == 1) {
  339. //打折券
  340. if ($user_coupon_info['money'] < 0 || $user_coupon_info['money'] > 100) {
  341. $this->error('优惠券折扣错误,请联系管理员');
  342. break;
  343. }
  344. } else {
  345. //抵扣券
  346. //会员价和优惠券是否可以叠加使用:0=否,1=是
  347. if ($info['is_overlying'] == 0) {
  348. if ($info['price'] < $user_coupon_info['minmoney']) {
  349. $this->error('优惠券使用条件不满足');
  350. break;
  351. }
  352. } else {
  353. if ($vipprice < $user_coupon_info['minmoney']) {
  354. $this->error('优惠券使用条件不满足');
  355. break;
  356. }
  357. }
  358. }
  359. }
  360. //判断价格
  361. //会员价和优惠券是否可以叠加使用:0=否,1=是
  362. if ($info['is_overlying'] == 0) {
  363. if ($v['coupon_id']) { //使用优惠券
  364. if ($v['vipprice'] != $info['price']) {
  365. $this->error('会员价显示错误');
  366. break;
  367. }
  368. if ($user_coupon_info['type'] == 1) {
  369. //打折券
  370. $coupon_price = number_format($info['price'] * (100 - $user_coupon_info['money']) / 100, 2, '.', '');
  371. $price = number_format($info['price'] - $coupon_price, 2, '.', '');
  372. } else {
  373. //抵扣券
  374. $price = number_format($info['price'] - $user_coupon_info['money'], 2, '.', '');
  375. }
  376. } else {
  377. $price = $vipprice;
  378. }
  379. } else {
  380. if ($vipprice != $v['vipprice']) {
  381. $this->error('会员价显示错误');
  382. break;
  383. }
  384. if ($v['coupon_id']) { //使用优惠券
  385. if ($user_coupon_info['type'] == 1) {
  386. //打折券
  387. $coupon_price = number_format($vipprice * (100 - $user_coupon_info['money']) / 100, 2, '.', '');
  388. $price = number_format($vipprice - $coupon_price, 2, '.', '');
  389. } else {
  390. //抵扣券
  391. $price = number_format($vipprice - $user_coupon_info['money'], 2, '.', '');
  392. }
  393. } else {
  394. $price = $vipprice;
  395. }
  396. }
  397. //判断小计
  398. if ($price != $v['price']) {
  399. $this->error('小计显示错误');
  400. break;
  401. }
  402. $data['vipprice'] = $v['vipprice']; //会员价
  403. $data['coupon_id'] = $v['coupon_id']; //优惠券id
  404. if ($v['coupon_id']) {
  405. $data['coupontype'] = $user_coupon_info['type'];
  406. $data['couponprice'] = $user_coupon_info['money'];
  407. }
  408. }
  409. $data['name'] = $this->auth->realname;
  410. $data['idcard'] = $this->auth->idcard;
  411. $data['mobile'] = $this->auth->mobile;
  412. $data['emergencycontact'] = $this->auth->emergencycontact;
  413. $data['contactmobile'] = $this->auth->contactmobile;
  414. } else {
  415. //帮人报名判断年龄 报名信息
  416. if ($info['maxage'] > 0) {
  417. $age = $this->idcardage($v['idcard']);
  418. if ($age < $info['minage'] || $age > $info['maxage']) {
  419. $this->error('活动年龄限制为' . $info['minage'] . '-' . $info['maxage']);
  420. break;
  421. }
  422. }
  423. //判断是否符合满几人减免一人费用
  424. //会员权限
  425. if ($vip_info['manypeople'] > 1 && $k == $vip_info['manypeople'] - 1) {
  426. if ($v['price'] != 0) {
  427. $this->error('小计显示错误');
  428. break;
  429. }
  430. } else {
  431. if ($v['price'] != $info['price']) {
  432. $this->error('小计显示错误');
  433. break;
  434. }
  435. }
  436. $data['name'] = $v['name'];
  437. $data['idcard'] = $v['idcard'];
  438. $data['mobile'] = $v['mobile'];
  439. $data['emergencycontact'] = $v['emergencycontact'];
  440. $data['contactmobile'] = $v['contactmobile'];
  441. $data['vipprice'] = $v['price']; //会员价
  442. }
  443. $data['active_id'] = $id;
  444. $data['user_id'] = $this->auth->id;
  445. $data['collectionplace'] = $v['collectionplace'];
  446. $data['credtype'] = $v['credtype'];
  447. $data['insurance'] = $v['insurance'];
  448. $data['originalprice'] = $info['price'];
  449. $data['is_free'] = $v['is_free'];
  450. $data['price'] = $v['price']; //小计
  451. $data['is_self'] = $v['is_self'];
  452. $data['createtime'] = time();
  453. array_push($_data, $data);
  454. $total_amount += $v['price'];
  455. }
  456. if ($total_amount != $total_price) {
  457. $this->error('合计价格错误');
  458. }
  459. if ($paytype == 0) { //余额支付
  460. if ($this->auth->money < $total_amount) {
  461. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  462. }
  463. }
  464. //构建订单信息
  465. $order_data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  466. $order_data['active_id'] = $id;
  467. $order_data['user_id'] = $this->auth->id;
  468. // $order_data['collectionplace'] = $collectionplace;
  469. $order_data['paytype'] = $paytype;
  470. $order_data['price'] = $total_amount;
  471. $order_data['number'] = count($active_people_arr);
  472. $order_data['status'] = $paytype == 1 ? 0 : 1;
  473. $order_data['createtime'] = time();
  474. //构建活动信息
  475. $active_data['currentperson'] = $info['currentperson'] + count($active_people_arr);
  476. if ($info['currentperson'] + count($active_people_arr) >= $info['minperson'] && $info['status'] == 0) {
  477. $active_data['status'] = 1;
  478. }
  479. //开始事务
  480. Db::startTrans();
  481. //修改活动表数据
  482. $active_rs = Db::name('active')->where(['id' => $id, 'status' => $info['status'],'currentperson' => $info['currentperson']])->setField($active_data);
  483. if (!$active_rs) {
  484. Db::rollback();
  485. $this->error('网络延迟,请稍后再试');
  486. }
  487. //添加订单
  488. $rs = Db::name('active_order')->insertGetId($order_data);
  489. if (!$rs) {
  490. Db::rollback();
  491. $this->error('网络延迟,请稍后再试');
  492. }
  493. //添加人员信息
  494. foreach ($_data as &$v) {
  495. $v['order_id'] = $rs;
  496. $v['status'] = $order_data['status'];
  497. $rt = $active_people->insertGetId($v);
  498. if (!$rt) {
  499. Db::rollback();
  500. $this->error('网络延迟,请稍后再试');
  501. }
  502. }
  503. //扣除免费次数
  504. if ($info['is_free'] == 1 && $active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['is_free'] == 1) {
  505. $freenumber = $this->auth->freenumber - 1;
  506. $user_rs = Db::name('user')->where(['id' => $this->auth->id, 'freenumber' => $this->auth->freenumber])->setField('freenumber', $freenumber);
  507. if (!$user_rs) {
  508. Db::rollback();
  509. $this->error('网络延迟,请稍后再试');
  510. }
  511. }
  512. //扣除优惠券
  513. if ($active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['coupon_id']) {
  514. $user_coupon_rs = Db::name('user_coupon')->where(['id' => $active_people_arr[0]['coupon_id'], 'user_id' => $this->auth->id, 'status' => 0])->setField(['active_id' => $id, 'order_id' => $rs, 'status' => 1]);
  515. if (!$user_coupon_rs) {
  516. Db::rollback();
  517. $this->error('网络延迟,请稍后再试');
  518. }
  519. }
  520. //扣款 支付方式:0=余额,1=微信
  521. if ($paytype == 0) {
  522. $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2, $rs);
  523. if ($res != 1) {
  524. Db::rollback();
  525. $this->error('余额资金异常,请联系管理员');
  526. }
  527. //给上级发送优惠券
  528. if ($this->auth->pre_user_id) {
  529. //查询报名活动优惠券
  530. $invite_coupon = Db::name('coupon')->where(['purpose' => 5, 'status' => 1])->order('weigh desc, id desc')->find();
  531. if ($invite_coupon) {
  532. $invite_coupon_data = [
  533. 'user_id' => $this->auth->pre_user_id,
  534. 'coupon_id' => $invite_coupon['id'],
  535. 'title' => $invite_coupon['title'],
  536. 'desc' => $invite_coupon['desc'],
  537. 'type' => $invite_coupon['type'],
  538. 'money' => $invite_coupon['money'],
  539. 'minmoney' => $invite_coupon['minmoney'],
  540. 'purpose' => $invite_coupon['purpose'],
  541. 'starttime' => time(),
  542. 'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
  543. 'active_id' => $id,
  544. 'order_id' => $rs,
  545. 'createtime' => time()
  546. ];
  547. $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
  548. if (!$invite_coupon_rs) {
  549. Db::rollback();
  550. $this->error('发放优惠券失败');
  551. }
  552. }
  553. }
  554. //发送消息
  555. $data = [
  556. 'user_id' => $this->auth->id,
  557. 'type' => 1,
  558. 'title' => '活动通知',
  559. 'content' => '您已成功报名' . $info['title'] . '活动',
  560. 'createtime' => time()
  561. ];
  562. $sys_rs = Db::name('sys_msg')->insertGetId($data);
  563. if (!$sys_rs) {
  564. Db::rollback();
  565. $this->error('网络延迟,请稍后再试');
  566. }
  567. Db::commit();
  568. $this->success('报名成功');
  569. } else {
  570. //生成支付订单记录
  571. $rechar_order['user_id'] = $this->auth->id;
  572. $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999); //微信订单编号
  573. $rechar_order['money'] = $total_amount;
  574. $rechar_order['purpose'] = 1; //充值用途:1=支付订单,2=充值,3=开通会员
  575. $rechar_order['pay_type'] = 'wechat';
  576. $rechar_order['relation_id'] = $rs;
  577. $rechar_order['createtime'] = time();
  578. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  579. if (!$result) {
  580. Db::rollback();
  581. $this->error('网络延迟,请稍后再试');
  582. }
  583. Db::commit();
  584. //构建支付链接数据
  585. $wxData['body'] = '报名活动支付';
  586. $wxData['out_trade_no'] = $rechar_order['order_no'];
  587. $wxData['total_fee'] = $total_amount;
  588. // $wxData['total_fee'] = 0.01;
  589. $wxData['openid'] = $this->auth->openid;
  590. // require_once($_SERVER['DOCUMENT_ROOT'] . '/Plugins/Weixin/WxPay/WxPay.php');
  591. $wxPay = new wxpay\WxPay(config('wxchatpay'));
  592. $doResult = $wxPay->WxPayJs($wxData);
  593. $this->success('微信支付参数返回成功', $doResult);
  594. }
  595. }
  596. //根据身份证号获取年龄
  597. public function idcardage($idcard = '') {
  598. //截取身份证里的出生日期
  599. $year = substr($idcard, 6, 4);
  600. $month = substr($idcard, 10, 2);
  601. $day = substr($idcard, 12, 2);
  602. //获取当前日期
  603. $current_year = date('Y');
  604. $current_month = date('m');
  605. $current_day = date('d');
  606. //计算年龄
  607. $age = $current_year - $year;//今年减去生日年
  608. if ($month > $current_month || ($month == $current_month && $day > $current_day)) {
  609. //如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  610. $age--;
  611. }
  612. return $age;
  613. }
  614. //私人订制类型
  615. public function personaltype() {
  616. $list = Db::name('personal_type')->field('id, name')->order('weigh', 'desc')->select();
  617. $this->success('私人订制类型', $list);
  618. }
  619. //私人订制活动类型
  620. public function personalactivetype() {
  621. $list = Db::name('personal_active_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
  622. $list = $this->getchildtype($list);
  623. $this->success('私人订制活动类型', $list);
  624. }
  625. //无限级私人订制活动类型
  626. public function getchildtype($list = [])
  627. {
  628. $complaint_type = Db::name('personal_active_type');
  629. foreach ($list as &$v) {
  630. $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
  631. if ($child) {
  632. $child = $this->getchildtype($child);
  633. }
  634. $v['child'] = $child;
  635. }
  636. return $list;
  637. }
  638. //车辆类型
  639. public function car() {
  640. $list = Db::name('car')->field('id, name, desc')->order('weigh', 'desc')->select();
  641. $this->success('车辆类型', $list);
  642. }
  643. //领队
  644. public function leader() {
  645. $list = Db::name('leader')->field('id, name')->order('weigh', 'desc')->select();
  646. $this->success('领队', $list);
  647. }
  648. //私人订制出行方向
  649. public function personaldirection() {
  650. $list = Db::name('personal_direction')->field('id, name')->order('weigh', 'desc')->select();
  651. $this->success('私人订制出行方向', $list);
  652. }
  653. //私人订制
  654. public function personalactive() {
  655. $type = input('type', '', 'trim'); //类型
  656. $number = input('number', 0, 'intval'); //出行人数
  657. $traveltime = input('traveltime', '', 'strtotime'); //出行时间
  658. $traveday = input('traveday', 0, 'intval'); //出行天数
  659. $activetype = input('activetype', '', 'trim'); //活动类型
  660. $car = input('car', '', 'trim'); //车辆
  661. $leader = input('leader', '', 'trim'); //领队
  662. $travedirection = input('travedirection', '', 'trim'); //出行方向
  663. $freerange = input('freerange', '', 'trim'); //空闲时段
  664. $remark = input('remark', '', 'trim'); //留言
  665. if (!$type || iconv_strlen($type, 'utf-8') > 50) {
  666. $this->error('请选择类型');
  667. }
  668. if ($number <= 0) {
  669. $this->error('请填写出行人数');
  670. }
  671. if ($traveltime < time()) {
  672. $this->error('请选择正确出行时间');
  673. }
  674. if ($traveday <= 0) {
  675. $this->error('请填写正确出行天数');
  676. }
  677. if (!$activetype || iconv_strlen($activetype, 'utf-8') > 50) {
  678. $this->error('请选择活动类型');
  679. }
  680. if ($car && iconv_strlen($car, 'utf-8') > 50) {
  681. $this->error('请选择车辆');
  682. }
  683. if ($leader && iconv_strlen($leader, 'utf-8') > 50) {
  684. $this->error('请选择领队');
  685. }
  686. if (!$travedirection || iconv_strlen($travedirection, 'utf-8') > 50) {
  687. $this->error('请选择出行方向');
  688. }
  689. if (!$freerange || iconv_strlen($freerange, 'utf-8') > 50) {
  690. $this->error('请选择空闲时段');
  691. }
  692. if (iconv_strlen($remark, 'utf-8') > 500) {
  693. $this->error('留言最多500字');
  694. }
  695. $data['user_id'] = $this->auth->id;
  696. $data['type'] = $type;
  697. $data['number'] = $number;
  698. $data['traveltime'] = $traveltime;
  699. $data['traveday'] = $traveday;
  700. $data['activetype'] = $activetype;
  701. $data['car'] = $car;
  702. $data['leader'] = $leader;
  703. $data['travedirection'] = $travedirection;
  704. $data['freerange'] = $freerange;
  705. $data['remark'] = $remark;
  706. $data['createtime'] = time();
  707. $rs = Db::name('personal_order')->insertGetId($data);
  708. if (!$rs) {
  709. $this->error('提交失败');
  710. }
  711. $this->success('提交成功');
  712. }
  713. //查询轮播图优惠券列表
  714. public function bannercoupon() {
  715. $list = Db::name('coupon')->field('id, title, desc, type, money')
  716. ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
  717. $user_coupon = Db::name('user_coupon');
  718. foreach ($list as &$v) {
  719. $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
  720. }
  721. $this->success('查询轮播图优惠券列表', $list);
  722. }
  723. //领取轮播图优惠券
  724. public function receivebannercoupon() {
  725. $id = input('id', 0, 'intval'); //优惠券id
  726. if (!$id) {
  727. $this->error('参数缺失');
  728. }
  729. $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
  730. if (!$info) {
  731. $this->error('优惠券不存在');
  732. }
  733. if ($info['status'] != 1) {
  734. $this->error('优惠券已下架');
  735. }
  736. //查询是否已领取
  737. $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  738. if ($count) {
  739. $this->error('您已经领取过了');
  740. }
  741. $data['user_id'] = $this->auth->id;
  742. $data['coupon_id'] = $id;
  743. $data['title'] = $info['title'];
  744. $data['desc'] = $info['desc'];
  745. $data['type'] = $info['type'];
  746. $data['money'] = $info['money'];
  747. $data['minmoney'] = $info['minmoney'];
  748. $data['purpose'] = $info['purpose'];
  749. $data['starttime'] = time();
  750. $data['endtime'] = time() + $info['effectiveday'] * 86400;
  751. $data['createtime'] = time();
  752. //开启事务
  753. Db::startTrans();
  754. //添加领取记录
  755. $rs = Db::name('user_coupon')->insertGetId($data);
  756. if (!$rs) {
  757. Db::rollback();
  758. $this->error('领取失败');
  759. }
  760. $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
  761. if ($rt != 1) {
  762. Db::rollback();
  763. $this->error('领取失败');
  764. }
  765. Db::commit();
  766. $this->success('领取成功');
  767. }
  768. //体验会员列表
  769. public function experiencevip() {
  770. $where = [];
  771. if ($this->auth->maxlevel != 5) {
  772. $where['id'] = ['neq', 5];
  773. }
  774. $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->where($where)->select();
  775. $vip_privilege = Db::name('vip_privilege');
  776. foreach ($list as &$v) {
  777. $v['vip_privilege'] = $vip_privilege->field('id, title, desc')
  778. ->where(['vip_id' => $v['id']])->order('weigh desc')->select();
  779. }
  780. $this->success('体验会员列表', $list);
  781. }
  782. //购买体验会员
  783. public function buyexperiencevip() {
  784. //检查是否已经开通体验会员
  785. if ($this->auth->experiencetime >= time()) {
  786. $this->error('您已开通体验会员,不能重复开通');
  787. }
  788. $id = input('id', 0, 'intval');
  789. if (!$id) {
  790. $this->error('参数缺失');
  791. }
  792. $info = Db::name('vip')->where(['id' => $id])->find();
  793. if (!$info) {
  794. $this->error('会员不存在');
  795. }
  796. if ($info['status'] != 1) {
  797. $this->error('体验会员已下架');
  798. }
  799. if ($info['price'] <= 0) {
  800. $this->error('会员价格异常');
  801. }
  802. //体验会员等级必须大于成长值会员
  803. if ($id <= $this->auth->maxlevel) {
  804. $this->error('请开通更高等级体验会员');
  805. }
  806. //判断余额
  807. if ($this->auth->money < $info['price']) {
  808. $this->success('您的余额不足,请先去充值', ['code' => 2]);
  809. }
  810. $data['user_id'] = $this->auth->id;
  811. $data['vip_id'] = $id;
  812. $data['title'] = $info['title'];
  813. $data['level'] = $info['level'];
  814. $data['growthvalue'] = $info['growthvalue'];
  815. $data['free'] = $info['free'];
  816. $data['price'] = $info['price'];
  817. $data['endtime'] = time() + $info['day'] * 86400;
  818. $data['vipdiscount'] = $info['vipdiscount'];
  819. $data['birthdiscount'] = $info['birthdiscount'];
  820. $data['manypeople'] = $info['manypeople'];
  821. $data['createtime'] = time();
  822. //开启事务
  823. Db::startTrans();
  824. //添加开通记录
  825. $rs = Db::name('vip_log')->insertGetId($data);
  826. if (!$rs) {
  827. Db::rollback();
  828. $this->error('开通失败');
  829. }
  830. //扣除余额
  831. $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4, $rs);
  832. if ($result != 1) {
  833. Db::rollback();
  834. $this->error('资金异常,请联系管理员');
  835. }
  836. //成长值会员信息
  837. $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
  838. //修改用户表信息
  839. $user_data['experiencelevel'] = $id;
  840. $user_data['experiencetime'] = $data['endtime'];
  841. $user_data['maxlevel'] = $id;
  842. $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
  843. $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
  844. $rt = Db::name('user')->where([
  845. 'id' => $this->auth->id,
  846. 'experiencelevel' => $this->auth->experiencelevel,
  847. 'maxlevel' => $this->auth->maxlevel,
  848. 'freenumber' => $this->auth->freenumber])->setField($user_data);
  849. if (!$rt) {
  850. Db::rollback();
  851. $this->error('开通失败');
  852. }
  853. Db::commit();
  854. $this->success('开通成功');
  855. }
  856. //获取活动分享链接
  857. public function activelink() {
  858. $id = input('id', 0, 'intval'); //活动id
  859. if (!$id) {
  860. $this->error('参数缺失');
  861. }
  862. $info = Db::name('active')->find($id);
  863. if (!$info) {
  864. $this->error('活动不存在');
  865. }
  866. if ($info['status'] == 2) {
  867. $this->error('活动已结束');
  868. }
  869. if ($info['status'] == 3) {
  870. $this->error('活动已取消');
  871. }
  872. if ($info['showstatus'] != 1) {
  873. $this->error('活动暂时不能报名');
  874. }
  875. $access_token = Cache::get('access_token');
  876. if (!$access_token) {
  877. //获取$access_token
  878. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxchatpay.app_id').'&secret='.config('wxchatpay.app_secret');
  879. $result = file_get_contents($url);
  880. $result = json_decode($result, true);
  881. $access_token = $result['access_token'];
  882. //缓存
  883. Cache::set('access_token', $access_token, 7000);
  884. }
  885. if (!$access_token) {
  886. $this->error('参数缺失');
  887. }
  888. $data['page_url'] = 'pages/home/detail?id='.$id.'&code='.$this->auth->invite_no;
  889. $data['page_title'] = $info['title'];
  890. $data = json_encode($data, 320);
  891. $url = 'https://api.weixin.qq.com/wxa/genwxashortlink?access_token='.$access_token;
  892. $rs = httpRequest($url, 'POST', $data);
  893. $rs = json_decode($rs, true);
  894. if ($rs['errcode'] != 0) {
  895. $this->error('网络延迟');
  896. }
  897. $this->success('分享链接', $rs['link']);
  898. }
  899. //生成小程序邀请二维码
  900. public function getqrcode($id = 0) {
  901. $access_token = Cache::get('access_token');
  902. // $access_token = '';
  903. if (!$access_token) {
  904. //获取$access_token
  905. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxchatpay.app_id').'&secret='.config('wxchatpay.app_secret');
  906. // $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx326ed0bf442d2773&secret=33609a3bc45bb407f0b26816158405b8';
  907. $result = file_get_contents($url);
  908. $result = json_decode($result, true);
  909. $access_token = $result['access_token'];
  910. //缓存
  911. Cache::set('access_token', $access_token, 7000);
  912. }
  913. if (!$access_token) {
  914. $this->error('参数缺失');
  915. }
  916. $data['scene'] = 'id='.$id.'&code='.$this->auth->invite_no;
  917. // $data['scene'] = 'id=AVwvR&code='.$this->auth->invite_no;
  918. $data['page'] = 'pages/home/detail';
  919. // $data['page'] = 'pages/product/product';
  920. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  921. $ch = curl_init($url);
  922. $timeout = 6000;
  923. curl_setopt($ch, CURLOPT_POST, 1);
  924. curl_setopt($ch, CURLOPT_HEADER, 0);
  925. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  926. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  927. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  928. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  929. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
  930. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  931. $ret = curl_exec($ch);
  932. curl_close($ch);
  933. if (is_array($ret)) {
  934. return '';
  935. }
  936. if (json_decode($ret)) {
  937. $this->error('生成失败');
  938. }
  939. $secretId = "AKIDhDTSBdoTs0rS4bx3rQijSu61f3B2cv3y"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  940. $secretKey = "f3A1btufAOL2SbT4ORDiwtZy7yYooY1D"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  941. $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
  942. $cosClient = new Client(
  943. array(
  944. 'region' => $region,
  945. 'schema' => 'https', //协议头部,默认为http
  946. 'credentials'=> array(
  947. 'secretId' => $secretId ,
  948. 'secretKey' => $secretKey)));
  949. // $local_path = "/Users/xxx/Desktop/exampleobject.txt"; //保存到用户本地路径
  950. $path = "qrcode/"; // 二维码文件流存放位置
  951. $fileName = time() . rand(10000,99999) . ".png";
  952. $result = $cosClient->putObject(array(
  953. 'Bucket' => 'fireflytra-1309974405', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  954. 'Key' => $path . $fileName,//'exampleobject',
  955. 'Body' => $ret,//fopen($local_path, 'rb'),
  956. ));
  957. // 请求成功
  958. return 'https://' . $result['Location'];
  959. // //上传到阿里云oss
  960. // require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/autoload.php';
  961. // require_once './Plugins/Aliyun/aliyun-oss-php-sdk-2.3.0/src/OSS/OssClient.php';
  962. // $config = C('ALIOSS_CONFIG');
  963. //
  964. // $oss = new \OSS\OssClient($config['KEY_ID'], $config['KEY_SECRET'], $config['END_POINT']);
  965. //
  966. // $path = "shopqrcode/"; // 二维码文件流存放位置
  967. // $fileName = time() . rand(10000,99999) . ".png";
  968. //
  969. // // 上传到oss
  970. // $result = $oss->putObject($config['BUCKET'], $path . $fileName, $ret);
  971. //
  972. // // 获取图片url地址
  973. // $oss_url = json_decode(json_encode($result), true);
  974. //
  975. // return $oss_url['oss-request-url'];
  976. }
  977. //生成活动海报
  978. public function activeposter() {
  979. // $poster = Db::name('poster')->find(1);
  980. // p($poster);die;
  981. $id = input('id', 0, 'intval'); //活动id
  982. if (!$id) {
  983. $this->error('参数缺失');
  984. }
  985. $info = Db::name('active')->find($id);
  986. if (!$info) {
  987. $this->error('活动不存在');
  988. }
  989. if ($info['status'] == 2) {
  990. $this->error('活动已结束');
  991. }
  992. if ($info['status'] == 3) {
  993. $this->error('活动已取消');
  994. }
  995. if ($info['showstatus'] != 1) {
  996. $this->error('活动暂时不能报名');
  997. }
  998. $data = [
  999. [
  1000. "left" => "4px",
  1001. "top" => "4px",
  1002. "type" => "img",
  1003. "width" => "310px",
  1004. "height" => "235px",
  1005. "src" => one_domain_image($info['image']) //主图
  1006. ],
  1007. [
  1008. "left" => "100px",
  1009. "top" => "347px",
  1010. "type" => "img",
  1011. "width" => "115px",
  1012. "height" => "115px",
  1013. "src" => $this->getqrcode($id) //小程序二维码'https://fireflytra-1309974405.cos.ap-beijing.myqcloud.com/qrcode/165405491386733.png'
  1014. ]
  1015. ];
  1016. //处理标题字符
  1017. $child = [
  1018. "left" => "11px",
  1019. "top" => "253px",
  1020. "type" => "nickname",
  1021. "width" => "296px",
  1022. "height" => "50px",
  1023. "size" => "16px",
  1024. "color" => "#000",
  1025. "content" => mb_substr($info['title'], 0, 14)
  1026. ];
  1027. array_push($data, $child);
  1028. if (iconv_strlen($info['title'], 'utf-8') > 14) {
  1029. $child = [
  1030. "left" => "11px",
  1031. "top" => "285px",
  1032. "type" => "nickname",
  1033. "width" => "296px",
  1034. "height" => "50px",
  1035. "size" => "16px",
  1036. "color" => "#000",
  1037. "content" => mb_substr($info['title'], 14, 14)
  1038. ];
  1039. if (iconv_strlen($info['title'], 'utf-8') <= 28) {
  1040. $child['content'] = mb_substr($info['title'], 14, 14);
  1041. } else {
  1042. $child['content'] = mb_substr($info['title'], 14, 11) . '...';
  1043. }
  1044. array_push($data, $child);
  1045. }
  1046. //添加价格
  1047. $child = [
  1048. "left" => "11px",
  1049. "top" => "318px",
  1050. "type" => "nickname",
  1051. "width" => "296px",
  1052. "height" => "50px",
  1053. "size" => "16px",
  1054. "color" => "#FF0000",
  1055. "content" => $info['price'] . '元'
  1056. ];
  1057. array_push($data, $child);
  1058. $data = json_encode($data, 320);
  1059. $poster = [
  1060. 'id' => 1,
  1061. 'title' => '测试',
  1062. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  1063. 'bg_image' => '/assets/img/bg.png',
  1064. 'data' => $data,
  1065. 'status' => 'normal',
  1066. 'weigh' => 0,
  1067. 'createtime' => 1653993709,
  1068. 'updatetime' => 1653994259,
  1069. ];
  1070. $image = new \addons\poster\library\Image();
  1071. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  1072. if (!$imgurl) {
  1073. $this->error('生成海报出错');
  1074. }
  1075. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  1076. $this->success('', $imgurl);
  1077. }
  1078. //查询帮报名过的人员信息
  1079. public function getpeopleinfo() {
  1080. $name = input('name', '', 'trim'); //名称
  1081. if (!$name) {
  1082. $this->success('信息', (object)[]);
  1083. }
  1084. $info = Db::name('active_people')->field('name, idcard, mobile, emergencycontact, contactmobile')->where(['user_id' => $this->auth->id, 'name' => $name])->find();
  1085. if (!$info) {
  1086. $info = (object)[];
  1087. }
  1088. $this->success('信息', $info);
  1089. }
  1090. //视频分类列表
  1091. public function videotype() {
  1092. $type = input('type', 0, 'intval'); //分类类型:0=老年大学,1=普法课堂
  1093. if (!in_array($type, [0, 1])) {
  1094. $this->error('参数错误');
  1095. }
  1096. $list = Db::name('video_type')->field('id, name, image')->where(['type' => $type])
  1097. ->page($this->page, $this->pagenum)->order('weigh, id')->select();
  1098. $list = list_domain_image($list, ['image']);
  1099. $this->success('分类', $list);
  1100. }
  1101. //视频列表
  1102. public function video() {
  1103. $type_id = input('type_id', 0, 'intval'); //分类id
  1104. if (!$type_id) {
  1105. $this->error('您的网络开小差了~');
  1106. }
  1107. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])->page($this->page, $this->pagenum)->order('weigh, id desc')->select();
  1108. $list = list_domain_image($list, ['image']);
  1109. $this->success('视频', $list);
  1110. }
  1111. //视频详情
  1112. public function videoinfo() {
  1113. $id = input('id', 0, 'intval'); //视频id
  1114. if (!$id) {
  1115. $this->error('您的网络开小差了');
  1116. }
  1117. $info = Db::name('video')->field('id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  1118. ->where(['id' => $id])->find();
  1119. if (!$info) {
  1120. $this->error('数据不存在');
  1121. }
  1122. if ($info['status'] != 1) {
  1123. $this->error('视频丢失');
  1124. }
  1125. if ($info['inject_status'] != 2) {
  1126. $this->error('视频丢失');
  1127. }
  1128. $info['image'] = one_domain_image($info['image']);
  1129. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  1130. $this->success('详情', $info);
  1131. }
  1132. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  1133. public function encrypt($string, $key) {
  1134. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  1135. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  1136. $data = bin2hex($data);
  1137. return $data;
  1138. }
  1139. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  1140. public function decrypt($string, $key) {
  1141. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  1142. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  1143. return $decrypted;
  1144. }
  1145. //视频播放记录
  1146. public function playrecord() {
  1147. $id = input('id', 0, 'intval');
  1148. $total_time = input('total_time', 0, 'intval'); //总时长
  1149. $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
  1150. $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
  1151. $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
  1152. if (!$id) {
  1153. $this->error('您的网络开小差了');
  1154. }
  1155. $info = Db::name('video')->where(['id' => $id])->find();
  1156. if (!$info) {
  1157. $this->error('数据不存在');
  1158. }
  1159. if ($info['inject_status'] != 2) {
  1160. $this->error('视频丢失');
  1161. }
  1162. $info['image'] = one_domain_image($info['image']);
  1163. $url = 'http://jscp.agency.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
  1164. $content = [
  1165. 'cpPrvdName' => '健康e家',
  1166. 'cpPrvCode' => '41000144',
  1167. 'cpPrvType' => '1006',
  1168. 'contentName' => $info['title'],
  1169. 'ChnName' => '健康',
  1170. 'ChnCode' => '1000020',
  1171. 'contentId' => (string)$info['id'],
  1172. 'extraContentID' => '',
  1173. 'isEffective' => $info['status'],
  1174. 'isPaid' => $info['is_pay'],
  1175. 'contentTotalTime' => $total_time,
  1176. 'startWatchTime' => $start_time,
  1177. 'endWatchTime' => $end_time,
  1178. 'playTime' => $end_time - $start_time,
  1179. 'logType' => $log_type,
  1180. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  1181. 'cpPermission' => 'GITV',
  1182. 'intent' => [
  1183. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  1184. 'package' => 'com.huxiu.heh.tv',
  1185. 'component' => [
  1186. 'pkg' => 'com.huxiu.heh.tv',
  1187. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  1188. ],
  1189. 'extras' => [
  1190. /*'cmd' => '',
  1191. 'from' => '',
  1192. 'media_id' => ''*/
  1193. 'type_id' => $info['video_type_id'],
  1194. 'id' => $info['id']
  1195. ]
  1196. ],
  1197. 'imageURL' => $info['image']
  1198. ];
  1199. $content = json_encode($content, 320);
  1200. $rt = httpRequest($url, 'POST', $content);
  1201. if (!$rt) {
  1202. $this->error('同步失败');
  1203. }
  1204. $rt = json_decode($rt, true);
  1205. if ($rt['code'] != 0) {
  1206. $this->error('同步失败');
  1207. }
  1208. $this->success('同步成功');
  1209. }
  1210. //视频收藏/取消收藏
  1211. public function collectionrecord() {
  1212. $id = input('id', 0, 'intval');
  1213. if (!$id) {
  1214. $this->error('您的网络开小差了');
  1215. }
  1216. $info = Db::name('video')->where(['id' => $id])->find();
  1217. if (!$info) {
  1218. $this->error('数据不存在');
  1219. }
  1220. $info['image'] = one_domain_image($info['image']);
  1221. //查询是否收藏
  1222. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  1223. //开启事务
  1224. if ($count) {
  1225. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  1226. } else {
  1227. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  1228. }
  1229. if (!$result) {
  1230. Db::rollback();
  1231. $this->error('操作失败');
  1232. }
  1233. $url = 'http://jscp.agency.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  1234. $content = [
  1235. 'cpPrvdName' => '健康e家',
  1236. 'cpPrvCode' => '41000144',
  1237. 'cpPrvType' => '1006',
  1238. 'content' => $info['title'],
  1239. 'ChnCode' => '1000020',
  1240. 'contentId' => (string)$info['id'],
  1241. 'extraContentID' => '',
  1242. 'isEffective' => $info['status'],
  1243. 'isPaid' => $info['is_pay'],
  1244. 'collectionFlag' => $count ? 0 : 1,
  1245. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  1246. 'cpPermission' => 'GITV',
  1247. 'intent' => [
  1248. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  1249. 'package' => 'com.huxiu.heh.tv',
  1250. 'component' => [
  1251. 'pkg' => 'com.huxiu.heh.tv',
  1252. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  1253. ],
  1254. 'extras' => [
  1255. /*'cmd' => '',
  1256. 'from' => '',
  1257. 'media_id' => ''*/
  1258. 'type_id' => $info['video_type_id'],
  1259. 'id' => $info['id']
  1260. ]
  1261. ],
  1262. 'imageURL' => $info['image']
  1263. ];
  1264. $content = json_encode($content, 320);
  1265. $rt = httpRequest($url, 'POST', $content);
  1266. if (!$rt) {
  1267. Db::rollback();
  1268. $this->error('操作失败');
  1269. }
  1270. $rt = json_decode($rt, true);
  1271. if ($rt['code'] != 0) {
  1272. Db::rollback();
  1273. $this->error('操作失败');
  1274. }
  1275. //大数据上报
  1276. $data = [
  1277. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  1278. 'UserID' => $this->auth->mobile,
  1279. 'time' => date('Y-m-d H:i:s'),
  1280. 'type' => $count ? 0 : 1,
  1281. 'cpid' => config('data_cp_id'),
  1282. 'albumid' => $id,
  1283. 'albumname' => $info['title']
  1284. ];
  1285. $data = join(json_decode('"\u0001"', true), $data);
  1286. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  1287. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  1288. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1289. error_log('', 3, './dashuju/' . $check_filename);
  1290. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  1291. error_log('', 3, './dashuju/' . $finish_filename);
  1292. Db::commit();
  1293. $this->success('操作成功');
  1294. }
  1295. //用户观看行为(大数据)
  1296. public function userplay() {
  1297. $id = input('id', 0, 'intval'); //视频id
  1298. $sn = input('sn', '', 'trim'); //SN号
  1299. $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
  1300. $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
  1301. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
  1302. $trace_id = input('trace_id', '', 'trim');
  1303. $istry = input('istry', 0, 'intval'); //0非试看 1试看
  1304. $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
  1305. if (!$id) {
  1306. $this->error('您的网络开小差了');
  1307. }
  1308. $info = Db::name('video')->where(['id' => $id])->find();
  1309. if (!$info) {
  1310. $this->error('数据不存在');
  1311. }
  1312. $content = [
  1313. 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  1314. 'UserID' => $this->auth->mobile,
  1315. 'SN' => $sn,
  1316. 'start_time' => $start_time,
  1317. 'end_time' => $end_time,
  1318. 'service_type' => 1,
  1319. 'cpid' => config('data_cp_id'),
  1320. 'albumid' => $id,
  1321. 'albumname' => $info['title'],
  1322. 'videoid' => $id,
  1323. 'videoname' => $info['title'],
  1324. 'csource' => $csource,
  1325. 'trace_id' => $trace_id,
  1326. 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
  1327. 'istry' => $istry,
  1328. 'iscon' => 0,
  1329. 'start_posi' => $start_posi
  1330. ];
  1331. $content = join(json_decode('"\u0001"', true), $content);
  1332. $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
  1333. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
  1334. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1335. error_log('', 3, './dashuju/' . $check_filename);
  1336. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
  1337. error_log('', 3, './dashuju/' . $finish_filename);
  1338. $this->success('');
  1339. }
  1340. //用户行为feedback
  1341. public function userfeedback() {
  1342. $type = input('type', '', 'trim'); //曝光display/播放play/点击click/订购order/搜索 search/收藏 fav
  1343. $itemid = input('itemid', '', 'trim'); //视频id,研究院推荐内容上报
  1344. $otherid = input('otherid', '', 'trim'); //视频id,非研究院推荐内容上报
  1345. $prodid = input('prodid', '', 'trim'); //订购行为必填;其余行为可选
  1346. $trace_id = input('trace_id', '', 'trim'); //大数据推荐内容有trace_id
  1347. $signal = input('signal', '', 'trim'); //所属板块编号,0异形、1头部、3电影,后续查看服务接口标识;非推荐内容所有行为为空;推荐内容所有行为必填
  1348. $pos = input('pos', '', 'trim'); //所在位置编号,从左至右第1、2…个推荐位; 非推荐内容所有行为为空;推荐内容所有行为必填
  1349. $play_duration = input('play_duration', 0, 'trim'); //单位毫秒,在播放结束时反馈该值
  1350. $url = 'http://jscp.agency.gitv.tv/v2/feedback';
  1351. $content['userid'] = $this->auth->mobile;
  1352. $content['type'] = $type;
  1353. if ($itemid) {
  1354. $content['itemid'] = config('data_cp_id') . '|' . $itemid;
  1355. }
  1356. if ($otherid) {
  1357. $content['otherid'] = config('data_cp_id') . '|' . $otherid;
  1358. }
  1359. if ($prodid) {
  1360. $content['prodid'] = $prodid;
  1361. }
  1362. if ($trace_id) {
  1363. $content['trace_id'] = 'v2_1_2_1000035_' . $this->auth->mobile . '_153672384859_123456_01';
  1364. } else {
  1365. $content['trace_id'] = '';
  1366. }
  1367. if ($signal) {
  1368. $content['signal'] = $signal;
  1369. } else {
  1370. $content['signal'] = '';
  1371. }
  1372. if ($pos) {
  1373. $content['pos'] = $pos;
  1374. } else {
  1375. $content['pos'] = '';
  1376. }
  1377. if ($play_duration) {
  1378. $content['play_duration'] = $play_duration;
  1379. } else {
  1380. $content['play_duration'] = '';
  1381. }
  1382. $content['operate_time'] = getMillisecond();
  1383. $content = http_build_query($content);
  1384. $url = $url . '?' . $content;
  1385. $rt = file_get_contents($url);
  1386. if (!$rt) {
  1387. $this->error('上报失败');
  1388. }
  1389. $this->success('上报成功');
  1390. }
  1391. //用户观看行为(支付)
  1392. public function payuserplay() {
  1393. $id = input('id', 0, 'intval'); //视频id
  1394. $sn = input('sn', '', 'trim'); //SN号
  1395. $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
  1396. $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
  1397. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
  1398. if (!$id) {
  1399. $this->error('您的网络开小差了');
  1400. }
  1401. $info = Db::name('video')->where(['id' => $id])->find();
  1402. if (!$info) {
  1403. $this->error('数据不存在');
  1404. }
  1405. $content = [
  1406. 'UserID' => $this->auth->mobile,
  1407. 'city' => '14',
  1408. 'start_time' => $start_time,
  1409. 'end_time' => $end_time,
  1410. 'service_type' => 1,
  1411. 'albumid' => $id,
  1412. 'albumname' => $info['title'],
  1413. 'csource' => $csource,
  1414. 'SN' => $sn,
  1415. 'ip' => request()->ip(),
  1416. 'fee_type' => $info['is_pay'] == 1 ? 1 : '',
  1417. 'flow' => '',
  1418. 'product' => '',
  1419. 'product_name' => '',
  1420. 'info_source' => '02'
  1421. ];
  1422. $content = join('|', $content);
  1423. $filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.dat';
  1424. $check_filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.chk';
  1425. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  1426. error_log('', 3, './dashuju/' . $check_filename);
  1427. $this->success('');
  1428. }
  1429. //生活服务
  1430. public function life_service() {
  1431. $list = Db::name('life_service')->field('id, name, images')->where(['status' => 1])->page($this->page, $this->pagenum)->order('weigh, id')->select();
  1432. $list = list_domain_image($list, ['images']);
  1433. $this->success('生活服务', $list);
  1434. }
  1435. }