Explorar o código

add - 权益卡 支付 退费

liugc hai 1 ano
pai
achega
550566b95f

+ 85 - 0
app/api/logic/ServiceOrderLogic.php

@@ -10,6 +10,7 @@ use app\common\enum\WorkEnum;
 use app\common\enum\YesNoEnum;
 use app\common\enum\YesNoEnum;
 use app\common\logic\BaseLogic;
 use app\common\logic\BaseLogic;
 use app\common\logic\PaymentLogic;
 use app\common\logic\PaymentLogic;
+use app\common\logic\PayNotifyLogic;
 use app\common\logic\RefundLogic;
 use app\common\logic\RefundLogic;
 use app\common\model\coupon\CouponCategory;
 use app\common\model\coupon\CouponCategory;
 use app\common\model\coupon\UserCoupon;
 use app\common\model\coupon\UserCoupon;
@@ -152,6 +153,7 @@ class ServiceOrderLogic extends BaseLogic
                 'lon'=>!empty($params['lon'])?$params['lon']:0,
                 'lon'=>!empty($params['lon'])?$params['lon']:0,
                 'lat'=>!empty($params['lat'])?$params['lat']:0,
                 'lat'=>!empty($params['lat'])?$params['lat']:0,
                 'property_activity_id'=>!empty($params['property_activity_id'])?$params['property_activity_id']:0,
                 'property_activity_id'=>!empty($params['property_activity_id'])?$params['property_activity_id']:0,
+                'user_equity_id'=>$params['user_equity_id']??0,
             ];
             ];
 
 
             //判断是否是加单
             //判断是否是加单
@@ -173,6 +175,13 @@ class ServiceOrderLogic extends BaseLogic
 
 
             $service_work = ServiceWork::create($work_data);
             $service_work = ServiceWork::create($work_data);
 
 
+
+            //使用权益卡时订单应支付金额=0
+            if(isset($params['user_equity_id']) && $params['user_equity_id']){
+                $order_total = 0;
+                $order_amount = 0;
+            }
+
             //生成服务订单
             //生成服务订单
             $data = [
             $data = [
                 'work_id'=> $service_work['id'],
                 'work_id'=> $service_work['id'],
@@ -215,6 +224,15 @@ class ServiceOrderLogic extends BaseLogic
                 'goods_status' => $goods['goods_status'],
                 'goods_status' => $goods['goods_status'],
             ]);
             ]);
             Db::commit();
             Db::commit();
+            if(empty($order_amount)){
+                $is_zero_pay = self::zeroDirectlyPayment([
+                    'attach' => 'goods',
+                    'out_trade_no' => $order['sn'],
+                ]);
+                if($is_zero_pay === false){
+                    Log::info('0元支付失败:'.$order['sn']."---".self::getError());
+                }
+            }
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             self::setError($e->getMessage());
             self::setError($e->getMessage());
             return false;
             return false;
@@ -1204,4 +1222,71 @@ class ServiceOrderLogic extends BaseLogic
         }
         }
     }
     }
 
 
+    /**
+     * 0元支付直接完成支付
+     * @param array $params attach out_trade_no
+     * @return bool|void
+     */
+    public static function zeroDirectlyPayment(array $params, $extra = [])
+    {
+        try {
+            $message['out_trade_no'] = mb_substr($params['out_trade_no'], 0, 18);
+            $order = RechargeOrder::where(['sn' => $params['out_trade_no']])->findOrEmpty();
+            if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
+                return true;
+            }
+            switch ($params['attach']) {
+                case 'recharge':
+                    PayNotifyLogic::handle('recharge', $params['out_trade_no'], $extra);
+                    break;
+                case 'goods':
+                    $res = PayNotifyLogic::handle('goods', $params['out_trade_no'], $extra);
+                    if($res === true){
+                        // 用户下单后,给订单运营专员(配置固定ID)发送公众号提醒(订单信息)
+                        $order = RechargeOrder::where('sn', $message['out_trade_no'])
+                            ->where('payment_type','IN',[0,1])
+                            ->where('pay_status','=',1)
+                            ->findOrEmpty();
+                        if(!$order->isEmpty()){
+                            $workDetail = ServiceWork::findOrEmpty($order->work_id);
+                            if(!$workDetail->isEmpty()){
+                                event('Notice',  [
+                                    'scene_id' => 100,
+                                    'params' => [
+                                        'user_id' => 0,
+                                        'order_id' => $workDetail['id'],
+                                        'thing3' => $workDetail['title'],
+                                        'time6' => $workDetail['appointment_time'],
+                                        'phone_number8' => asteriskString($workDetail['mobile']),
+                                        'thing5' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
+                                    ]
+                                ]);
+                            }
+                        }
+
+                        // 订单完成通知【给用户】 - 尾款 -通知
+                        $order = RechargeOrder::where('sn', $message['out_trade_no'])
+                            ->where('payment_type','=',2)
+                            ->where('pay_status','=',1)
+                            ->findOrEmpty();
+                        if(!$order->isEmpty()){
+                            event('Notice',  [
+                                'scene_id' => 120,
+                                'params' => [
+                                    'user_id' => $order['user_id']
+                                ]
+                            ]);
+                        }
+                    }
+                    break;
+            }
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+
 }
 }

+ 5 - 0
app/common/command/QueryRefund.php

@@ -19,6 +19,7 @@ use app\common\enum\RefundEnum;
 use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\logic\RetentionMoneyLogic;
 use app\common\logic\RetentionMoneyLogic;
 use app\common\logic\WorkerAccountLogLogic;
 use app\common\logic\WorkerAccountLogLogic;
+use app\common\model\equity\UserEquity;
 use app\common\model\master_worker\MasterWorkerAccountLog;
 use app\common\model\master_worker\MasterWorkerAccountLog;
 use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
 use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
 use app\common\model\property\PropertyCommission;
 use app\common\model\property\PropertyCommission;
@@ -231,6 +232,10 @@ class QueryRefund extends Command
                         'surplus_profit_amount' => Db::raw('surplus_profit_amount-'.$property_commission['commission_amount'])
                         'surplus_profit_amount' => Db::raw('surplus_profit_amount-'.$property_commission['commission_amount'])
                     ]);
                     ]);
                 }
                 }
+                // 权益卡剩余次数
+                if(!empty($work->user_equity_id)){
+                    UserEquity::where(['id'=>$work->user_equity_id])->inc('number')->save();
+                }
             }else{
             }else{
                 Log::channel('re_fund')->info('工单ID'.$order->work_id.'数据'.json_encode($work,JSON_UNESCAPED_UNICODE));
                 Log::channel('re_fund')->info('工单ID'.$order->work_id.'数据'.json_encode($work,JSON_UNESCAPED_UNICODE));
             }
             }

+ 18 - 9
app/common/logic/PayNotifyLogic.php

@@ -17,6 +17,7 @@ namespace app\common\logic;
 use app\common\enum\PayEnum;
 use app\common\enum\PayEnum;
 use app\common\enum\user\AccountLogEnum;
 use app\common\enum\user\AccountLogEnum;
 use app\common\enum\WorkEnum;
 use app\common\enum\WorkEnum;
+use app\common\model\equity\UserEquity;
 use app\common\model\recharge\OrderGoods;
 use app\common\model\recharge\OrderGoods;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\shops\ShopOrders;
 use app\common\model\shops\ShopOrders;
@@ -126,16 +127,24 @@ class PayNotifyLogic extends BaseLogic
             if(!$work->isEmpty()){
             if(!$work->isEmpty()){
                 $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
                 $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
 
 
-                $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
-
-                $order_total = 0;
-                $order_amount = 0;
-                foreach ($orders as $k=>$v){
-                    $order_total += $v['order_total'];
-                    $order_amount += $v['order_amount'];
+                // 权益卡工单
+                if(!empty($work->user_equity_id)){
+                    $work->work_total = $work->service_fee;
+                    $work->work_amount = $work->service_fee;
+                    // 权益卡剩余次数
+                    UserEquity::where(['id'=>$work->user_equity_id])->dec('number')->save();
+                }else{
+                    $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
+
+                    $order_total = 0;
+                    $order_amount = 0;
+                    foreach ($orders as $k=>$v){
+                        $order_total += $v['order_total'];
+                        $order_amount += $v['order_amount'];
+                    }
+                    $work->work_total = $order_total;
+                    $work->work_amount = $order_amount;
                 }
                 }
-                $work->work_total = $order_total;
-                $work->work_amount = $order_amount;
                 if($work->work_status != 0 and $work->work_status != 1 and $work->work_status != 2){
                 if($work->work_status != 0 and $work->work_status != 1 and $work->work_status != 2){
                     $work->work_status = 7;
                     $work->work_status = 7;
                     $work->user_confirm_status = 5;
                     $work->user_confirm_status = 5;