Activity.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ActivityApply;
  4. use app\common\model\PlatformLike;
  5. use app\common\model\User;
  6. use app\common\model\UserCollect;
  7. use app\common\model\UserSearch;
  8. use app\common\model\UserTrack;
  9. use app\common\service\OrderCallback;
  10. use think\Db;
  11. /**
  12. * @title 活动
  13. * @controller Activity
  14. * @group base
  15. */
  16. class Activity extends Base
  17. {
  18. // 需要登录的
  19. protected $need_login = ['activityTags','activityCollect','activityTransmit','activityApply','payApplyOrder'];
  20. public function initialize()
  21. {
  22. parent::initialize();
  23. parent::setUid();
  24. }
  25. /**
  26. * @title 活动推荐
  27. * @desc 活动推荐
  28. * @author qc
  29. * @method GET
  30. * @url /api/Activity/getRecommendList
  31. * @header name:Authorization require:1 desc:Token
  32. * @param name:page type:int default:0 desc:页数
  33. * @param name:page_num type:int default:20 desc:每页数
  34. * @return name:id type:string default:-- desc:资料item_id
  35. * @return name:id type:int default:-- desc:id
  36. * @return name:address type:string default:-- desc:地址
  37. * @return name:cover type:string default:-- desc:封面
  38. * @return name:label_name type:array default:-- desc:标签
  39. * @return name:start_time type:string default:-- desc:开始时间
  40. * @return name:end_time type:string default:-- desc:结束时候
  41. * @return name:end_time type:string default:-- desc:结束时间
  42. * @return name:price type:string default:-- desc:价格
  43. * @return name:status type:int default:-- desc:活动状态1正常2取消
  44. * @return name:is_apply type:int default:-- desc:是否报名(0否1是)
  45. */
  46. public function getRecommendList()
  47. {
  48. $search_log = UserSearch::getSearchTitle($this->user_id,11);
  49. $search_arr = [];
  50. $where_str = 'b.id > 0';
  51. foreach ($search_log as $t){
  52. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  53. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  54. }
  55. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  56. $field = 'a.id,cover,a.user_id,title,a.status,address,label,start_time,end_time,ladder,price,IFNULL(is_recommend,0) is_recommend ';
  57. $table = 'dd_activity';
  58. $order_by_two = 'read_num';
  59. $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
  60. $list = Db::query($sql);
  61. array_walk($list,function (&$v,$k){
  62. $v['is_apply'] = ActivityApply::checkApply($this->user_id,$v['id']);
  63. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  64. });
  65. $this->success('ok',['list'=>$list]);
  66. }
  67. /**
  68. * @title 获取活动列表
  69. * @desc 获取活动列表
  70. * @author qc
  71. * @method GET
  72. * @url /api/Activity/getActivityList
  73. * @header name:Authorization require:1 desc:Token
  74. * @param name:title type:string default:-- desc:标题
  75. * @param name:page type:int default:0 desc:页数
  76. * @param name:page_num type:int default:20 desc:每页数
  77. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  78. * @return name:title type:string default:-- desc:标题
  79. * @return name:cover type:string default:-- desc:图片多张|隔开
  80. * @return name:status type:int default:-- desc:活动状态1正常2取消
  81. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  82. * @return name:content type:string default:-- desc:详情
  83. * @return name:create_at type:string default:-- desc:时间
  84. * @return name:start_time type:string default:-- desc:开始时间
  85. * @return name:end_time type:string default:-- desc:结束时间
  86. * @return name:address type:string default:-- desc:地址
  87. * @return name:price type:float default:-- desc:价格
  88. * @return name:label type:string default:-- desc:标签[多个','隔开]
  89. * @return name:label_name type:array default:-- desc:标签[数组]
  90. * @return name:is_apply type:int default:0 desc:是否报名【0否1是】
  91. */
  92. public function getActivityList(){
  93. $title = input('get.title');
  94. $sort_type = input('get.sort_type',1);
  95. switch ($sort_type) {
  96. case 1:
  97. $order = ['sort'=>'desc','id'=>'desc'];
  98. break;
  99. case 2:
  100. $order = ['id'=>'asc','sort'=>'desc'];
  101. break;
  102. case 3:
  103. $order = ['id'=>'desc','sort'=>'desc'];
  104. break;
  105. }
  106. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,11);
  107. $list = \app\common\model\Activity::where(['is_deleted'=>0,'status'=>1])
  108. ->when($title,function ($query)use($title){
  109. if($title) $query->where('title|label','like','%'.$title.'%');
  110. })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
  111. foreach ($list as &$v) {
  112. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  113. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  114. $v['is_apply'] = ActivityApply::checkApply($this->user_id,$v['id']);
  115. $v['ladder_arr'] = json_decode($v['ladder'],true);
  116. }
  117. $this->success('ok',['list'=>$list]);
  118. }
  119. /**
  120. * @title 获取活动详情
  121. * @desc 获取活动详情
  122. * @author qc
  123. * @method GET
  124. * @url /api/Activity/getActivityDetail
  125. * @header name:Authorization require:1 desc:Token
  126. * @param name:id type:int default:-- desc:活动id
  127. * @return name:title type:string default:-- desc:标题
  128. * @return name:cover type:string default:-- desc:图片多张|隔开
  129. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  130. * @return name:status type:int default:-- desc:活动状态1正常2取消
  131. * @return name:content type:string default:-- desc:详情
  132. * @return name:create_at type:string default:-- desc:时间
  133. * @return name:start_time type:string default:-- desc:开始时间
  134. * @return name:end_time type:string default:-- desc:结束时间
  135. * @return name:address type:string default:-- desc:地址
  136. * @return name:price type:float default:-- desc:价格
  137. * @return name:label type:string default:-- desc:标签[多个','隔开]
  138. * @return name:label_name type:array default:-- desc:标签[数组]
  139. * @return name:is_apply type:int default:0 desc:是否报名【0否1是】
  140. * @return name:praise_num type:int default:-- desc:点赞量
  141. * @return name:is_praise type:int default:-- desc:是否点赞【0否1是】
  142. * @return name:is_collect type:int default:-- desc:是否收藏【0否1是】
  143. * @return name:collect_num type:int default:-- desc:收藏量
  144. * @return name:transmit_num type:int default:-- desc:转发量
  145. * @return name:app_name type:string default:-- desc:发布方名称
  146. * @return name:app_logo type:string default:-- desc:发布方头像
  147. * @return name:ladder_arr type:array default:-- desc:价格阶梯设置
  148. * @return name:ladder_arr.ladder_num type:int default:-- desc:人数
  149. * @return name:ladder_arr.ladder_num type:float default:-- desc:价格
  150. */
  151. public function getActivityDetail()
  152. {
  153. $sel_where[] = ['id','=',input('get.id')];
  154. $detail = \app\common\model\Activity::where($sel_where)->find()->toArray();
  155. $detail['cover_arr'] = $detail['cover'] ? explode('|',$detail['cover']) : null;
  156. $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')): null;
  157. $detail['is_apply'] = ActivityApply::checkApply($this->user_id,$detail['id']);
  158. $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],4);
  159. $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],4);
  160. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,7,$detail['id']);
  161. $detail['collect_num'] = UserCollect::getCollectNum(7,$detail['id']);
  162. $detail['ladder_arr'] = $detail['ladder'] ? json_decode($detail['ladder']): null;
  163. if(!$detail['user_id']){
  164. $detail['app_name'] = sysconf('app_name');
  165. $detail['app_logo'] = sysconf('app_logo');
  166. }else{
  167. $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
  168. $detail['app_name'] = $user_info ? $user_info->name : '';
  169. $detail['app_logo'] = $user_info ? $user_info->headimg : '';
  170. }
  171. UserTrack::crateTrack($this->user_id,7,input('get.id'),0);
  172. $this->success('ok',['detail'=>$detail]);
  173. }
  174. /**
  175. * @title 以下接口调用验证登录【需要header传Authorization】
  176. * @desc 以下接口调用验证登录
  177. * @author qc
  178. * @method
  179. * @url /api/Activity/needLogin()
  180. */
  181. public function needLogin(){}
  182. /**
  183. * @title 点赞||取消点赞
  184. * @desc 点赞||取消点赞
  185. * @author qc
  186. * @method POST
  187. * @url /api/Activity/activityTags
  188. * @header name:Authorization require:1 desc:Token
  189. * @param name:id type:int default:1 desc:活动id
  190. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  191. */
  192. public function activityTags()
  193. {
  194. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),4);
  195. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  196. }
  197. /**
  198. * @title 收藏||取消收藏
  199. * @desc 用户收藏
  200. * @author qc
  201. * @method POST
  202. * @url /api/Activity/activityCollect
  203. * @header name:Authorization require:1 desc:Token
  204. * @param name:id type:int require:1 default:-- desc:活动id
  205. * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  206. */
  207. public function activityCollect(){
  208. $coll_status = UserCollect::plateCollect($this->user_id,7,input('post.id',0));
  209. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  210. }
  211. /**
  212. * @title 活动转发(转发数量统计)
  213. * @desc 转发成功后调用
  214. * @author qc
  215. * @method POST
  216. * @url /api/Activity/activityTransmit
  217. * @header name:Authorization require:1 desc:Token
  218. * @param name:id type:int default:-- desc:活动id
  219. */
  220. public function activityTransmit()
  221. {
  222. $activity_id = input('post.id',0);
  223. \app\common\model\Activity::where('id',$activity_id)->setInc('transmit_num');
  224. $this->success('ok');
  225. }
  226. /**
  227. * @title 活动报名
  228. * @desc 活动报名[生成订单(报名记录),返回支付信息]
  229. * @author qc
  230. * @method POST
  231. * @url /api/Activity/activityApply
  232. * @header name:Authorization require:1 desc:Token
  233. * @param name:act_id type:int default:-- desc:活动id
  234. * @param name:name type:string default:-- desc:联系人
  235. * @param name:phone type:string default:-- desc:联系人电话
  236. * @param name:email type:string default:-- desc:email
  237. * @param name:num type:int default:-- desc:报名人数
  238. * @param name:phone_code type:int default:-- desc:短信验证码
  239. * @param name:pay_type type:int require:1 default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付)
  240. * @param name:port type:int default:1 desc:来源【1:h5,2:安卓,3:ios】
  241. *
  242. * @return name:pay_status type:int default:0 desc:该值为1:订单金额是0不需要支付!!!
  243. * @return name:config type:array default:0 desc:支付配置
  244. * @return name:config.appId type:string default:-- desc:公众账号ID
  245. * @return name:config.signType type:string default:-- desc:签名类型
  246. * @return name:config.paySign type:string default:-- desc:签名
  247. * @return name:config.nonceStr type:string default:-- desc:随机字符串
  248. * @return name:config.timestamp type:string default:-- desc:时间戳
  249. * @return name:config.partnerid type:string default:-- desc:商户号
  250. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  251. * @return name:config.package type:string default:-- desc:package
  252. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  253. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  254. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  255. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  256. * @return name:code_url type:string default:-- desc:付款码url
  257. * @return name:openid type:string default:-- desc:openid
  258. */
  259. public function activityApply()
  260. {
  261. $act_id = input('post.act_id');
  262. $name = input('post.name');
  263. $phone = input('post.phone');
  264. $email = input('post.email');
  265. $num = input('post.num',1);
  266. $port = input('post.port',1);
  267. $phone_code = input('post.phone_code');
  268. $pay_type = input('post.pay_type',1);
  269. if(!$name || !$phone || !$email) $this->error('请完善报名信息');
  270. if(!in_array($pay_type,[1,2,3,4,5])) $this->error('支付方式错误');
  271. if($num <= 0) $this->error('请输入报名人数');
  272. $check_apply = ActivityApply::checkApply($this->user_id,$act_id);
  273. //if($check_apply) $this->error('已报名!');
  274. $act_info = \app\common\model\Activity::where('id',$act_id)->where('is_deleted',0)->find();
  275. if(!$act_info) $this->error('活动不存在');
  276. if(strtotime($act_info->end_time) < time() ) $this->error('活动已经结束');
  277. if(strtotime($act_info->start_time) < time() ) $this->error('活动已经开始');
  278. if($act_info->status == 2) $this->error('活动已经取消');
  279. $check_code = $this->checkPhoneCode($phone,$phone_code);
  280. // if(!$check_code) $this->error('验证码错误');
  281. $this->updatePhoneCode($check_code);
  282. $ladder = $act_info->ladder ? json_decode($act_info->ladder,true) : [];
  283. $order_money = bcmul($act_info->price,$num,2);
  284. if(!empty($ladder)) {
  285. $ladder_set = array_column($ladder,null,'ladder_num');
  286. krsort($ladder_set);
  287. $max_num = array_column($ladder_set,'ladder_num');
  288. $min_num = array_column($ladder_set,'ladder_num');
  289. if($max_num < $num) {
  290. $order_money = bcmul($ladder_set[$max_num]['ladder_price'],$num,2);
  291. }else if ($min_num > $num){
  292. foreach ($ladder_set as $lk=>$lv) {
  293. if($lk <= $num){
  294. $order_money = bcmul($lv['ladder_price'],$num,2);
  295. break;
  296. }
  297. }
  298. }
  299. }
  300. if($order_money < 0 )$this->error('报名费不能小于0');
  301. $apply_info = [
  302. 'user_id' => $this->user_id,
  303. 'order_no' => get_order_sn(),
  304. 'pay_no' => get_order_sn(),
  305. 'num' => $num,
  306. 'name' => $name,
  307. 'phone' => $phone,
  308. 'email' => $email,
  309. 'pay_type' => $pay_type,
  310. 'money' => $order_money,
  311. 'port' => $port,
  312. 'act_id' => $act_id,
  313. ];
  314. $user_info = User::where('id',$this->user_id)->find();
  315. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
  316. Db::startTrans();
  317. try {
  318. $order_info = ActivityApply::create($apply_info)->toArray();
  319. if($order_money == 0) {
  320. $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
  321. if(!$back_res['ret_val']) $this->exception('报名失败');
  322. $ret_data['pay_status'] = 1;
  323. }else{
  324. $ret_data['order_id'] = $order_info['id'];
  325. switch ($pay_type){
  326. case 1:
  327. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  328. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
  329. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  330. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  331. $pay_config['config']['pay_no'] = $order_info['pay_no'];
  332. $pay_config['config']['notify_url'] = $notify_url;
  333. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  334. $pay_config['config']['total_fee'] = $order_info['money'] * 100;
  335. $ret_data['config'] = $pay_config['config'];
  336. break;
  337. case 2:
  338. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  339. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  340. $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  341. $ret_data['config']['ali_url'] = $config;
  342. $ret_data['ali_url'] = $config;
  343. break;
  344. case 3:
  345. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  346. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
  347. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  348. $ret_data['config'] = $pay_config['config'];
  349. break;
  350. case 4:
  351. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  352. $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
  353. $ret_data['config']['ali_url'] = $config;
  354. $ret_data['ali_url'] = $config;
  355. $ret_data['money'] = $order_info['money'];
  356. break;
  357. case 5 :
  358. if(!$user_info['openid']) $this->exception('请绑定openid');
  359. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  360. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
  361. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  362. $ret_data['config'] = $pay_config['config'];
  363. break;
  364. }
  365. }
  366. Db::commit();
  367. }catch (\Exception $e){
  368. Db::rollback();
  369. $this->error($e->getMessage());
  370. }
  371. $this->success('报名成功',$ret_data);
  372. }
  373. /**
  374. * @title 活动报名订单支付
  375. * @desc 活动报名订单支付
  376. * @author qc
  377. * @method POST
  378. * @url /api/Activity/payApplyOrder
  379. * @header name:Authorization require:1 desc:Token
  380. * @param name:order_id type:int default:-- desc:订单id【报名记录id】
  381. *
  382. * @return name:pay_status type:array default:0 desc:该值为1:订单金额是0不需要支付!!!
  383. * @return name:config type:array default:0 desc:支付配置
  384. * @return name:config.appId type:string default:-- desc:公众账号ID
  385. * @return name:config.signType type:string default:-- desc:签名类型
  386. * @return name:config.paySign type:string default:-- desc:签名
  387. * @return name:config.nonceStr type:string default:-- desc:随机字符串
  388. * @return name:config.timestamp type:string default:-- desc:时间戳
  389. * @return name:config.partnerid type:string default:-- desc:商户号
  390. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  391. * @return name:config.package type:string default:-- desc:package
  392. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  393. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  394. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  395. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  396. * @return name:code_url type:string default:-- desc:付款码url
  397. * @return name:openid type:string default:-- desc:openid
  398. */
  399. public function payApplyOrder()
  400. {
  401. $order_id = input('post.order_id');
  402. $order_info = ActivityApply::where('id',$order_id)->find()->toArray();
  403. if($order_info['status'] != 0) $this->error('订单状态错误');
  404. if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
  405. if($order_info['money'] <= 0) $this->error('订单金额错误');
  406. $pay_type = $order_info['pay_type'];
  407. $user_info = User::where('id',$this->user_id)->find();
  408. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
  409. Db::startTrans();
  410. try {
  411. switch ($pay_type){
  412. case 1:
  413. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  414. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
  415. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  416. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  417. $pay_config['config']['pay_no'] = $order_info['pay_no'];
  418. $pay_config['config']['notify_url'] = $notify_url;
  419. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  420. $pay_config['config']['total_fee'] = $order_info['money'] * 100;
  421. $ret_data['config'] = $pay_config['config'];
  422. break;
  423. case 2:
  424. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  425. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  426. $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  427. $ret_data['config']['ali_url'] = $config;
  428. $ret_data['ali_url'] = $config;
  429. break;
  430. case 3:
  431. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  432. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
  433. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  434. $ret_data['config'] = $pay_config['config'];
  435. break;
  436. case 4:
  437. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  438. $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
  439. $ret_data['config']['ali_url'] = $config;
  440. $ret_data['ali_url'] = $config;
  441. $ret_data['money'] = $order_info['money'];
  442. break;
  443. case 5 :
  444. if(!$user_info['openid']) $this->exception('请绑定openid');
  445. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  446. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
  447. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  448. $ret_data['config'] = $pay_config['config'];
  449. break;
  450. }
  451. Db::commit();
  452. }catch (\Exception $e){
  453. Db::rollback();
  454. $this->error($e->getMessage());
  455. }
  456. $this->success('ok',$ret_data);
  457. }
  458. /**
  459. * @title 我的发布列表
  460. * @desc 我的发布列表
  461. * @author qc
  462. * @method GET
  463. * @url /api/Activity/getMyActivityList
  464. * @header name:Authorization require:1 desc:Token
  465. * @param name:title type:string default:-- desc:标题
  466. * @param name:page type:int default:0 desc:页数
  467. * @param name:page_num type:int default:20 desc:每页数
  468. * @return name:title type:string default:-- desc:标题
  469. * @return name:cover type:string default:-- desc:图片多张|隔开
  470. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  471. * @return name:content type:string default:-- desc:详情
  472. * @return name:create_at type:string default:-- desc:时间
  473. * @return name:start_time type:string default:-- desc:开始时间
  474. * @return name:end_time type:string default:-- desc:结束时间
  475. * @return name:address type:string default:-- desc:地址
  476. * @return name:price type:float default:-- desc:价格
  477. * @return name:label type:string default:-- desc:标签[多个','隔开]
  478. * @return name:label_name type:array default:-- desc:标签[数组]
  479. */
  480. public function getMyActivityList(){
  481. $title = input('get.title');
  482. $list = \app\common\model\Activity::where(['is_deleted'=>0,'user_id'=>$this->user_id])
  483. ->when($title,function ($query)use($title){
  484. if($title) $query->where('title|label','like','%'.$title.'%');
  485. })->order( ['sort'=>'desc','id'=>'desc'])->limit($this->off_set,$this->page_num)->select()->toArray();
  486. foreach ($list as &$v) {
  487. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  488. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  489. }
  490. $this->success('ok',['list'=>$list]);
  491. }
  492. /**
  493. * @title 我的收藏【活动】
  494. * @desc 我的收藏
  495. * @author qc
  496. * @method GET
  497. * @url /api/Activity/getCollectActivity
  498. * @header name:Authorization require:1 desc:Token
  499. * @param name:title type:string default:-- desc:标题
  500. * @param name:page type:int default:0 desc:页数
  501. * @param name:page_num type:int default:20 desc:每页数
  502. * @return name:title type:string default:-- desc:标题
  503. * @return name:activity_id type:string default:-- desc:活动id
  504. * @return name:cover type:string default:-- desc:图片多张|隔开
  505. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  506. * @return name:content type:string default:-- desc:详情
  507. * @return name:create_at type:string default:-- desc:时间
  508. * @return name:start_time type:string default:-- desc:开始时间
  509. * @return name:end_time type:string default:-- desc:结束时间
  510. * @return name:address type:string default:-- desc:地址
  511. * @return name:price type:float default:-- desc:价格
  512. * @return name:label type:string default:-- desc:标签[多个','隔开]
  513. * @return name:label_name type:array default:-- desc:标签[数组]
  514. */
  515. public function getCollectActivity()
  516. {
  517. $sel_where = [];
  518. $title = input('get.title');
  519. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  520. $sel_where[] = ['t.user_id','=',$this->user_id];
  521. $sel_where[] = ['t.coll_type','=',7];
  522. $list = UserCollect::where($sel_where)
  523. ->alias('t')
  524. ->field('t.id,t.create_at,t.coll_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
  525. ->leftJoin('Activity i','t.coll_id = i.id')
  526. ->order('id desc')
  527. ->limit($this->off_set,$this->page_num)
  528. ->select()->toArray();
  529. foreach ($list as &$v) {
  530. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  531. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  532. }
  533. $this->success('ok',['list'=>$list]);
  534. }
  535. /**
  536. * @title 浏览记录【活动】
  537. * @desc 浏览记录
  538. * @author qc
  539. * @method GET
  540. * @url /api/Activity/getActivityTrack
  541. * @header name:Authorization require:1 desc:Token
  542. * @param name:title type:string default:-- desc:标题
  543. * @param name:page type:int default:0 desc:页数
  544. * @param name:page_num type:int default:20 desc:每页数
  545. * @return name:title type:string default:-- desc:标题
  546. * @return name:activity_id type:string default:-- desc:活动id
  547. * @return name:cover type:string default:-- desc:图片多张|隔开
  548. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  549. * @return name:content type:string default:-- desc:详情
  550. * @return name:start_time type:string default:-- desc:开始时间
  551. * @return name:end_time type:string default:-- desc:结束时间
  552. * @return name:address type:string default:-- desc:地址
  553. * @return name:price type:float default:-- desc:价格
  554. * @return name:label type:string default:-- desc:标签[多个','隔开]
  555. * @return name:label_name type:array default:-- desc:标签[数组]
  556. * @return name:time type:string default:-- desc:时间
  557. */
  558. public function getActivityTrack()
  559. {
  560. $sel_where = [];
  561. $sel_where[] = ['t.user_id','=',$this->user_id];
  562. $sel_where[] = ['t.type','=',4];
  563. $title = input('get.title');
  564. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  565. $list = UserTrack::where($sel_where)
  566. ->alias('t')
  567. ->field('t.id,t.update_int,t.first_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
  568. ->leftJoin('Activity i','t.first_id = i.id')
  569. ->order('update_int desc')
  570. ->limit($this->off_set,$this->page_num)
  571. ->select()->toArray();
  572. foreach ($list as &$v) {
  573. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  574. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  575. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  576. }
  577. $this->success('ok',['list'=>$list]);
  578. }
  579. /**
  580. * @title 我的点赞【活动】
  581. * @desc 我的点赞
  582. * @author qc
  583. * @method GET
  584. * @url /api/Activity/getTagsActivity
  585. * @header name:Authorization require:1 desc:Token
  586. * @param name:title type:string default:-- desc:标题
  587. * @param name:page type:int default:0 desc:页数
  588. * @param name:page_num type:int default:20 desc:每页数
  589. * @return name:title type:string default:-- desc:标题
  590. * @return name:activity_id type:string default:-- desc:活动id
  591. * @return name:cover type:string default:-- desc:图片多张|隔开
  592. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  593. * @return name:content type:string default:-- desc:详情
  594. * @return name:start_time type:string default:-- desc:开始时间
  595. * @return name:end_time type:string default:-- desc:结束时间
  596. * @return name:address type:string default:-- desc:地址
  597. * @return name:price type:float default:-- desc:价格
  598. * @return name:label type:string default:-- desc:标签[多个','隔开]
  599. * @return name:label_name type:array default:-- desc:标签[数组]
  600. */
  601. public function getTagsActivity()
  602. {
  603. $sel_where = [];
  604. $title = input('get.title');
  605. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  606. $sel_where[] = ['t.user_id','=',$this->user_id];
  607. $sel_where[] = ['t.type','=',4];
  608. $list = PlatformLike::where($sel_where)
  609. ->alias('t')
  610. ->field('t.id,t.create_at,t.like_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
  611. ->leftJoin('Activity i','t.like_id = i.id')
  612. ->order('id desc')
  613. ->limit($this->off_set,$this->page_num)
  614. ->select()->toArray();
  615. foreach ($list as &$v) {
  616. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  617. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  618. }
  619. $this->success('ok',['list'=>$list]);
  620. }
  621. /**
  622. * @title 我的报名【活动】
  623. * @desc 我的报名
  624. * @author qc
  625. * @method GET
  626. * @url /api/Activity/getApplyList
  627. * @header name:Authorization require:1 desc:Token
  628. * @param name:title type:string default:-- desc:标题
  629. * @param name:page type:int default:0 desc:页数
  630. * @param name:page_num type:int default:20 desc:每页数
  631. * @return name:title type:string default:-- desc:标题
  632. * @return name:activity_id type:string default:-- desc:活动id
  633. * @return name:status type:int default:-- desc:活动状态1正常2取消
  634. * @return name:cover type:string default:-- desc:图片多张|隔开
  635. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  636. * @return name:content type:string default:-- desc:详情
  637. * @return name:start_time type:string default:-- desc:开始时间
  638. * @return name:end_time type:string default:-- desc:结束时间
  639. * @return name:address type:string default:-- desc:地址
  640. * @return name:price type:float default:-- desc:价格
  641. * @return name:label type:string default:-- desc:标签[多个','隔开]
  642. * @return name:label_name type:array default:-- desc:标签[数组]
  643. */
  644. public function getApplyList()
  645. {
  646. $sel_where = [];
  647. $title = input('get.title');
  648. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  649. $sel_where[] = ['t.user_id','=',$this->user_id];
  650. $sel_where[] = ['t.status','=',1];
  651. $list = ActivityApply::where($sel_where)
  652. ->field('t.id,t.order_no,t.act_id activity_id,i.title,i.status,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
  653. ->alias('t')
  654. ->leftJoin('Activity i','t.act_id = i.id')
  655. ->order(['t.id'=>'desc'])
  656. ->limit($this->off_set,$this->page_num)
  657. ->select()->toArray();
  658. foreach ($list as &$v) {
  659. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  660. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  661. }
  662. $this->success('ok',['list'=>$list]);
  663. }
  664. }