Commit cf7575fb authored by 蔡闯's avatar 蔡闯

订单接口

parent ddea9757
......@@ -30,31 +30,41 @@ class Payorder extends Base
$vacancys[$k]['vacancy_address'] = $res['vacancy_address'];
foreach ($convertArr as $key=>$value) {
$where['type'] = $key;
//总金额
$data= Db::name('cost')->where($where)->sum('pay_money');
$time = Db::name('cost')->where($where)->order('create_time','desc')->value('create_time');
if(!$data) {
$dataInfo = Db::name('cost')->where($where)->order('create_time','desc')->field('cost_id,pay_money,create_time')->select()->toArray();
if(!$dataInfo) {
continue;
}
$rest['money'] = $data;
$total = 0;
$costIds=[];
foreach ($dataInfo as $ke =>$va) {
$total+=$va['pay_money'];
$costIds[]=$va['cost_id'];
}
//总金额
$rest['money'] =$total;
$rest['type'] = $key;
$rest['type_zh'] = $convertArr[$key];
$rest['create_time'] = $time;
$rest['create_time'] = $dataInfo[0]['create_time']; //最近的账单生成的时间
$rest['cost_ids'] = $costIds;
$vacancys[$k]['pay_list'][] = Common::changeField($rest);;
}
//获取自定义的
unset($where['type']);
$money = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->sum('pay_money');
$time = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->order('create_time','desc')->value('create_time');
if($money){
$rest_other['money'] = $money;
$dataInfo = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->order('create_time','desc')->field('cost_id,pay_money,create_time')->select()->toArray();
if(!$dataInfo) {
continue;
}
$total = 0;
$costIds=[];
foreach ($dataInfo as $ke =>$va) {
$total+=$va['pay_money'];
$costIds[]=$va['cost_id'];
}
$rest_other['money'] = $total;
$rest_other['type'] = "other";
$rest_other['type_zh'] = "自定义";
$rest_other['create_time'] = $time;
}
$rest_other['create_time'] = $dataInfo[0]['create_time']; //最近的账单生成的时间
$rest_other['cost_ids'] = $costIds;
$vacancys[$k]['pay_list'][] = Common::changeField($rest_other);
}
} else {
......@@ -159,6 +169,7 @@ class Payorder extends Base
}
//某个房间下的某个收费项的未缴费缴费列表
//具体房间未缴费列表
public function vacancyPayList() {
$vacancy_id = Request::param('vacancy_id');
$type = Request::param('type'); //property|water|electric|gas|park|other,除了other,其他都能对应表中的type
......@@ -174,7 +185,7 @@ class Payorder extends Base
$where[] = ['is_pay','=',0];
//查询该房间的服务结束时间
$property_end_time = Db::name('house_user_vacancy')->where(['vacancy_id'=>$vacancy_id])->value('property_end_time');
$property_end_time = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->value('property_end_time');
if($property_end_time){
$where[] = ['cost_month','>',$property_end_time];
} else {
......@@ -187,7 +198,7 @@ class Payorder extends Base
return $this->returnJson([],'查询错误!',400);
}
$data = Db::name('cost')->where($where)->page($page,config('app.limit'))->order('cost_month','desc')->field('cost_id,cost_month,pay_money,type')->select()->toArray();
$data = Db::name('cost')->where($where)->page($page,config('app.limit'))->order('cost_month','asc')->field('cost_id,cost_month,pay_money,type')->select()->toArray();
$total = Db::name('cost')->where($where)->count();
$res['total'] = $total;
$res['data'] = $data;
......@@ -240,13 +251,24 @@ class Payorder extends Base
$where['type'] = 'property';
$where['is_pay'] = 0;
$where['vacancy_id'] = $vacancy_id;
$property_cost_ids = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id
//获取房间的物业服务时间,
$property_end_time = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->value('property_end_time');
if($property_end_time) {
$whereOne[] = ['cost_month','>',$property_end_time];
} else {
$whereOne = [];
}
$property_cost_ids = Db::name('cost')->where($where)->where($whereOne)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id
//如果物业费选择了,则判断
if($property_cost_ids) {
$limit = count($property_cost_ids);
$cost_property_ids = Db::name('cost')->where($where)->limit($limit)->column('cost_id');
$cost_property_ids = Db::name('cost')->where($where)->where($whereOne)->limit($limit)->column('cost_id');
if($cost_property_ids != $property_cost_ids) {
return $this->returnJson([],'物业费缴费必须连续!');
}
return $this->returnJson([],'物业费缴费必须连续!',400);
}
}
$total_money = Request::param('total_money',0);
//判断金额是否一致
unset($where['type']);
......@@ -268,7 +290,6 @@ class Payorder extends Base
if($res['code'] !=200){
return $this->returnJson([],$res['data'],400);
}
$data['property_id'] =$res['data']['property_id'];
$data['village_id'] =$res['data']['village_id'];
$data['bind_id'] = $bind_id;
......@@ -280,6 +301,8 @@ class Payorder extends Base
if($order_id) {
unset($res);
$res['order_id'] = $order_id;
//cost表中关联order_id
Db::name('cost')->whereIn('cost_id',$cost_ids)->save(['order_id'=>$order_id]);
return $this->returnJson($res);
} else{
return $this->returnJson([],'添加失败!',400);
......@@ -314,12 +337,7 @@ class Payorder extends Base
$param['subject'] = $orderInfo['order_name'];
$param['total_amount'] = floatval($orderInfo['money']);
$res= $this->getAliPaySign($param);
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"支付宝"]);
$cost_ids = json_encode($orderInfo['cost_ids']);
Db::name('pay_order')->whereIn('cost_id',$cost_ids)->save(['order_id'=>$order_id]);
//微信支付
} else {
$param['order_id'] = $orderInfo['order_id'];
......@@ -330,9 +348,7 @@ class Payorder extends Base
//更改订单的支付方式
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"微信"]);
}
//修改cost表
$cost_ids = json_encode($orderInfo['cost_ids']);
Db::name('pay_order')->whereIn('cost_id',$cost_ids)->save(['order_id'=>$order_id]);
return $this->returnJson($res);
} else {
return $this->returnJson([],'非法的订单信息!',400);
......@@ -365,7 +381,6 @@ class Payorder extends Base
public function getWeiXinPaySign($param) {
require_once "../extend/weixin/Weixin.php";
$configArr = config('app.weixinPay');
$configArr['notifyurl'] = config('app.notifyurl');
$weixin = new \Weixin($param,$configArr);
return $weixin->pay();
}
......
......@@ -11,6 +11,7 @@ class Payreturn extends BaseController
{
//支付宝支付成功后的异步通知地址
public function aliPayReturn() {
require_once "../extend/aliPay/AopClient.php";
//生成日志
$this->createPayLog($_POST,"支付宝");
......@@ -51,7 +52,7 @@ class Payreturn extends BaseController
private function changePayStatus($out_trade_no) {
$where['order_num'] = $out_trade_no;
$save['pay_time'] = time();
$save['paid'] = 1;
$save['is_pay'] = 1;
$cost_ids = DB::name('pay_order')->where(['order_num'=>$out_trade_no])->value('cost_ids');
$cost_ids_arr = json_decode($cost_ids);
Db::startTrans();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment