From a3942f41d92aaaeb7447b075c5267c9d2c4759f6 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Wed, 8 Dec 2021 16:35:05 +0800 Subject: [PATCH] edit-admin-add_pay_log --- admin/controllers/receiver/Orders.php | 68 +++++++++++++++----- admin/views/receiver/orders/add_paylog.php | 12 ++++ admin/views/receiver/orders/paylog.php | 8 --- common/services/apporder/Payment_service.php | 7 +- 4 files changed, 71 insertions(+), 24 deletions(-) diff --git a/admin/controllers/receiver/Orders.php b/admin/controllers/receiver/Orders.php index 2ced9e24..1593516f 100644 --- a/admin/controllers/receiver/Orders.php +++ b/admin/controllers/receiver/Orders.php @@ -638,7 +638,7 @@ class Orders extends HD_Controller $where = [ 'o_id' => $oid, 'status' => 1, - 'pay_price!=' => 0 + 'pay_price>' => 0 ]; $sum = $this->app_liche_orders_model->sum('total_price', $where); //已收金额 $need_price = $this->orders_entity->recevable_price($oid); //应收金额 @@ -756,32 +756,29 @@ class Orders extends HD_Controller $p_row = $this->app_liche_orders_model->get(['o_id'=>$params['id'],'pid'=>0],'id'); $where = [ 'o_id' => $params['id'], - 'status>=' => 0, - '((pid>0 and type!=5) or (pid=0 and type=5))' => null + 'status' => 1, + 'pay_price>' => 0 ]; $count = $this->app_liche_orders_model->count($where); if ($count) { - $rows = $this->app_liche_orders_model->select($where, 'type asc', $page, $size, 'id,total_price,type,pay_time,mch_id,descrip,status,pid'); + $rows = $this->app_liche_orders_model->select($where, 'id desc', $page, $size, 'id,total_price,type,pay_time,mch_id,descrip,status,pid'); $type_arr = $this->app_liche_orders_model->get_type_arr(); foreach ($rows as $item) { $company = ''; if ($item['mch_id']) { $company = $this->sys_company_model->get(['wx_mchid' => $item['mch_id']], 'short'); } - $type_cn = $item['type']==3 && $item['pid']==$p_row['id'] ? '尾款-主订单' : $type_arr[$item['type']]; $list[] = [ 'id'=> $item['id'], 'money' => $item['total_price'], - 'type_cn' => $type_cn, + 'type_cn' => $type_arr[$item['type']], 'pay_time' => $item['pay_time'], - 'status' => $item['status'], 'company' => $company ? $company['short'] : '', 'descrip' => $item['descrip'], - 'status_cn' => $item['status'] ? '已支付' : '未支付', ]; } } - $sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$params['id'],'status'=>1,'pay_price!='=>0]); + $sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$params['id'],'status'=>1,'pay_price>'=>0]); $this->data['pay_price'] = $sum['total_price']; $this->data['need_price'] = $this->orders_entity->recevable_price($params['id']); $this->data['list'] = $list; @@ -796,21 +793,26 @@ class Orders extends HD_Controller //添加支付日志 public function add_paylog() { + $id = $this->input->get_post('id'); + $row = $this->orders_model->get(['id' => $id]); + $srv_price = $this->orders_entity->order_srv_money($row['id']); if ($this->input->method() == 'post') { - $id = $this->input->post('id'); - $row = $this->orders_model->get(['id' => $id]); $money = $this->input->post('money'); $pay_time = $this->input->post('pay_time'); $wx_mchid = $this->input->post('wx_mchid'); $descrip = $this->input->post('descrip'); + $type = $this->input->post('type'); if (!$money || !$pay_time || !$row || !$wx_mchid) { return $this->show_json(SYS_CODE_FAIL, '参数错误'); } + $p_row = $this->app_liche_orders_model->get(['pid'=>0,'o_id'=>$row['id']]); $this->load->helper('order'); - $sid = create_order_no(350200, 'liche', 1, 5); + $sid = create_order_no(350200, 'liche', 1, $type); $data = [ 'o_id' => $row['id'], 'sid' => $sid, + 'uid' => $p_row['uid'], + 'entrust_uid' => $p_row['entrust_uid'], 'mch_id' => $wx_mchid, 'brand_id' => $row['brand_id'], 's_id' => $row['s_id'], @@ -819,19 +821,55 @@ class Orders extends HD_Controller 'incor_id' => $row['incor_id'], 'total_price' => $money, 'pay_price' => $money, - 'type' => 5, - 'status' => 1, - 'pay_time' => date('Y-m-d H:i:s', strtotime($pay_time)), + 'type' => $type, + 'status' => 0, 'c_time' => time() ]; $descrip && $data['descrip'] = $descrip; + if($type==1){ //定金 + $data['pid'] = $p_row['id']; + $this->app_liche_orders_model->update(['status'=>-1],['type'=>1,'status'=>0,'o_id'=>$row['id']]); + }elseif($type==2){ //服务费 + if(!$srv_price){ + return $this->show_json(SYS_CODE_FAIL, '该订单不需要支付服务费'); + } + $this->app_liche_orders_model->update(['status'=>-1],['type'=>2,'status'=>0,'o_id'=>$row['id']]); + $data['pid'] = $p_row['id']; + }elseif($type==3){ //尾款 + $last_p_row = $this->app_liche_orders_model->get(['type'=>3,'pid'=>$p_row['id']]); + if(!$last_p_row){ + return $this->show_json(SYS_CODE_FAIL, '该订单未到支付尾款阶段'); + } + $data['pid'] = $last_p_row['id']; + $this->app_liche_orders_model->update(['status'=>-1],['type'=>3,'status'=>0,'o_id'=>$row['id'],'pid'=>$last_p_row['id']]); + //获取已支付尾款 + $pay_sum = $this->app_liche_orders_model->sum('pay_price',['type'=>3,'status'=>1,'o_id'=>$row['id'],'pid'=>$last_p_row['id']]); + if($pay_sum['pay_price']+$money>$last_p_row['total_price']){ + return $this->show_json(SYS_CODE_FAIL, '请输入正确尾款金额'); + } + }else{ + return $this->show_json(SYS_CODE_FAIL, '请选择正确订单类型'); + } $res = $this->app_liche_orders_model->add($data); if (!$res) { return $this->show_json(SYS_CODE_FAIL, '保存失败'); } + $this->load->service('apporder/payment_service', array('app_id' => 1)); + $result = $this->payment_service->after_pay_liche($sid,$money,'',$pay_time); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } + $ck_row = $this->order_ckcars_model->get(['o_id'=>$id]); + $sign_row = $this->order_signs_model->get(['o_id'=>$id]); $companys = $this->sys_company_model->select(['status' => 1, 'wx_mchid!=' => ''], 'id desc', '', '', 'id,wx_mchid,short'); + $type = []; + if(!$row['status'] && $sign_row['status']==1){ + $type[] = ['id'=>1,'name'=>'定金']; + } + if($row['status']==2 && $ck_row['status']==2){ + $srv_price >0 && $type[] = ['id'=>2,'name'=>'服务费']; + $type[] = ['id'=>3,'name'=>'尾款']; + } + $this->data['type'] = $type; $this->data['companys'] = $companys; $this->data['id'] = $this->input->get('id'); return $this->show_view('receiver/orders/add_paylog'); diff --git a/admin/views/receiver/orders/add_paylog.php b/admin/views/receiver/orders/add_paylog.php index 0e5475f2..7c2299d0 100644 --- a/admin/views/receiver/orders/add_paylog.php +++ b/admin/views/receiver/orders/add_paylog.php @@ -8,6 +8,18 @@ +
+ +
+ +
+
+
diff --git a/admin/views/receiver/orders/paylog.php b/admin/views/receiver/orders/paylog.php index 0c0cfd01..93bfd5cc 100644 --- a/admin/views/receiver/orders/paylog.php +++ b/admin/views/receiver/orders/paylog.php @@ -11,8 +11,6 @@ 收款公司 备注 付款时间 - 支付状态 - 操作 @@ -22,12 +20,6 @@ {{item.company}} {{item.descrip}} {{item.pay_time}} - {{item.status_cn}} - - - diff --git a/common/services/apporder/Payment_service.php b/common/services/apporder/Payment_service.php index fece920c..f2a4b649 100644 --- a/common/services/apporder/Payment_service.php +++ b/common/services/apporder/Payment_service.php @@ -130,8 +130,9 @@ class Payment_service extends HD_Service{ * @param string $sid * @param float $pay_price 订单真实支付金额 * @param string $descrip 订单描述 + * @param date $pay_time 支付时间 */ - public function after_pay_liche($sid,$pay_price = '',$descrip=''){ + public function after_pay_liche($sid,$pay_price = '',$descrip='',$pay_time=''){ if($sid){ debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file); $order = $this->app_liche_orders_model->get(array('sid'=>$sid)); @@ -148,6 +149,7 @@ class Payment_service extends HD_Service{ $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); $pay_price && $upd['pay_price'] = $pay_price; $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); if($res) { //更新订单状态 @@ -184,6 +186,7 @@ class Payment_service extends HD_Service{ $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); $pay_price && $upd['pay_price'] = $pay_price; $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); if($res){ return array('code'=>1,'msg'=>'操作成功'); @@ -195,6 +198,7 @@ class Payment_service extends HD_Service{ $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); $pay_price && $upd['pay_price'] = $pay_price; $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); if($res){ //判断是否尾款支付完成 @@ -221,6 +225,7 @@ class Payment_service extends HD_Service{ $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); $pay_price && $upd['pay_price'] = $pay_price; $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); if($res) { //更新订单下定时间