...
|
...
|
@@ -13,6 +13,10 @@ use app\common\controller\Api; |
|
|
use think\Cache;
|
|
|
use think\Db;
|
|
|
use think\Validate;
|
|
|
use EasyWeChat\Foundation\Application as WXPAY_APP;
|
|
|
use EasyWeChat\Payment\Order as WXPAY_ORDER;
|
|
|
use addons\third\model\Third;
|
|
|
|
|
|
/**
|
|
|
* 社区公告
|
|
|
*/
|
...
|
...
|
@@ -464,7 +468,7 @@ class HouseBoard extends Api |
|
|
ha.start_time,
|
|
|
ha.end_time,
|
|
|
ha.spec_type,
|
|
|
hj.pay_status
|
|
|
hj.join_status
|
|
|
')
|
|
|
->order("ha.createtime desc")
|
|
|
->select();
|
...
|
...
|
@@ -475,13 +479,13 @@ class HouseBoard extends Api |
|
|
// 活动日期
|
|
|
$v['activity_time'] = date('Y-m-d',$v['start_time']).'-'.date('Y-m-d',$v['end_time']);
|
|
|
// 活动状态
|
|
|
if($v['pay_status'] == '1'){
|
|
|
if($v['join_status'] == '1'){
|
|
|
$status = ['text'=>'已报名','value'=>1];
|
|
|
}else{
|
|
|
$status = $v['end_time'] < time() ? ['text'=>'已到期','value'=>2] : ['text'=>'报名中','value'=>0];
|
|
|
}
|
|
|
$v['status'] = $status;
|
|
|
unset($v['start_time'],$v['end_time'],$v['pay_status']);
|
|
|
unset($v['start_time'],$v['end_time'],$v['join_status']);
|
|
|
}
|
|
|
return $list;
|
|
|
}
|
...
|
...
|
@@ -520,7 +524,8 @@ class HouseBoard extends Api |
|
|
"spec_sku_id": "52_50",
|
|
|
"price": "12.00"
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
"price": "12.00"
|
|
|
}
|
|
|
})
|
|
|
*/
|
...
|
...
|
@@ -540,6 +545,150 @@ class HouseBoard extends Api |
|
|
}
|
|
|
$spec_data['spec_list'] = $spec_list;
|
|
|
}
|
|
|
$price = Db::name('house_activity_spec')->where('house_activity_id',$activity['id'])->value('price');
|
|
|
// 默认报名费
|
|
|
$spec_data['price'] = $price > 0 ? $price : 0;
|
|
|
$this->success(__('成功'),$spec_data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (社区公告-社区活动-报名)
|
|
|
* @ApiSummary (社区公告-社区活动-报名)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="house_activity_id", type="integer", required=true, description="活动id")
|
|
|
* @ApiParams (name="total_num", type="integer", required=true, description="数量")
|
|
|
* @ApiParams (name="spec_sku_id", type="integer", description="活动规格sku")
|
|
|
* @ApiParams (name="contact", type="string", required=true, description="姓名")
|
|
|
* @ApiParams (name="mobile", type="string", required=true, description="联系方式")
|
|
|
* @ApiParams (name="remark", type="string", description="备注")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
"data": {
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function join(){
|
|
|
$house_activity_id = $this->request->param('house_activity_id');
|
|
|
$total_num = $this->request->param('total_num');
|
|
|
$spec_sku_id = $this->request->param('spec_sku_id','');
|
|
|
$contact = $this->request->param('contact');
|
|
|
$mobile = $this->request->param('mobile');
|
|
|
$remark = $this->request->param('remark');
|
|
|
// 验证
|
|
|
empty($house_activity_id) && $this->error('缺少必要参数');
|
|
|
empty($total_num) && $this->error('缺少必要参数');
|
|
|
empty($contact) && $this->error('缺少必要参数');
|
|
|
empty($mobile) && $this->error('缺少必要参数');
|
|
|
$activity = Db::name('house_activity')
|
|
|
->where('id',$house_activity_id)
|
|
|
->field('title,content,spec_type,start_time,end_time')
|
|
|
->find();
|
|
|
empty($activity) && $this->error('活动信息不存在');
|
|
|
if($activity['spec_type'] == '2' && empty($spec_sku_id)){
|
|
|
$this->error('多规格活动,请传入spec_sku_id');
|
|
|
}
|
|
|
// 必要数据查询
|
|
|
$price = 0; //报名费
|
|
|
$total_price = 0; // 总报名费
|
|
|
$house_activity_spec_id = 0; // 活动规格ID
|
|
|
if($activity['spec_type'] > '0'){
|
|
|
$house_activity_spec = Db::name('house_activity_spec')
|
|
|
->where('house_activity_id',$house_activity_id)
|
|
|
->where('spec_sku_id',$spec_sku_id)
|
|
|
->field('id,price')
|
|
|
->find();
|
|
|
$price = $house_activity_spec['price'];
|
|
|
$total_price = $price * $total_num;
|
|
|
$house_activity_spec_id = $house_activity_spec['id'];
|
|
|
}
|
|
|
// 生成报名订单
|
|
|
$house_join_id = Db::name('house_join')->insertGetId(array_merge([
|
|
|
'order_no' => date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8),
|
|
|
'contact' => $contact,
|
|
|
'mobile' => $mobile,
|
|
|
'remark' => $remark,
|
|
|
'total_price' => $total_price,
|
|
|
'pay_price' => $total_price,
|
|
|
'user_id' => $this->auth->id,
|
|
|
'house_activity_id' => $house_activity_id,
|
|
|
'price' => $price,
|
|
|
'total_num' => $total_num,
|
|
|
'spec_sku_id' => $spec_sku_id,
|
|
|
'house_activity_spec_id' => $house_activity_spec_id,
|
|
|
'createtime' => time()
|
|
|
],$activity));
|
|
|
if($total_price > 0){
|
|
|
// 调起支付
|
|
|
$this->init_wx_pay_for_gzh(true);
|
|
|
$this->make_wx_pay('wechat',$house_join_id);
|
|
|
}
|
|
|
// 免费活动直接报名成功
|
|
|
Db::name('house_join')->where('id',$house_join_id)->setField('join_status','1');
|
|
|
$this->success(__('报名成功'));
|
|
|
}
|
|
|
|
|
|
private function init_wx_pay_for_gzh($Ischeck=false){
|
|
|
//这里首先判断 此用户是否绑定了微信公众号
|
|
|
// if($Ischeck){
|
|
|
// $third = Third::where(['user_id' => $this->auth->id, 'platform' => 'wechat'])->find();
|
|
|
// if(!$third){
|
|
|
// //从这里自动绑定微信公众号的账户
|
|
|
// $this->error('您未绑定微信号',null,1008);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
$config = get_addon_config('litestore');
|
|
|
|
|
|
$third_config = get_addon_config('third');
|
|
|
$third_options = array_intersect_key($third_config, array_flip(['wechat']));
|
|
|
$third_options = $third_options['wechat'];
|
|
|
|
|
|
$options = [
|
|
|
'debug' => true,
|
|
|
'log' => [
|
|
|
'level' => 'debug',
|
|
|
'file' => '/tmp/easywechat.log',
|
|
|
],
|
|
|
'app_id' => $third_options['app_id'],
|
|
|
'secret' => $third_options['app_secret'],
|
|
|
'payment' => [
|
|
|
'merchant_id' => $config['MCHIDGZH'],
|
|
|
'key' => $config['APIKEYGZH'],
|
|
|
'notify_url' => \think\Request::instance()->domain().'/index/ajax/callback_for_wxgzh',
|
|
|
],
|
|
|
|
|
|
];
|
|
|
$this->wxapp = new WXPAY_APP($options);
|
|
|
}
|
|
|
|
|
|
private function make_wx_pay($platform,$house_join_id){
|
|
|
// 报名是否存在
|
|
|
$join = Db::name('house_join')->where('id',$house_join_id)->find();
|
|
|
empty($join) && $this->error('报名信息不存在');
|
|
|
$join['pay_status'] == '1' && $this->error('已支付,请勿重复操作');
|
|
|
|
|
|
$third = Third::where(['user_id' => $this->auth->id, 'platform' => $platform])->find();
|
|
|
$payment = $this->wxapp->payment;
|
|
|
|
|
|
$attributes = [
|
|
|
'trade_type' => 'JSAPI',
|
|
|
'body' => $join['order_no'],
|
|
|
'detail' => 'OrderID:'.$join['id'],
|
|
|
'out_trade_no' => $join['order_no'],
|
|
|
//'total_fee' => $this->model['pay_price'] * 100, // 单位:分
|
|
|
'total_fee' => 1, // 单位:分
|
|
|
'openid' => $third['openid'],
|
|
|
];
|
|
|
$order = new WXPAY_ORDER($attributes);
|
|
|
|
|
|
$result = $payment->prepare($order);
|
|
|
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){
|
|
|
$prepayId = $result->prepay_id;
|
|
|
$config = $payment->configForJSSDKPayment($prepayId); // 返回数组
|
|
|
return $this->success('预支付成功',$config);
|
|
|
}
|
|
|
return $this->error('微信支付调用失败',$result);
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|