|
|
@@ -13,7 +13,9 @@ use app\common\model\goods\Goods;
|
|
|
use app\common\model\master_worker\MasterWorker;
|
|
|
use app\common\model\orders\RechargeOrder;
|
|
|
use app\common\model\recharge\OrderGoods;
|
|
|
+use app\common\model\spare_part\SparePart;
|
|
|
use app\common\model\works\ServiceWork;
|
|
|
+use app\common\model\works\ServiceWorkSpare;
|
|
|
use app\workerapi\logic\ServiceWorkLogLogic;
|
|
|
use think\Exception;
|
|
|
use think\facade\Db;
|
|
|
@@ -311,7 +313,7 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
$order_info = \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
|
|
|
$query->visible(['goods_name','goods_image','goods_number','good_unit']);
|
|
|
},'service_work'=>function ($query) {
|
|
|
- $query->visible(['real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','finished_images','finished_time'])->append(['service_status_text','user_service_status','user_service_status_text']);
|
|
|
+ $query->visible(['real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','finished_images','finished_time','spare_total','service_work_spare_id'])->append(['service_status_text','user_service_status','user_service_status_text']);
|
|
|
}])
|
|
|
->visible(['id','sn','payment_type','order_total','order_amount','paid_amount','pay_status','create_time','title','work_id'])
|
|
|
->where([
|
|
|
@@ -320,6 +322,9 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
'sn'=>$params['sn']
|
|
|
])->findOrEmpty()->toArray();
|
|
|
|
|
|
+ if(empty($order_info)){
|
|
|
+ throw new Exception('订单不存在');
|
|
|
+ }
|
|
|
|
|
|
$order_info['master_worker'] = [
|
|
|
'avatar' => '',
|
|
|
@@ -329,9 +334,7 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
'worker_exp'=>''
|
|
|
];
|
|
|
|
|
|
- if(empty($order_info)){
|
|
|
- throw new Exception('订单不存在');
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
//查询总价
|
|
|
$order_info['order_amount'] = \app\common\model\recharge\RechargeOrder::where(['order_type'=>0,'user_id'=>$params['user_id'],'work_id'=>$order_info['work_id']])->sum('order_amount');
|
|
|
@@ -348,7 +351,7 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
$order_info['master_worker']['worker_exp'] = DictData::where(['type_value'=>'worker_exp_type','value'=>$maintain_exp_type])->value('name');
|
|
|
}
|
|
|
//搜索当前工单下的所有订单记录
|
|
|
- $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('id as order_id, pay_status,payment_type,pay_way,pay_time,order_amount,coupon_price')->order('id asc')->select()->toArray();
|
|
|
+ $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('id as order_id, pay_status,payment_type,pay_way,pay_time,order_total,order_amount,coupon_price')->order('id asc')->select()->toArray();
|
|
|
|
|
|
$pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
|
|
|
$payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
|
|
|
@@ -358,12 +361,34 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
$v['pay_status_name'] = $pay_status_data[$v['pay_status']];
|
|
|
$v['payment_type_name'] = $payment_type_data[$v['payment_type']];
|
|
|
$v['pay_way_name'] = $pay_way_data[$v['pay_way']];
|
|
|
+
|
|
|
+ if($v['payment_type']!=1 and !empty($order_info['service_work']['spare_total'])){
|
|
|
+ $v['order_total'] = $v['order_total'] - $order_info['service_work']['spare_total'];
|
|
|
+ $v['order_amount'] = $v['order_total'] - $order_info['service_work']['spare_total'];
|
|
|
+ }
|
|
|
+
|
|
|
$coupon_price += $v['coupon_price'];
|
|
|
}
|
|
|
|
|
|
//汇总优惠卷额度
|
|
|
$order_info['coupon_price'] = $coupon_price;
|
|
|
|
|
|
+ // 所有配件
|
|
|
+ $order_info['spare_total'] = $order_info['service_work']['spare_total']??0;
|
|
|
+ $order_info['spare_parts'] = [];
|
|
|
+ if($order_info['service_work']['service_work_spare_id']){
|
|
|
+ $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$order_info['service_work']['service_work_spare_id'])->value('spare_parts'),true);
|
|
|
+ $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
|
|
|
+ ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $spare_parts = array_column($spare_parts,null,'id');
|
|
|
+ foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
|
|
|
+ $spare_parts[$k] = array_merge($spare_parts[$k],$v);
|
|
|
+ }
|
|
|
+ $order_info['spare_parts'] = array_values($spare_parts)??[];
|
|
|
+ }
|
|
|
+
|
|
|
return $order_info;
|
|
|
}
|
|
|
catch (\Exception $e) {
|
|
|
@@ -373,6 +398,80 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取订单支付详情
|
|
|
+ * @param $params
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public static function orderPayInfo($params)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $order_info = \app\common\model\recharge\RechargeOrder::with(['service_work'=>function ($query) {
|
|
|
+ $query->visible(['spare_total','service_work_spare_id']);
|
|
|
+ }])
|
|
|
+ ->visible(['id','sn','work_id'])
|
|
|
+ ->where([
|
|
|
+ 'order_type' => 0,
|
|
|
+ 'user_id' => $params['user_id'],
|
|
|
+ 'sn'=>$params['sn']
|
|
|
+ ])->findOrEmpty()->toArray();
|
|
|
+
|
|
|
+ if(empty($order_info)){
|
|
|
+ throw new Exception('订单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询总价
|
|
|
+ $order_info['order_amount'] = \app\common\model\recharge\RechargeOrder::where(['order_type'=>0,'user_id'=>$params['user_id'],'work_id'=>$order_info['work_id']])->sum('order_amount');
|
|
|
+ $order_info['paid_amount'] = \app\common\model\recharge\RechargeOrder::where(['order_type'=>0,'user_id'=>$params['user_id'],'work_id'=>$order_info['work_id']])->sum('paid_amount');
|
|
|
+
|
|
|
+ //搜索当前工单下的所有订单记录
|
|
|
+ $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('id as order_id, pay_status,payment_type,pay_way,pay_time,order_total,order_amount,coupon_price')->order('id asc')->select()->toArray();
|
|
|
+
|
|
|
+ $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
|
|
|
+ $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
|
|
|
+ $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
|
|
|
+ $coupon_price = 0;
|
|
|
+ foreach ($order_info['pay_orders'] as $k=>&$v){
|
|
|
+ $v['pay_status_name'] = $pay_status_data[$v['pay_status']];
|
|
|
+ $v['payment_type_name'] = $payment_type_data[$v['payment_type']];
|
|
|
+ $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
|
|
|
+
|
|
|
+ if($v['payment_type']!=1 and !empty($order_info['service_work']['spare_total'])){
|
|
|
+ $v['order_total'] = $v['order_total'] - $order_info['service_work']['spare_total'];
|
|
|
+ $v['order_amount'] = $v['order_amount'] - $order_info['service_work']['spare_total'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $coupon_price += $v['coupon_price'];
|
|
|
+ }
|
|
|
+
|
|
|
+ //汇总优惠卷额度
|
|
|
+ $order_info['coupon_price'] = $coupon_price;
|
|
|
+
|
|
|
+ // 所有配件
|
|
|
+ $order_info['spare_total'] = $order_info['service_work']['spare_total']??0;
|
|
|
+ $order_info['spare_parts'] = [];
|
|
|
+ if($order_info['service_work']['service_work_spare_id']){
|
|
|
+ $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$order_info['service_work']['service_work_spare_id'])->value('spare_parts'),true);
|
|
|
+ $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
|
|
|
+ ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $spare_parts = array_column($spare_parts,null,'id');
|
|
|
+ foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
|
|
|
+ $spare_parts[$k] = array_merge($spare_parts[$k],$v);
|
|
|
+ }
|
|
|
+ $order_info['spare_parts'] = array_values($spare_parts)??[];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $order_info;
|
|
|
+ }
|
|
|
+ catch (\Exception $e) {
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 取消订单
|
|
|
* @param $params
|
|
|
@@ -492,16 +591,9 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
$service_work->user_confirm_status = 5;
|
|
|
$service_work->service_status = 3;
|
|
|
$service_work->work_pay_status = 1;
|
|
|
- $service_work->work_total = $orders[0]['order_total'];
|
|
|
- $service_work->work_amount = $orders[0]['order_amount'];
|
|
|
}else{
|
|
|
$service_work->work_status = 6;
|
|
|
$service_work->user_confirm_status = 4;
|
|
|
- $order_total = 0;
|
|
|
- foreach ($orders as $k=>$v){
|
|
|
- $order_total += $v['order_total'];
|
|
|
- }
|
|
|
- $service_work->work_total = $order_total;
|
|
|
}
|
|
|
$service_work->finished_time = time();
|
|
|
|
|
|
@@ -619,7 +711,6 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
array_walk($orderGoodsData, function (&$value, $key, $data) {
|
|
|
$value = array_merge($value, ['sn' => $data['sn']]);
|
|
|
},$data);
|
|
|
- dd($orderGoodsData);
|
|
|
$orderGoodsModel = new OrderGoods();
|
|
|
$orderGoodsModel->saveAll($orderGoodsData);
|
|
|
Db::commit();
|