1 个管道
的构建
通过
耗费
1 秒
Merge branch 'master' of http://114.215.101.231:8099/guosheng/community into liuzhen
# Conflicts: # public/api.html
正在显示
4 个修改的文件
包含
155 行增加
和
5 行删除
@@ -134,7 +134,7 @@ class Goods extends Api | @@ -134,7 +134,7 @@ class Goods extends Api | ||
134 | $param = (new GoodsValidate())->goCheck('common'); | 134 | $param = (new GoodsValidate())->goCheck('common'); |
135 | $page = $param['page']; | 135 | $page = $param['page']; |
136 | $field = '*'; | 136 | $field = '*'; |
137 | - $order = 'createtime'; | 137 | + $order = ['goods_sort'=>'DESC','createtime'=>'DESC']; |
138 | $basic_where = [ | 138 | $basic_where = [ |
139 | 'goods_status' => '10', | 139 | 'goods_status' => '10', |
140 | 'is_delete' => '0' | 140 | 'is_delete' => '0' |
@@ -13,6 +13,10 @@ use app\common\controller\Api; | @@ -13,6 +13,10 @@ use app\common\controller\Api; | ||
13 | use think\Cache; | 13 | use think\Cache; |
14 | use think\Db; | 14 | use think\Db; |
15 | use think\Validate; | 15 | use think\Validate; |
16 | +use EasyWeChat\Foundation\Application as WXPAY_APP; | ||
17 | +use EasyWeChat\Payment\Order as WXPAY_ORDER; | ||
18 | +use addons\third\model\Third; | ||
19 | + | ||
16 | /** | 20 | /** |
17 | * 社区公告 | 21 | * 社区公告 |
18 | */ | 22 | */ |
@@ -464,7 +468,7 @@ class HouseBoard extends Api | @@ -464,7 +468,7 @@ class HouseBoard extends Api | ||
464 | ha.start_time, | 468 | ha.start_time, |
465 | ha.end_time, | 469 | ha.end_time, |
466 | ha.spec_type, | 470 | ha.spec_type, |
467 | - hj.pay_status | 471 | + hj.join_status |
468 | ') | 472 | ') |
469 | ->order("ha.createtime desc") | 473 | ->order("ha.createtime desc") |
470 | ->select(); | 474 | ->select(); |
@@ -475,13 +479,13 @@ class HouseBoard extends Api | @@ -475,13 +479,13 @@ class HouseBoard extends Api | ||
475 | // 活动日期 | 479 | // 活动日期 |
476 | $v['activity_time'] = date('Y-m-d',$v['start_time']).'-'.date('Y-m-d',$v['end_time']); | 480 | $v['activity_time'] = date('Y-m-d',$v['start_time']).'-'.date('Y-m-d',$v['end_time']); |
477 | // 活动状态 | 481 | // 活动状态 |
478 | - if($v['pay_status'] == '1'){ | 482 | + if($v['join_status'] == '1'){ |
479 | $status = ['text'=>'已报名','value'=>1]; | 483 | $status = ['text'=>'已报名','value'=>1]; |
480 | }else{ | 484 | }else{ |
481 | $status = $v['end_time'] < time() ? ['text'=>'已到期','value'=>2] : ['text'=>'报名中','value'=>0]; | 485 | $status = $v['end_time'] < time() ? ['text'=>'已到期','value'=>2] : ['text'=>'报名中','value'=>0]; |
482 | } | 486 | } |
483 | $v['status'] = $status; | 487 | $v['status'] = $status; |
484 | - unset($v['start_time'],$v['end_time'],$v['pay_status']); | 488 | + unset($v['start_time'],$v['end_time'],$v['join_status']); |
485 | } | 489 | } |
486 | return $list; | 490 | return $list; |
487 | } | 491 | } |
@@ -520,7 +524,8 @@ class HouseBoard extends Api | @@ -520,7 +524,8 @@ class HouseBoard extends Api | ||
520 | "spec_sku_id": "52_50", | 524 | "spec_sku_id": "52_50", |
521 | "price": "12.00" | 525 | "price": "12.00" |
522 | } | 526 | } |
523 | - } | 527 | + }, |
528 | + "price": "12.00" | ||
524 | } | 529 | } |
525 | }) | 530 | }) |
526 | */ | 531 | */ |
@@ -540,6 +545,150 @@ class HouseBoard extends Api | @@ -540,6 +545,150 @@ class HouseBoard extends Api | ||
540 | } | 545 | } |
541 | $spec_data['spec_list'] = $spec_list; | 546 | $spec_data['spec_list'] = $spec_list; |
542 | } | 547 | } |
548 | + $price = Db::name('house_activity_spec')->where('house_activity_id',$activity['id'])->value('price'); | ||
549 | + // 默认报名费 | ||
550 | + $spec_data['price'] = $price > 0 ? $price : 0; | ||
543 | $this->success(__('成功'),$spec_data); | 551 | $this->success(__('成功'),$spec_data); |
544 | } | 552 | } |
553 | + | ||
554 | + /** | ||
555 | + * @ApiTitle (社区公告-社区活动-报名) | ||
556 | + * @ApiSummary (社区公告-社区活动-报名) | ||
557 | + * @ApiMethod (POST) | ||
558 | + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") | ||
559 | + * @ApiParams (name="house_activity_id", type="integer", required=true, description="活动id") | ||
560 | + * @ApiParams (name="total_num", type="integer", required=true, description="数量") | ||
561 | + * @ApiParams (name="spec_sku_id", type="integer", description="活动规格sku") | ||
562 | + * @ApiParams (name="contact", type="string", required=true, description="姓名") | ||
563 | + * @ApiParams (name="mobile", type="string", required=true, description="联系方式") | ||
564 | + * @ApiParams (name="remark", type="string", description="备注") | ||
565 | + * @ApiReturn ({ | ||
566 | + 'code':'1', | ||
567 | + 'msg':'返回成功', | ||
568 | + "data": { | ||
569 | + } | ||
570 | + }) | ||
571 | + */ | ||
572 | + public function join(){ | ||
573 | + $house_activity_id = $this->request->param('house_activity_id'); | ||
574 | + $total_num = $this->request->param('total_num'); | ||
575 | + $spec_sku_id = $this->request->param('spec_sku_id',''); | ||
576 | + $contact = $this->request->param('contact'); | ||
577 | + $mobile = $this->request->param('mobile'); | ||
578 | + $remark = $this->request->param('remark'); | ||
579 | + // 验证 | ||
580 | + empty($house_activity_id) && $this->error('缺少必要参数'); | ||
581 | + empty($total_num) && $this->error('缺少必要参数'); | ||
582 | + empty($contact) && $this->error('缺少必要参数'); | ||
583 | + empty($mobile) && $this->error('缺少必要参数'); | ||
584 | + $activity = Db::name('house_activity') | ||
585 | + ->where('id',$house_activity_id) | ||
586 | + ->field('title,content,spec_type,start_time,end_time') | ||
587 | + ->find(); | ||
588 | + empty($activity) && $this->error('活动信息不存在'); | ||
589 | + if($activity['spec_type'] == '2' && empty($spec_sku_id)){ | ||
590 | + $this->error('多规格活动,请传入spec_sku_id'); | ||
591 | + } | ||
592 | + // 必要数据查询 | ||
593 | + $price = 0; //报名费 | ||
594 | + $total_price = 0; // 总报名费 | ||
595 | + $house_activity_spec_id = 0; // 活动规格ID | ||
596 | + if($activity['spec_type'] > '0'){ | ||
597 | + $house_activity_spec = Db::name('house_activity_spec') | ||
598 | + ->where('house_activity_id',$house_activity_id) | ||
599 | + ->where('spec_sku_id',$spec_sku_id) | ||
600 | + ->field('id,price') | ||
601 | + ->find(); | ||
602 | + $price = $house_activity_spec['price']; | ||
603 | + $total_price = $price * $total_num; | ||
604 | + $house_activity_spec_id = $house_activity_spec['id']; | ||
605 | + } | ||
606 | + // 生成报名订单 | ||
607 | + $house_join_id = Db::name('house_join')->insertGetId(array_merge([ | ||
608 | + 'order_no' => date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8), | ||
609 | + 'contact' => $contact, | ||
610 | + 'mobile' => $mobile, | ||
611 | + 'remark' => $remark, | ||
612 | + 'total_price' => $total_price, | ||
613 | + 'pay_price' => $total_price, | ||
614 | + 'user_id' => $this->auth->id, | ||
615 | + 'house_activity_id' => $house_activity_id, | ||
616 | + 'price' => $price, | ||
617 | + 'total_num' => $total_num, | ||
618 | + 'spec_sku_id' => $spec_sku_id, | ||
619 | + 'house_activity_spec_id' => $house_activity_spec_id, | ||
620 | + 'createtime' => time() | ||
621 | + ],$activity)); | ||
622 | + if($total_price > 0){ | ||
623 | + // 调起支付 | ||
624 | + $this->init_wx_pay_for_gzh(true); | ||
625 | + $this->make_wx_pay('wechat',$house_join_id); | ||
626 | + } | ||
627 | + // 免费活动直接报名成功 | ||
628 | + Db::name('house_join')->where('id',$house_join_id)->setField('join_status','1'); | ||
629 | + $this->success(__('报名成功')); | ||
630 | + } | ||
631 | + | ||
632 | + private function init_wx_pay_for_gzh($Ischeck=false){ | ||
633 | + //这里首先判断 此用户是否绑定了微信公众号 | ||
634 | + // if($Ischeck){ | ||
635 | + // $third = Third::where(['user_id' => $this->auth->id, 'platform' => 'wechat'])->find(); | ||
636 | + // if(!$third){ | ||
637 | + // //从这里自动绑定微信公众号的账户 | ||
638 | + // $this->error('您未绑定微信号',null,1008); | ||
639 | + // } | ||
640 | + // } | ||
641 | + | ||
642 | + $config = get_addon_config('litestore'); | ||
643 | + | ||
644 | + $third_config = get_addon_config('third'); | ||
645 | + $third_options = array_intersect_key($third_config, array_flip(['wechat'])); | ||
646 | + $third_options = $third_options['wechat']; | ||
647 | + | ||
648 | + $options = [ | ||
649 | + 'debug' => true, | ||
650 | + 'log' => [ | ||
651 | + 'level' => 'debug', | ||
652 | + 'file' => '/tmp/easywechat.log', | ||
653 | + ], | ||
654 | + 'app_id' => $third_options['app_id'], | ||
655 | + 'secret' => $third_options['app_secret'], | ||
656 | + 'payment' => [ | ||
657 | + 'merchant_id' => $config['MCHIDGZH'], | ||
658 | + 'key' => $config['APIKEYGZH'], | ||
659 | + 'notify_url' => \think\Request::instance()->domain().'/index/ajax/callback_for_wxgzh', | ||
660 | + ], | ||
661 | + | ||
662 | + ]; | ||
663 | + $this->wxapp = new WXPAY_APP($options); | ||
664 | + } | ||
665 | + | ||
666 | + private function make_wx_pay($platform,$house_join_id){ | ||
667 | + // 报名是否存在 | ||
668 | + $join = Db::name('house_join')->where('id',$house_join_id)->find(); | ||
669 | + empty($join) && $this->error('报名信息不存在'); | ||
670 | + $join['pay_status'] == '1' && $this->error('已支付,请勿重复操作'); | ||
671 | + | ||
672 | + $third = Third::where(['user_id' => $this->auth->id, 'platform' => $platform])->find(); | ||
673 | + $payment = $this->wxapp->payment; | ||
674 | + | ||
675 | + $attributes = [ | ||
676 | + 'trade_type' => 'JSAPI', | ||
677 | + 'body' => $join['order_no'], | ||
678 | + 'detail' => 'OrderID:'.$join['id'], | ||
679 | + 'out_trade_no' => $join['order_no'], | ||
680 | + //'total_fee' => $this->model['pay_price'] * 100, // 单位:分 | ||
681 | + 'total_fee' => 1, // 单位:分 | ||
682 | + 'openid' => $third['openid'], | ||
683 | + ]; | ||
684 | + $order = new WXPAY_ORDER($attributes); | ||
685 | + | ||
686 | + $result = $payment->prepare($order); | ||
687 | + if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){ | ||
688 | + $prepayId = $result->prepay_id; | ||
689 | + $config = $payment->configForJSSDKPayment($prepayId); // 返回数组 | ||
690 | + return $this->success('预支付成功',$config); | ||
691 | + } | ||
692 | + return $this->error('微信支付调用失败',$result); | ||
693 | + } | ||
545 | } | 694 | } |
public/api.html
已删除
100644 → 0
此 diff 太大无法显示。
-
请 注册 或 登录 后发表评论