作者 郭鑫

退款功能,后台功能调试

... ... @@ -62,6 +62,52 @@ class AlipayController extends NotifyCommonController
var_dump($response);
}
// 退款
public function refund($data) {
// $data = $this->request->param();
$config = $this->config;
//商户订单号,商户网站订单系统中唯一订单号
$out_trade_no = '';
if(!empty($data['out_trade_no'])) {
$out_trade_no = trim($data['out_trade_no']);
}
//支付宝交易号
if(!empty($data['trade_no'])) {
$trade_no = trim($data['trade_no']);
}
//请二选一设置
//需要退款的金额,该金额不能大于订单金额,必填
$refund_amount = trim($data['refund_amount']);
//退款的原因说明
$refund_reason = trim($data['refund_reason']);
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
// $out_request_no = trim($data['WIDTRout_request_no']);
$out_request_no = '';
//构造参数
$RequestBuilder=new \AlipayTradeRefundContentBuilder();
$RequestBuilder->setOutTradeNo($out_trade_no);
$RequestBuilder->setTradeNo($trade_no);
$RequestBuilder->setRefundAmount($refund_amount);
$RequestBuilder->setOutRequestNo($out_request_no);
$RequestBuilder->setRefundReason($refund_reason);
$aop = new \AlipayTradeService($config);
/**
* alipay.trade.refund (统一收单交易退款接口)
* @param $builder 业务参数,使用buildmodel中的对象生成。
* @return $response 支付宝返回的信息
*/
$response = $aop->Refund($RequestBuilder);
return $response;
}
// 回调
public function notify_url() {
$config = $this->config;
... ...
... ... @@ -12,6 +12,7 @@ use api\portal\model\AgencyModel;
use api\portal\model\MemberModel;
use api\portal\model\MoneyDetailModel;
use api\portal\model\OrderModel;
use api\portal\model\RewardModel;
use api\portal\model\UserNeedModel;
use cmf\controller\HomeBaseController;
use think\Db;
... ... @@ -30,7 +31,7 @@ class NotifyCommonController extends HomeBaseController
$order_model = new OrderModel();
$orderInfo = $order_model->where($where)->find();
if($orderInfo['status'] == 1) {
// $order_model->startTrans();
$order_model->startTrans();
$update = [
'status' => 2,
'pay_type' => $pay_type,
... ... @@ -71,6 +72,12 @@ class NotifyCommonController extends HomeBaseController
if($orderInfo['type'] == 1) {
$order_type = 1;
}
if($orderInfo['type'] == 2) {
$order_type = 2;
}
if($orderInfo['type'] == 3) {
$order_type = 3;
}
$insert = [
'order_id' => $orderInfo['id'],
'user_id' => $user['id'],
... ... @@ -87,8 +94,36 @@ class NotifyCommonController extends HomeBaseController
$order_model->rollback();
return false;
}
// 增加用户推荐人余额
if($user['referee_id'] && ($orderInfo['type'] == 1 || $orderInfo['type'] == 2)) {
$referee_user = $member_model->where(['id'=>$user['referee_id']])->find();
if($referee_user) {
$reward_model = new RewardModel();
$reward_number = $reward_model->where(['type'=>5,'status'=>['neq',9]])->value('number');
$referee_result = $member_model->where(['id'=>$user['referee_id']])->setInc('money',$reward_number);
if(!$referee_result) {
$order_model->rollback();
return false;
}
$insert = [
'user_id' => $user['id'],
'user_type' => $user['type'],
'title' => '推荐人奖励',
'money' => $reward_number,
'order_type' => 7,
'type' => 1,
'pay_type' => 3,
'create_time' => time()
];
$money_detail_insert2 = $money_detail_model->insertGetId($insert);
if(!$money_detail_insert2) {
$order_model->rollback();
return false;
}
}
}
$order_model->commit();
return $orderInfo['type'];
return true;
}
}
... ...
... ... @@ -10,6 +10,7 @@ namespace api\portal\controller;
use api\portal\model\AgencyModel;
use api\portal\model\OrderModel;
use api\portal\model\UserNeedModel;
use cmf\controller\HomeBaseController;
use api\portal\model\PortalPostModel;
... ... @@ -59,7 +60,7 @@ class ThirdsendController extends HomeBaseController
// 查询中介报价(暂未用)
// $need_id 需求id
public function Offer($user_id,$need_id){
public function Offer($user_id,$need_id){
$where_agency['status'] = 2;
$where_agency['create_time'] = array('lt',time());
$where_agency['need_id'] = $need_id;
... ... @@ -83,7 +84,7 @@ class ThirdsendController extends HomeBaseController
foreach ($agency_list as $finalk=>$finalv){
foreach ($money_arr as $monryk=>$moneyv){
if($finalv['true_money'] == $moneyv){
$return[] = $finalv;
$return[] = $finalv;
}
}
}
... ... @@ -184,166 +185,139 @@ class ThirdsendController extends HomeBaseController
// 查询相应报价
$final_time = $userNeedList['pay_time'] + $userNeedList['quotation_time'] * 86400;
// 判断时间是否正确
if ($time >= $final_time) {
if ($time >= $final_time) {
// $us_middleid = $uNeedv['id'];
$where_agency['a.status'] = 2;
$where_agency['a.pay_time'] = array('lt', time());
$where_agency['a.need_id'] = $userNeedList['id'];
$where_agency['m.type'] = 2;
$where_agency['m.status'] = 1;
$agency_list = Db::name('Agency')->alias('a')
->where($where_agency)
->join("hp_Member m", 'm.id = a.agency_id')
->field('a.*,m.company')
->select()->toArray();
$where_agency['a.status'] = 2;
$where_agency['a.pay_time'] = array('lt', time());
$where_agency['a.need_id'] = $userNeedList['id'];
$where_agency['m.type'] = 2;
$where_agency['m.status'] = 1;
$agency_list = Db::name('Agency')->alias('a')
->where($where_agency)
->join("hp_Member m", 'm.id = a.agency_id')
->field('a.*,m.company')
->select()->toArray();
// 查询品牌企业
$where_brand['status'] = 1;
$band_list = Db::name('Brand')->where($where_brand)->column('name');
$agen_arr = array();
if ($agency_list) {
$where_brand['status'] = 1;
$band_list = Db::name('Brand')->where($where_brand)->column('name');
$agen_arr = array();
if ($agency_list) {
// 删除十万以内报价
foreach ($agency_list as $tenk=>$tenv){
$ten_money = $tenv['housing_price'] * 10000 + $tenv['assessment_tax'] + $tenv['security_tax'] + $tenv['else_tax'] + $tenv['service_charge'];
if($ten_money > 1000000){
$is_trueMoney[] = $tenv;
}
foreach ($agency_list as $tenk=>$tenv){
$ten_money = $tenv['housing_price'] * 10000 + $tenv['assessment_tax'] + $tenv['security_tax'] + $tenv['else_tax'] + $tenv['service_charge'];
if($ten_money > 1000000){
$is_trueMoney[] = $tenv;
}
// 判断是否超过三个报价人
if (count($is_trueMoney) >= 3) {
}
// 判断是否超过三个报价人
if (count($is_trueMoney) >= 3) {
// 查询三人中是否有品牌中介
// 循环匹配品牌企业
foreach ($is_trueMoney as $agencyk => $agencyv) {
foreach ($band_list as $brak => $brav) {
foreach ($is_trueMoney as $agencyk => $agencyv) {
foreach ($band_list as $brak => $brav) {
// 判断是否在品牌企业中
if (strstr($brav, $agencyv['company']) !== false) {
if (strstr($brav, $agencyv['company']) !== false) {
// 存在
$agen_money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
if (empty($agen_arr)) {
$agen_money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
if (empty($agen_arr)) {
$agen_arr[0]['money'] = $agen_money;
$agen_arr[0]['id'] = $agencyv['id'];
} else {
// 判断大小
if ($agen_money < $agen_arr[0]['money']) {
$agen_arr[0]['money'] = $agen_money;
$agen_arr[0]['id'] = $agencyv['id'];
} else {
// 判断大小
if ($agen_money < $agen_arr[0]['money']) {
$agen_arr[0]['money'] = $agen_money;
$agen_arr[0]['id'] = $agencyv['id'];
}
}
}
}
// 取出前三报价
$money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
$money_list[$agencyv['id']] = $money;
}
asort($money_list);
$k = 0;
foreach ($money_list as $mok => $mov) {
$else_changeList[] = $mok;
if ($k < 3) {
$fin_list[$k]['id'] = $mok;
$fin_list[$k]['money'] = $mov;
$fin_arr[] = $mok;
}
$k += 1;
// 取出前三报价
$money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
$money_list[$agencyv['id']] = $money;
}
asort($money_list);
$k = 0;
foreach ($money_list as $mok => $mov) {
$else_changeList[] = $mok;
if ($k < 3) {
$fin_list[$k]['id'] = $mok;
$fin_list[$k]['money'] = $mov;
$fin_arr[] = $mok;
}
if($agen_arr){
if(!in_array($agen_arr[0]['id'],$fin_arr)){
$k += 1;
}
if($agen_arr){
if(!in_array($agen_arr[0]['id'],$fin_arr)){
// 品牌中介不在取出三个最低价中
$middle_agen[0] = $agen_arr[0]['id'];
$get_list = array_merge($fin_arr,$middle_agen);
}else{
$get_list = $fin_arr;
}
$middle_agen[0] = $agen_arr[0]['id'];
$get_list = array_merge($fin_arr,$middle_agen);
}else{
$get_list = $fin_arr;
}
foreach ($else_changeList as $getk=>$getv){
if(in_array($getv,$get_list)){
$change_final['id'] = $getv;
$change_final['status'] = 4;
}else{
$change_final['id'] = $getv;
$change_final['status'] = 3;
}
$agencyModel = new AgencyModel();
$fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
if(!$fianl_AgsaveFirst){
Db::rollback();
}
}
foreach ($else_changeList as $getk=>$getv){
if(in_array($getv,$get_list)){
$change_final['id'] = $getv;
$change_final['status'] = 4;
}else{
$change_final['id'] = $getv;
$change_final['status'] = 3;
// 中介报价未进入决赛,执行订单退款
$refund_result = $this->agency_order_refund($getv,'中介报价未进入决赛圈退款');
}
// 报价成功,更改状态
$userSave_statusFirst['id'] = $userNeedList['need_id'];
$userSave_statusFirst['status'] = 5;
$userSave_statusFirst['choose_time'] = time();
$userNeedModel = new UserNeedModel();
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_statusFirst);
if(!$fianl_Ussave){
$agencyModel = new AgencyModel();
$fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
if(!$fianl_AgsaveFirst){
Db::rollback();
}
} else {
}
// 报价成功,更改状态
$userSave_statusFirst['id'] = $userNeedList['need_id'];
$userSave_statusFirst['status'] = 5;
$userSave_statusFirst['choose_time'] = time();
$userNeedModel = new UserNeedModel();
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_statusFirst);
if(!$fianl_Ussave){
Db::rollback();
}
} else {
// 报价小于3人,更改订单状态,报价失败
foreach ($agency_list as $changeka=>$changeva){
$change_final['id'] = $changeva['id'];
$change_final['status'] = 7;
$agencyModel = new AgencyModel();
$fianl_AgsaveNext = $agencyModel->isUpdate(true)->save($change_final);
foreach ($agency_list as $changeka=>$changeva){
$change_final['id'] = $changeva['id'];
$change_final['status'] = 7;
$agencyModel = new AgencyModel();
$fianl_AgsaveNext = $agencyModel->isUpdate(true)->save($change_final);
if(!$fianl_AgsaveNext){
Db::rollback();
}
// 退回中介保证金
$add_a['user_id'] = $changeva['agency_id'];
$add_a['title'] = '报价人数不足';
$add_a['type'] = 1;
$add_a['reason'] = 1;
$add_a['money'] = $changeva['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
// 用户表增加金额
$where_member['type'] = 2;
$where_member['id'] = $changeva['agency_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$changeva['deposit']);
if (!$add_money) {
Db::rollback();
}
}
$userSave_status['id'] = $userNeedList['id'];
$userSave_status['status'] = 4;
$userNeedModel = new UserNeedModel();
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_status);
if(!$fianl_Ussave){
if(!$fianl_AgsaveNext){
Db::rollback();
}
// 中介报价订单退款
$refund_result = $this->agency_order_refund($changeva,'中介报价少于3人退款');
// 退回保证金
// 用户
// 加用户金额明细表
$add_del['need_id'] = $userNeedList['id'];
$add_del['user_id'] = $userNeedList['user_id'];
$add_del['title'] = '报价人数不足';
$add_del['reason'] = 1;
$add_del['type'] = 1;
$add_del['money'] = $userNeedList['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
$where_memberNext['type'] = 1;
$where_memberNext['id'] = $userNeedList['user_id'];
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
if (!$add_moneyNext) {
// 退回中介保证金
// $add_a['user_id'] = $changeva['agency_id'];
// $add_a['title'] = '报价人数不足';
// $add_a['type'] = 1;
// $add_a['reason'] = 1;
// $add_a['money'] = $changeva['deposit'];
// $add_a['create_time'] = time();
// $add_a['update_time'] = time();
// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
// if (!$amoney_id) {
// Db::rollback();
// }
// 用户表增加金额
$where_member['type'] = 2;
$where_member['id'] = $changeva['agency_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$changeva['deposit']);
if (!$add_money) {
Db::rollback();
}
}
} else {
// 没有报价
$userSave_status['id'] = $userNeedList['id'];
$userSave_status['status'] = 4;
$userNeedModel = new UserNeedModel();
... ... @@ -352,39 +326,76 @@ class ThirdsendController extends HomeBaseController
Db::rollback();
}
// 用户需求订单退款
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
// 退回保证金
// 用户
// 加用户金额明细表
$add_del['need_id'] = $userNeedList['id'];
$add_del['user_id'] = $userNeedList['user_id'];
$add_del['title'] = '报价人数不足';
$add_del['type'] = 1;
$add_del['money'] = $userNeedList['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
$this->apiResponse('0','金额明细添加失败');
}
// $add_del['need_id'] = $userNeedList['id'];
// $add_del['user_id'] = $userNeedList['user_id'];
// $add_del['title'] = '报价人数不足';
// $add_del['reason'] = 1;
// $add_del['type'] = 1;
// $add_del['money'] = $userNeedList['pay_money'];
// $add_del['create_time'] = time();
// $add_del['update_time'] = time();
// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
// if (!$umoney_id) {
// Db::rollback();
// }
$where_memberNext['type'] = 1;
$where_memberNext['id'] = $userNeedList['user_id'];
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
if (!$add_moneyNext) {
Db::rollback();
}
}
} else {
// 没有报价
$userSave_status['id'] = $userNeedList['id'];
$userSave_status['status'] = 4;
$userNeedModel = new UserNeedModel();
$fianl_Ussave = $userNeedModel->isUpdate(true)->save($userSave_status);
if(!$fianl_Ussave){
Db::rollback();
}
// 用户需求订单退款
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
// 退回保证金
// 用户
// 加用户金额明细表
// $add_del['need_id'] = $userNeedList['id'];
// $add_del['user_id'] = $userNeedList['user_id'];
// $add_del['title'] = '报价人数不足';
// $add_del['type'] = 1;
// $add_del['money'] = $userNeedList['pay_money'];
// $add_del['create_time'] = time();
// $add_del['update_time'] = time();
// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
// if (!$umoney_id) {
// Db::rollback();
// $this->apiResponse('0','金额明细添加失败');
// }
$where_memberNext['type'] = 1;
$where_memberNext['id'] = $userNeedList['user_id'];
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
if (!$add_moneyNext) {
Db::rollback();
}
}
// 插入数据库
// 用户需求表
// 中介报价表
Db::commit();
$where_return['id'] = $data['need_id'];
$return = Db::name('UserNeed')->where($where_return)->find();
$this->apiResponse('1','成功',$return);
}else{
$this->apiResponse('0','时间不正确');
}
Db::commit();
$where_return['id'] = $data['need_id'];
$return = Db::name('UserNeed')->where($where_return)->find();
$this->apiResponse('1','成功',$return);
}else{
$this->apiResponse('0','时间不正确');
}
// }
}
... ... @@ -413,61 +424,65 @@ class ThirdsendController extends HomeBaseController
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,choose_time,user_id,pay_money,choose_time')->find();
if($userNeedList){
// foreach ($userNeedList as $needk=>$needv) {
if (time() >= ($userNeedList['choose_time'] + 259200)) {
$where_agency['need_id'] = $userNeedList['id'];
$where_agency['status'] = 4;
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
if ($agency_list) {
$where_agencyUpdate['need_id'] = $userNeedList['id'];
$where_agencyUpdate['status'] = 4;
$agency_save['status'] = 8;
$agency_save['update_time'] = time();
$agency_result = Db::name('Agency')->where($where_agencyUpdate)->update($agency_save);
if (!$agency_result) {
Db::rollback();
}
}
$where_needUpdate['id'] = $userNeedList['id'];
$needUpdate['status'] = 6;
$need_result = Db::name('UserNeed')->where($where_needUpdate)->update($needUpdate);
if (!$need_result) {
if (time() >= ($userNeedList['choose_time'] + 259200)) {
$where_agency['need_id'] = $userNeedList['id'];
$where_agency['status'] = 4;
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
if ($agency_list) {
$where_agencyUpdate['need_id'] = $userNeedList['id'];
$where_agencyUpdate['status'] = 4;
$agency_save['status'] = 8;
$agency_save['update_time'] = time();
$agency_result = Db::name('Agency')->where($where_agencyUpdate)->update($agency_save);
if (!$agency_result) {
Db::rollback();
} else {
}
foreach ($agency_list as $agency_key=>$agency_val) {
// 中介报价订单退款
$refund_result = $this->agency_order_refund($agency_val,'用户未选择中标中介退款');
}
}
$where_needUpdate['id'] = $userNeedList['id'];
$needUpdate['status'] = 6;
$need_result = Db::name('UserNeed')->where($where_needUpdate)->update($needUpdate);
if (!$need_result) {
Db::rollback();
} else {
// 加用户金额明细表
$add_del['need_id'] = $userNeedList['id'];
$add_del['user_id'] = $userNeedList['user_id'];
$add_del['title'] = '未选择中介';
$add_del['type'] = 2;
$add_del['money'] = $userNeedList['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
$add_del['need_id'] = $userNeedList['id'];
$add_del['user_id'] = $userNeedList['user_id'];
$add_del['title'] = '未选择中介';
$add_del['type'] = 2;
$add_del['money'] = $userNeedList['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
// 中介金额明细表
foreach ($agency_list as $agenk=>$agenv){
$add_a['ag_id'] = $agenv['id'];
$add_a['user_id'] = $agenv['agency_id'];
$add_a['title'] = '用户未选择中介';
$add_a['type'] = 1;
$add_a['money'] = $agenv['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
$where_member['type'] = 2;
$where_member['id'] = $agenv['agency_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
if (!$add_money) {
Db::rollback();
}
}
// foreach ($agency_list as $agenk=>$agenv){
// $add_a['ag_id'] = $agenv['id'];
// $add_a['user_id'] = $agenv['agency_id'];
// $add_a['title'] = '用户未选择中介';
// $add_a['type'] = 1;
// $add_a['money'] = $agenv['deposit'];
// $add_a['create_time'] = time();
// $add_a['update_time'] = time();
// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
// if (!$amoney_id) {
// Db::rollback();
// }
// $where_member['type'] = 2;
// $where_member['id'] = $agenv['agency_id'];
// $add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
// if (!$add_money) {
// Db::rollback();
// }
// }
}
}
}
// }
Db::commit();
$where_return['id'] = $data['need_id'];
... ... @@ -501,59 +516,59 @@ class ThirdsendController extends HomeBaseController
$need_list = Db::name('UserNeed')->where($where_need)->field('id,choose_time')->find();
if($need_list){
// foreach ($need_list as $needk=>$needv){
if(time() >= ($need_list['choose_time']+259200)){
$where_agency['status'] = 5;
$where_agency['need_id'] = $need_list['id'];
$agency = Db::name('Agency')->where($where_agency)->find();
if(time() >= ($need_list['choose_time']+259200)){
$where_agency['status'] = 5;
$where_agency['need_id'] = $need_list['id'];
$agency = Db::name('Agency')->where($where_agency)->find();
// 修改中介报价状态
if($agency){
$where_changeAgency['id'] = $agency['id'];
$changeAgency['status'] = 10;
$changeAgency['update_time'] = time();
$update_a = Db::name('Agency')->where($where_changeAgency)->update($changeAgency);
if(!$update_a){
Db::rollback();
}
}
// 增加中介保证金变化
$add_a['ag_id'] = $agency['id'];
$add_a['user_id'] = $agency['agency_id'];
$add_a['title'] = '中介未确认';
$add_a['type'] = 2;
$add_a['money'] = $agency['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
if($agency){
$where_changeAgency['id'] = $agency['id'];
$changeAgency['status'] = 10;
$changeAgency['update_time'] = time();
$update_a = Db::name('Agency')->where($where_changeAgency)->update($changeAgency);
if(!$update_a){
Db::rollback();
}
}
// 增加中介保证金变化
$add_a['ag_id'] = $agency['id'];
$add_a['user_id'] = $agency['agency_id'];
$add_a['title'] = '中介未确认';
$add_a['type'] = 2;
$add_a['money'] = $agency['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
// 修改用户需求状态
$where_needChange['id'] = $need_list['id'];
$update_need['status'] = 8;
$update_need['update_time'] = time();
$change_needFinal = Db::name('UserNeed')->where($where_needChange)->update($update_need);
if (!$change_needFinal) {
Db::rollback();
}
$where_needChange['id'] = $need_list['id'];
$update_need['status'] = 8;
$update_need['update_time'] = time();
$change_needFinal = Db::name('UserNeed')->where($where_needChange)->update($update_need);
if (!$change_needFinal) {
Db::rollback();
}
// 增加用户保证金,余额
$add_del['need_id'] = $need_list['id'];
$add_del['user_id'] = $need_list['user_id'];
$add_del['title'] = '中介未确认';
$add_del['type'] = 1;
$add_del['money'] = $need_list['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
$where_member['type'] = 1;
$where_member['id'] = $need_list['user_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$need_list['pay_money']);
if (!$add_money) {
Db::rollback();
}
$add_del['need_id'] = $need_list['id'];
$add_del['user_id'] = $need_list['user_id'];
$add_del['title'] = '中介未确认';
$add_del['type'] = 1;
$add_del['money'] = $need_list['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
$where_member['type'] = 1;
$where_member['id'] = $need_list['user_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$need_list['pay_money']);
if (!$add_money) {
Db::rollback();
}
}
// }
Db::commit();
$where_return['id'] = $data['need_id'];
... ... @@ -569,7 +584,7 @@ class ThirdsendController extends HomeBaseController
// 30分钟后发布(sure)(分钟执行)
public function thirdSend(){
public function thirdSend(){
Db::startTrans();
$where_need['status'] = 2;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,pay_time')->select()->toArray();
... ... @@ -594,7 +609,7 @@ class ThirdsendController extends HomeBaseController
}
// 规定时间结束报价(sure)(分钟执行)
public function over()
public function over()
{
Db::startTrans();
// 查询用户发布需求信息
... ... @@ -813,122 +828,38 @@ class ThirdsendController extends HomeBaseController
}
// 三天用户选择(sure)(天执行)
public function userChoose(){
Db::startTrans();
public function userChoose(){
Db::startTrans();
// 查询用户发布需求信息
$where_need['status'] = 5;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,choose_time,user_id,pay_money,choose_time')->select()->toArray();
if($userNeedList){
foreach ($userNeedList as $needk=>$needv) {
if (time() >= ($needv['choose_time'] + 259200)) {
$where_agency['need_id'] = $needv['id'];
$where_agency['status'] = 4;
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
if ($agency_list) {
$where_agencyUpdate['need_id'] = $needv['id'];
$where_agencyUpdate['status'] = 4;
$agency_save['status'] = 8;
$agency_save['update_time'] = time();
$agency_result = Db::name('Agency')->where($where_agencyUpdate)->update($agency_save);
if (!$agency_result) {
Db::rollback();
}
}
$where_needUpdate['id'] = $needv['id'];
$needUpdate['status'] = 6;
$need_result = Db::name('UserNeed')->where($where_needUpdate)->update($needUpdate);
if (!$need_result) {
Db::rollback();
} else {
// 加用户金额明细表
$add_del['need_id'] = $needv['id'];
$add_del['user_id'] = $needv['user_id'];
$add_del['title'] = '未选择中介';
$add_del['type'] = 2;
$add_del['money'] = $needv['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
// 中介金额明细表
foreach ($agency_list as $agenk=>$agenv){
$add_a['ag_id'] = $agenv['id'];
$add_a['user_id'] = $agenv['agency_id'];
$add_a['title'] = '用户未选择中介';
$add_a['type'] = 1;
$add_a['money'] = $agenv['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
$where_member['type'] = 2;
$where_member['id'] = $agenv['agency_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
if (!$add_money) {
Db::rollback();
}
}
}
}
}
}
Db::commit();
}
// 三天中介确认
public function intermediaryChoose(){
Db::startTrans();
$where_need['status'] = 7;
$need_list = Db::name('UserNeed')->where($where_need)->field('id,choose_time')->select()->toArray();
if($need_list){
foreach ($need_list as $needk=>$needv){
if(time() >= ($needv['choose_time']+259200)){
$where_agency['status'] = 5;
$where_agency['need_id'] = $needv['id'];
$agency = Db::name('Agency')->where($where_agency)->find();
// 修改中介报价状态
if($agency){
$where_changeAgency['id'] = $agency['id'];
$changeAgency['status'] = 10;
$changeAgency['update_time'] = time();
$update_a = Db::name('Agency')->where($where_changeAgency)->update($changeAgency);
if(!$update_a){
Db::rollback();
}
}
// 增加中介保证金变化
$add_a['ag_id'] = $agency['id'];
$add_a['user_id'] = $agency['agency_id'];
$add_a['title'] = '中介未确认';
$add_a['type'] = 2;
$add_a['money'] = $agency['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
// 修改用户需求状态
$where_needChange['id'] = $needv['id'];
$update_need['status'] = 8;
$update_need['update_time'] = time();
$change_needFinal = Db::name('UserNeed')->where($where_needChange)->update($update_need);
if (!$change_needFinal) {
$where_need['status'] = 5;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,choose_time,user_id,pay_money,choose_time')->select()->toArray();
if($userNeedList){
foreach ($userNeedList as $needk=>$needv) {
if (time() >= ($needv['choose_time'] + 259200)) {
$where_agency['need_id'] = $needv['id'];
$where_agency['status'] = 4;
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
if ($agency_list) {
$where_agencyUpdate['need_id'] = $needv['id'];
$where_agencyUpdate['status'] = 4;
$agency_save['status'] = 8;
$agency_save['update_time'] = time();
$agency_result = Db::name('Agency')->where($where_agencyUpdate)->update($agency_save);
if (!$agency_result) {
Db::rollback();
}
// 增加用户保证金,余额
}
$where_needUpdate['id'] = $needv['id'];
$needUpdate['status'] = 6;
$need_result = Db::name('UserNeed')->where($where_needUpdate)->update($needUpdate);
if (!$need_result) {
Db::rollback();
} else {
// 加用户金额明细表
$add_del['need_id'] = $needv['id'];
$add_del['user_id'] = $needv['user_id'];
$add_del['title'] = '中介未确认';
$add_del['type'] = 1;
$add_del['title'] = '未选择中介';
$add_del['type'] = 2;
$add_del['money'] = $needv['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
... ... @@ -936,18 +867,201 @@ class ThirdsendController extends HomeBaseController
if (!$umoney_id) {
Db::rollback();
}
$where_member['type'] = 1;
$where_member['id'] = $needv['user_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$needv['pay_money']);
if (!$add_money) {
// 中介金额明细表
foreach ($agency_list as $agenk=>$agenv){
$add_a['ag_id'] = $agenv['id'];
$add_a['user_id'] = $agenv['agency_id'];
$add_a['title'] = '用户未选择中介';
$add_a['type'] = 1;
$add_a['money'] = $agenv['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
$where_member['type'] = 2;
$where_member['id'] = $agenv['agency_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
if (!$add_money) {
Db::rollback();
}
}
}
}
}
}
Db::commit();
}
// 三天中介确认
public function intermediaryChoose(){
Db::startTrans();
$where_need['status'] = 7;
$need_list = Db::name('UserNeed')->where($where_need)->field('id,choose_time')->select()->toArray();
if($need_list){
foreach ($need_list as $needk=>$needv){
if(time() >= ($needv['choose_time']+259200)){
$where_agency['status'] = 5;
$where_agency['need_id'] = $needv['id'];
$agency = Db::name('Agency')->where($where_agency)->find();
// 修改中介报价状态
if($agency){
$where_changeAgency['id'] = $agency['id'];
$changeAgency['status'] = 10;
$changeAgency['update_time'] = time();
$update_a = Db::name('Agency')->where($where_changeAgency)->update($changeAgency);
if(!$update_a){
Db::rollback();
}
}
// 增加中介保证金变化
$add_a['ag_id'] = $agency['id'];
$add_a['user_id'] = $agency['agency_id'];
$add_a['title'] = '中介未确认';
$add_a['type'] = 2;
$add_a['money'] = $agency['deposit'];
$add_a['create_time'] = time();
$add_a['update_time'] = time();
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
if (!$amoney_id) {
Db::rollback();
}
// 修改用户需求状态
$where_needChange['id'] = $needv['id'];
$update_need['status'] = 8;
$update_need['update_time'] = time();
$change_needFinal = Db::name('UserNeed')->where($where_needChange)->update($update_need);
if (!$change_needFinal) {
Db::rollback();
}
// 增加用户保证金,余额
$add_del['need_id'] = $needv['id'];
$add_del['user_id'] = $needv['user_id'];
$add_del['title'] = '中介未确认';
$add_del['type'] = 1;
$add_del['money'] = $needv['pay_money'];
$add_del['create_time'] = time();
$add_del['update_time'] = time();
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
if (!$umoney_id) {
Db::rollback();
}
$where_member['type'] = 1;
$where_member['id'] = $needv['user_id'];
$add_money = Db::name('Member')->where($where_member)->setInc('money',$needv['pay_money']);
if (!$add_money) {
Db::rollback();
}
}
Db::commit();
}
Db::commit();
}
}
/**
* 需求订单退款
* @param needInfo 用户需求信息
* @param reason 退款原因
*/
private function need_order_refund($needInfo,$reason) {
$order_model = new OrderModel();
$where = [
'user_id' => $needInfo['user_id'],
'type' => 1,
'need_id' => $needInfo['id'],
'is_get' => 2,
'status' => 2
];
// 根据不同订单类型执行退款操作
$orderInfo = $order_model->where($where)->find();
$transaction_id = $orderInfo['transaction_id'];
$order_sn = $orderInfo['order_sn'];
$money = $orderInfo['money'];
$out_refund_no = cmf_get_order_sn();
// 微信
$refund_result = false;
if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
$refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
}
// 支付宝
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
}
return $refund_result;
}
/**
* 中介报价退款
* @param agencyInfo 中介报价信息
* @param reason 退款原因
*/
private function agency_order_refund($agencyInfo,$reason) {
$order_model = new OrderModel();
$where = [
'user_id' => $agencyInfo['agency_id'],
'type' => 2,
'need_id' => $agencyInfo['id'],
'is_get' => 2,
'status' => 2
];
// 根据不同订单类型执行退款操作
$orderInfo = $order_model->where($where)->find();
$transaction_id = $orderInfo['transaction_id'];
$order_sn = $orderInfo['order_sn'];
$money = $orderInfo['money'];
$out_refund_no = cmf_get_order_sn();
$refund_result = false;
// 微信
if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
$refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
}
// 支付宝
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
}
return $refund_result;
}
/**
* 支付宝退款接口(两个订单号不能同时为空)
* @param trade_no 支付宝交易号
* @param out_trade_no 商户支付订单号
* @param refund_amount 退款金额
* @param refund_reason 退款原因
* @param out_request_no 如需部分退款,传此参数
*/
private function alipay_refund($trade_no = null, $out_trade_no = null, $refund_amount, $refund_reason, $out_request_no = null) {
$refund = controller('Alipay','controller');
$data = [
'trade_no' => $trade_no,
'out_trade_no' => $out_trade_no,
'refund_amount' => $refund_amount,
'refund_reason' => $refund_reason,
'out_request_no' => $out_request_no
];
return $refund->refund($data);
}
/**
* 微信退款接口(两个订单号不能同时为空)
* @param transaction_id 微信业务订单号
* @param out_refund_no 商户退款订单号
* @param total_fee 订单金额
* @param refund_fee 退款金额
* @param refund_desc 退款原因
*/
private function wxpay_refund($transaction_id = null, $out_refund_no = null, $total_fee, $refund_fee, $refund_desc) {
require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
$refund = new \WxRefund(Config::get('wx_appid'),Config::get('wx_mch_id'),Config::get('wx_key'),$transaction_id,
$out_refund_no,$total_fee,$refund_fee,$refund_desc);
return $refund->pay();
}
... ...
... ... @@ -79,6 +79,7 @@ class UserController extends CommonController
* @method POST
* @param name:tel type:int require:1 default: other: desc:手机号
* @param name:imgCode type:int require:1 default: other:genre=2时传 desc:图片验证码
* @param name:rand type:int require:1 default: other: desc:随机数
* @param name:genre type:int require:1 default: other: desc:类型(1->用户注册/中介注册,2->密码找回,3->发布需求,4->修改手机号,5->绑定银行卡)
* @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
*/
... ... @@ -108,7 +109,7 @@ class UserController extends CommonController
}else if($genre == 2 ){
// 验证图形验证码
// 验证码
session_start();
// session_start();
if(empty($data['imgCode'])){
$this->apiResponse('0','请先输入图形验证码');
}
... ... @@ -588,7 +589,7 @@ class UserController extends CommonController
* @param name:code type:int require:1 default: other: desc:短信验证码
* @param name:newPassword type:int require:1 default: other: desc:新密码
* @param name:sureNewPassword type:int require:1 default: other: desc:确认新密码
* @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:2
* @param name:connect type:int require:1 default: other:1 登录注册 ,2其他 desc:1
*/
public function findPassword(Request $request){
$data = $request->param();
... ...
... ... @@ -229,5 +229,9 @@ $configs = [
'cmf_default_theme' => 'simpleboot3',
'cmf_admin_theme_path' => 'themes/',
'cmf_admin_default_theme' => 'admin_simpleboot3',
'wx_appid' => 'wxf69d1d87d173c899',
'wx_appsecret' => '93c020c51020d87bda1c0bd98b527ff5',
'wx_mch_id' => '1507884301',
'wx_key' => 'VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI',
];
return array_merge($configs, $runtimeConfig);
\ No newline at end of file
... ...
... ... @@ -28,16 +28,19 @@ class IndexController extends CommonController
{
public function index()
{
$return = $this->wxpay(['order_sn'=>201807211032],'保证金支付');
// $return = $this->wxpay(['order_sn'=>201807211101],'保证金支付');
// $qrcode_url = url('portal/Index/qrcode',['data'=>urlencode($return['code_url'])],true,true);
// echo '<img src="'.$qrcode_url.'" alt=""/>';
$back = [
'return'=>$return,
// $back = [
// 'return'=>$return,
// 'code_url'=>base64_encode($return['code_url']),
// 'qrcode'=> '<img src="'.$qrcode_url.'" alt=""/>',
'alipay_url'=>url('portal/Alipay/alipay',array('order_sn'=>201807211032,'name'=>'保证金支付','price'=>0.01))
];
$this->redirect($back['alipay_url']);
// 'alipay_url'=>url('portal/Alipay/alipay',array('order_sn'=>201807211101,'name'=>'保证金支付','price'=>0.01))
// ];
// $this->redirect($back['alipay_url']);
$alipay_url = url('portal/Alipay/refund',array('trade_no'=>'2018072421001004410576233593','refund_amount'=>0.01,'refund_reason'=>'中介报价少于3人退款'));
$this->redirect($alipay_url);
// echo "<pre/>";
// print_r('7777');
... ... @@ -81,13 +84,15 @@ class IndexController extends CommonController
// 微信h5支付(测试)
public function wxpayh5() {
require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
$h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','YkeE7j21vdwqnBYW8FM2Z11O9T4v1kH0','201807211100',
'保证金支付','1','','保证金支付');
$h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','201807211465',
'保证金支付','1','{"h5_info": {"type":"Wap","wap_url": "http://houseprice.w.bronet.cn","wap_name": "保证金支付"}}' );
$result = $h5->pay();
var_dump($result);
$mweb_url = '';
if(!empty($result['mweb_url'])) {
$this->assign('mwen_url',$result['mweb_url']);
$mweb_url = $result['mweb_url'];
}
$this->assign('mwen_url',$mweb_url);
return $this->fetch(':h5');
}
... ... @@ -114,7 +119,7 @@ class IndexController extends CommonController
require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
// $h5 = new \WxpayH5(config('APP_ID'),config('MCH_ID'),config('WXPAY_KEY'),$data['order_sn'],
// $type[$data['_type']],'1',$scene_info);
$h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','YkeE7j21vdwqnBYW8FM2Z11O9T4v1kH0',$data['order_sn'],
$h5 = new \WxpayH5('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI',$data['order_sn'],
$type[$data['_type']],'1',$scene_info);
$result = $h5->pay();
if(empty($result['mweb_url'])) {
... ... @@ -129,6 +134,15 @@ class IndexController extends CommonController
}
}
// 微信退款(测试)
public function wxrefund() {
require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
$refund = new \WxRefund('wxf69d1d87d173c899','1507884301','VaY3CqbFLbq2Dw3FRENrixu24E9Qq1ZI','4200000146201807232084354569',
'201807250936','1','1','中介报价少于3人退款');
$result = $refund->pay();
var_dump($result);
}
public function callback() {
echo 111;
}
... ...
... ... @@ -9,6 +9,7 @@
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\UserNeedModel;
use cmf\controller\AdminBaseController;
use app\portal\model\NeedAnswerModel;
use app\portal\model\MemberModel;
... ... @@ -28,9 +29,9 @@ class NeedController extends AdminBaseController
// 列表
public function index(Request $request)
{
// $where_coo['status'] = 1;
$where_coo['n.status'] = array('neq',9);
// $where_coo['type'] = 2;
$where_coo = array();
// $where_coo = array();
if($request->post()){
$search = $request->post();
if($search['start_time']){
... ... @@ -82,52 +83,64 @@ class NeedController extends AdminBaseController
// 修改信息
public function change(Request $request)
{
if($request->post()){
// 添加数据
$data = $request->post();
if($request->Post('id')){
// 修改
$add['content'] = $data['content'];
$add['title'] = $data['title'];
$add['score'] = $data['score'];
$add['type'] = 2;
$validate = Loader::validate('NeedAnswer');
if(!$validate->scene('edit')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$add['id'] = $request->param('id');
$model = new NeedAnswerModel();
$final = $model->isUpdate(true)->allowField(true)->save($add);
}else{
// 添加
$add['content'] = $data['content'];
$add['title'] = $data['title'];
$add['score'] = $data['score'];
$add['type'] = 2;
$validate = Loader::validate('NeedAnswer');
if(!$validate->scene('add')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$model = new NeedAnswerModel();
$final = $model->save($add);
}
if($final){
$this->success('成功',url('index'));
$data = $request->Post();
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$where_area['area_name'] = array('like',"%$city%");
$city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
$where_money['city'] = array('like',"%".$city_id['area_id'].'%');
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if(!$money){
$where_elsemoney['city'] = 0;
$where_elsemoney['status'] = 1;
$where_elsemoney['low_area'] = array('lt',$area);
$where_elsemoney['height_area'] = array('egt',$area);
$elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
if($elsemoney){
$data['pay_money'] = $elsemoney['money'];
}else{
$this->error('失败');
$this->error('保证金获取失败');
}
}else{
$where_find['type'] = $request->param('id');
$list = Db::name('NeedAnswer')->where($where_find)->find();
if($list){
$list['content'] = htmlspecialchars_decode($list['content']);
$data['pay_money'] = $money['money'];
}
$model = new UserNeedModel();
// 修改
$where_need['id'] = $request->param('id');
$where_need['status'] = array('neq',9);
$need = Db::name('UserNeed')->where($where_need)->find();
$data['user_id'] = $need['user_id'];
if(!$need){
$this->error('该需求不可修改');
}else{
// $data['id'] = $data['need_id'];
if($need['status'] == 2){
unset($data['pay_money']);
}
$this->assign('list',$list);
return $this->fetch('add');
$data['create_time'] = strtotime($data['create_time']);
$data['update_time'] = strtotime($data['update_time']);
$data['pay_time'] = strtotime($data['pay_time']);
$data['choose_time'] = strtotime($data['choose_time']);
$save = $model->isUpdate(true)->allowField(true)->save($data);
}
if($save){
$final['need_id'] = $model->id;
$this->success('修改成功',url('Need/index'));
}else{
$this->error('修改失败');
}
}
... ... @@ -143,7 +156,7 @@ class NeedController extends AdminBaseController
$this->error('删除失败');
}
$add_del['status'] = 9;
$model = new NeedAnswerModel();
$model = new UserNeedModel();
$del = $model->isUpdate(true)->allowField(true)->save($add_del);
if($del){
$this->success('删除成功',url('index'));
... ...
... ... @@ -3,8 +3,7 @@
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href=" ">保证金说明列表</a></li>
<li><a href="{:url('Need/add')}">添加保证金说明</a></li>
<li class="active"><a href=" ">需求列表</a></li>
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('Need/index')}">
<!--分类:-->
... ... @@ -27,35 +26,6 @@
</form>
<form class="js-ajax-form" action="" method="post">
<div class="table-actions">
<!--<notempty name="category">-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/listOrder')}">{:lang('SORT')}-->
<!--</button>-->
<!--</notempty>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/publish',array('yes'=>1))}" data-subcheck="true">发布-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/publish',array('no'=>1))}" data-subcheck="true">取消发布-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/top',array('yes'=>1))}" data-subcheck="true">置顶-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/top',array('no'=>1))}" data-subcheck="true">取消置顶-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/recommend',array('yes'=>1))}" data-subcheck="true">推荐-->
<!--</button>-->
<!--<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"-->
<!--data-action="{:url('AdminArticle/recommend',array('no'=>1))}" data-subcheck="true">取消推荐-->
<!--</button>-->
<!--
<notempty name="category">
<button class="btn btn-primary btn-sm js-articles-move" type="button">批量移动</button>
</notempty>
<button class="btn btn-primary btn-sm js-articles-copy" type="button">批量复制</button>
-->
<button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
data-action="{:url('Need/del')}" data-subcheck="true" data-msg="您确定删除吗?">
{:lang('DELETE')}
... ... @@ -84,6 +54,7 @@
<th>状态</th>
<th>提交时间</th>
<th>操作</th>
<th>操作</th>
</tr>
</thead>
<foreach name="list" item="list">
... ...
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/7/21
* Time: 11:39
*/
/*
* 微信退款
*/
class WxRefund {
protected $appid;
protected $mch_id;
protected $key;
protected $transaction_id;
protected $out_refund_no;
protected $total_fee;
protected $refund_fee;
protected $refund_desc;
function __construct($appid, $mch_id, $key, $transaction_id, $out_refund_no, $total_fee, $refund_fee, $refund_desc) {
$this->appid = $appid;
$this->mch_id = $mch_id;
$this->key = $key;
$this->transaction_id = $transaction_id;
$this->out_refund_no = $out_refund_no;
$this->total_fee = $total_fee;
$this->refund_fee = $refund_fee;
$this->refund_desc = $refund_desc;
}
public function pay() {
//微信退款
$return = $this->weixinrefund();
return $return;
}
//退款接口
private function refund() {
$url = 'https://api.mch.weixin.qq.com/secapi/pay/refund';
$parameters = array(
'appid' => $this->appid, //appID
'mch_id' => $this->mch_id, //商户号
'nonce_str' => $this->createNoncestr(), //随机字符串
'transaction_id' => $this->transaction_id,
// 'out_trade_no' => '2015450806125348', //商户订单号
'out_refund_no'=> $this->out_refund_no,
// 'total_fee' => floatval(0.01 * 100), //总金额 单位 分
'total_fee' => $this->total_fee,
'refund_fee' => $this->refund_fee,
'notify_url' => url('portal/Notify/notify', '', '', true), //通知地址 确保外网能正常访问
'refund_desc' => $this->refund_desc
);
//统一下单签名
$parameters['sign'] = $this->getSign($parameters);
$xmlData = $this->arrayToXmlT($parameters);
$return = $this->xmlToArray($this->postXmlCurl($xmlData, $url, 60,1));
return $return;
}
private static function postXmlCurl($xml, $url, $second = 30,$pem = null)
{
$ch = curl_init();
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
if($pem) {
//以下是证书相关代码
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT,VENDOR_PATH.'WxpayAPI/cert/apiclient_cert.pem');//绝对路径
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY,VENDOR_PATH.'WxpayAPI/cert/apiclient_key.pem');//绝对路径
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
set_time_limit(0);
//运行curl
$data = curl_exec($ch);
//返回结果
if ($data) {
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
curl_close($ch);
return $error;
// throw new WxPayException("curl出错,错误码:$error");
}
}
//数组转换成xml
private function arrayToXml($arr) {
$xml = "<root>";
foreach ($arr as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . arrayToXml($val) . "</" . $key . ">";
} else {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
}
}
$xml .= "</root>";
return $xml;
}
//数组转换成xml
private function arrayToXmlT($arr) {
$xml = "<xml>";
foreach ($arr as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . arrayToXmlT($val) . "</" . $key . ">";
} else {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
}
}
$xml .= "</xml>";
return $xml;
}
//xml转换成数组
private function xmlToArray($xml) {
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring), true);
return $val;
}
//微信接口
private function weixinrefund() {
//退款接口
$refund = $this->refund();
return $refund;
// print_r($unifiedorder);
$parameters = array(
'appId' => $this->appid, //小程序ID
'timeStamp' => '' . time() . '', //时间戳
'nonceStr' => $this->createNoncestr(), //随机串
'package' => 'prepay_id=' . $refund['prepay_id'], //数据包
'signType' => 'MD5'//签名方式
);
//签名
$parameters['paySign'] = $this->getSign($parameters);
return $parameters;
}
//作用:产生随机字符串,不长于32位
private function createNoncestr($length = 32) {
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
//作用:生成签名
private function getSign($Obj) {
foreach ($Obj as $k => $v) {
$Parameters[$k] = $v;
}
//签名步骤一:按字典序排序参数
ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false);
//签名步骤二:在string后加入KEY
$String = $String . "&key=" . $this->key;
//签名步骤三:MD5加密
$String = md5($String);
//签名步骤四:所有字符转为大写
$result_ = strtoupper($String);
return $result_;
}
///作用:格式化参数,签名过程需要使用
private function formatBizQueryParaMap($paraMap, $urlencode) {
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v) {
if ($urlencode) {
$v = urlencode($v);
}
$buff .= $k . "=" . $v . "&";
}
$reqPar = "";
if (strlen($buff) > 0) {
$reqPar = substr($buff, 0, strlen($buff) - 1);
}
return $reqPar;
}
}
... ...
... ... @@ -19,7 +19,6 @@ class WxpayH5 {
protected $body;
protected $total_fee;
protected $scene_info;
protected $type;
function __construct($appid, $mch_id, $key,$out_trade_no,$body,$total_fee,$scene_info) {
$this->appid = $appid;
$this->mch_id = $mch_id;
... ... @@ -32,17 +31,17 @@ class WxpayH5 {
public function pay() {
//统一下单接口
//H5支付接口
$return = $this->weixinapp();
return $return;
}
//统一下单接口
//H5支付接口
private function unifiedorder() {
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
$parameters = array(
'appid' => $this->appid, //小程序ID
'appid' => $this->appid, //appID
'mch_id' => $this->mch_id, //商户号
'nonce_str' => $this->createNoncestr(), //随机字符串
// 'body' => 'test', //商品描述
... ... @@ -154,14 +153,14 @@ class WxpayH5 {
}
//微信小程序接口
//H5支付接口
private function weixinapp() {
//统一下单接口
//H5支付接口
$unifiedorder = $this->unifiedorder();
return $unifiedorder;
// print_r($unifiedorder);
$parameters = array(
'appId' => $this->appid, //小程序ID
'appId' => $this->appid, //appID
'timeStamp' => '' . time() . '', //时间戳
'nonceStr' => $this->createNoncestr(), //随机串
'package' => 'prepay_id=' . $unifiedorder['prepay_id'], //数据包
... ...