Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

林海涛 vor 1 Jahr
Ursprung
Commit
027298b6e6

+ 1 - 1
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -88,7 +88,7 @@ class ServiceWorkLogic extends BaseLogic
             }
 
             //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
-            if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-$work->receive_time)>1800){
+            if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-strtotime($work->receive_time))>1800){
                 throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
             }
 

+ 2 - 13
app/api/lists/GoodsLists.php

@@ -48,6 +48,7 @@ class GoodsLists  extends BaseApiDataLists implements ListsSearchInterface
     public function queryWhere()
     {
         $where = [];
+        $where['user_id'] = 0;//常规商品
         if (!empty($this->params['goods_category_id'])) {
             $goodsCategoryId = end($this->params['goods_category_id']);
             $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
@@ -73,22 +74,10 @@ class GoodsLists  extends BaseApiDataLists implements ListsSearchInterface
         $lists = Goods::order(['id' => 'desc'])
             ->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->visible([
-                'id','goods_image','goods_video','goods_category_ids',
-                'goods_number','good_unit','base_service_fee',
-                'service_total','service_fee','service_image','fee_schedule','warranty_period'
-            ])
+            ->visible(['id','goods_name','goods_image'])
             ->limit($this->limitOffset, $this->limitLength)
             ->select()
             ->toArray();
-        $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
-            ->select();
-        foreach ($lists as &$item) {
-            $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
-            $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
-            $item['goods_image'] = $item['goods_image'] ?  FileService::getFileUrl($item['goods_image']):null;
-            $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
-        }
         return $lists;
     }
 

+ 3 - 3
app/api/logic/GoodsLogic.php

@@ -25,13 +25,13 @@ class GoodsLogic extends BaseLogic
      */
     public static function detail($id,$type){
         if($type == 'category'){
-            $goods = Goods::where('goods_category_id',$id)->visible([
+            $goods = Goods::where(['goods_category_id'=>$id,'user_id'=>0])->visible([
                 'id','goods_image','goods_name','goods_banners','good_unit','base_service_fee',
                 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id'
             ])->select()->toArray();
         }else{
             $goods_category_id = Goods::where('id',$id)->value('goods_category_id');
-            $goods = Goods::where('goods_category_id',$goods_category_id)->visible([
+            $goods = Goods::where(['goods_category_id'=>$goods_category_id,'user_id'=>0])->visible([
                 'id','goods_image','goods_name','goods_banners','good_unit','base_service_fee',
                 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id'
             ])->select()->toArray();
@@ -69,7 +69,7 @@ class GoodsLogic extends BaseLogic
 
     public static function getHotData()
     {
-        return Goods::where('is_hot', '=', 1)
+        return Goods::where(['user_id'=>0,'is_hot'=>1])
             ->with('goodsCategory')
             ->visible(['id','goods_name','goods_image'])
             ->order(['top_weight' => 'desc', 'id' => 'desc'])

+ 2 - 6
app/api/logic/ServiceOrderLogic.php

@@ -51,13 +51,9 @@ class ServiceOrderLogic extends BaseLogic
             if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
                 //一口价订单
                 $order_amount = $goods['service_fee'];
-                $pay_status = PayEnum::UNPAID;
-                $work_pay_status = WorkEnum::UN_PAY_STATUS;
             }else{
                 $order_total = $goods['base_service_fee'];
                 $order_amount = $goods['service_fee'];
-                $pay_status = !empty($order_amount)?PayEnum::UNPAID:PayEnum::ISPAID;
-                $work_pay_status = !empty($order_amount)?WorkEnum::UN_PAY_STATUS:WorkEnum::IS_PAY_STATUS;
             }
 
             //优惠券验证
@@ -108,7 +104,7 @@ class ServiceOrderLogic extends BaseLogic
                 'goods_category_id' => $goods['goods_category_id'],
                 'base_service_fee' => $goods['base_service_fee'],
                 'service_fee' => $goods['service_fee'],
-                'work_pay_status'=>$work_pay_status,
+                'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
                 'appointment_time' => strtotime($params['appointment_time']),
                 'user_id'=>$params['user_id']
             ];
@@ -122,7 +118,7 @@ class ServiceOrderLogic extends BaseLogic
                 'order_terminal' => $params['terminal'],
                 'payment_type'=>$goods['goods_payment_type']==1?1:0,
                 'user_id' => $params['user_id'],
-                'pay_status' => $pay_status,
+                'pay_status' => PayEnum::UNPAID,
                 'coupon_id'=>!empty($params['coupon_id'])?$params['coupon_id']:0,
                 'coupon_price'=>!empty($order_coupon_amount)?$order_coupon_amount:0,
                 'pay_way' => $params['pay_way'],

+ 14 - 11
app/common/logic/EffectiveLogic.php

@@ -15,16 +15,19 @@ class EffectiveLogic extends BaseLogic
     {
         $orderGoods = OrderGoods::whereIn('sn',RechargeOrder::where('work_id',$work->id)->column('sn'))->findOrEmpty();
         $effective =  EffectiveCategory::with('effectiveRule')->where('goods_category_id',$orderGoods->goods_category_id)->findOrEmpty();
-        OrderEffectiveLog::create([
-            'effective_id' => $effective->effectiveRule->id,
-            'sn' => $orderGoods['sn'],
-            'user_id' => $work['user_id'],
-            'work_id' => $work->work_id,
-            'goods_id' => $orderGoods->goods_id,
-            'effective_unit' => $effective->effectiveRule->effective_unit,
-            'effective_num' => $effective->effectiveRule->effective_num,
-            'remark' => $effective->effectiveRule->remark,
-            'end_effective_time' =>  date("Y-m-d H:i:s",EffectiveRules::formatEndEffectiveTime(time() ,$effective->effectiveRule->effective_num,$effective->effectiveRule->effective_unit)),
-        ]);
+        if(!$effective->isEmpty()){
+            OrderEffectiveLog::create([
+                'effective_id' => $effective->effectiveRule->id,
+                'sn' => $orderGoods['sn'],
+                'user_id' => $work['user_id'],
+                'work_id' => $work->work_id,
+                'goods_id' => $orderGoods->goods_id,
+                'effective_unit' => $effective->effectiveRule->effective_unit,
+                'effective_num' => $effective->effectiveRule->effective_num,
+                'remark' => $effective->effectiveRule->remark,
+                'end_effective_time' =>  date("Y-m-d H:i:s",EffectiveRules::formatEndEffectiveTime(time() ,$effective->effectiveRule->effective_num,$effective->effectiveRule->effective_unit)),
+            ]);
+        }
+
     }
 }

+ 26 - 23
app/common/logic/PayNotifyLogic.php

@@ -92,31 +92,34 @@ class PayNotifyLogic extends BaseLogic
     public static function goods($orderSn, array $extra = [])
     {
         $order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
-        // 更新充值订单状态
-        $order->transaction_id = $extra['transaction_id'] ?? '';
-        $order->pay_status = PayEnum::ISPAID;
-        $order->pay_time = time();
-        $order->save();
-
+        if(!$order->isEmpty()){
+            // 更新充值订单状态
+            $order->transaction_id = $extra['transaction_id'] ?? '';
+            $order->pay_status = PayEnum::ISPAID;
+            $order->pay_time = time();
+            $order->save();
+        }
         $work = ServiceWork::findOrEmpty($order->work_id);
-
-        $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(!$work->isEmpty()){
+            $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'];
+            }
+            $work->work_total = $order_total;
+            $work->work_amount = $order_amount;
+            if($work->work_status != 0){
+                $work->work_status = 7;
+                $work->user_confirm_status = 5;
+                $work->service_status = 3;
+            }
+            $work->work_pay_status = 1;
+            $work->finished_time = time();
+            $work->save();
         }
-        $work->work_total = $order_total;
-        $work->work_amount = $order_amount;
-        $work->work_status = 7;
-        $work->user_confirm_status = 5;
-        $work->service_status = 3;
-        $work->work_pay_status = 1;
-        $work->finished_time = time();
-        $work->save();
     }
 
 

+ 9 - 4
app/common/logic/PaymentLogic.php

@@ -17,11 +17,13 @@ namespace app\common\logic;
 
 use app\common\enum\PayEnum;
 use app\common\enum\YesNoEnum;
+use app\common\model\effective\EffectiveCategory;
 use app\common\model\pay\PayWay;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\user\User;
 use app\common\service\pay\AliPayService;
 use app\common\service\pay\WeChatPayService;
+use think\Exception;
 
 
 /**
@@ -143,17 +145,19 @@ class PaymentLogic extends BaseLogic
         try {
             $order = RechargeOrder::findOrEmpty($params['order_id']);
             if ($order->isEmpty()) {
-                throw new \Exception('订单不存在');
+                throw new Exception('订单不存在');
             }
-
             //判断订单类型.服务订单尾款处理
             if($order['order_type'] == 0 and $order['pay_status'] == PayEnum::ISPAID)//服务工单
             {
                 $order = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
+                if($order->isEmpty()){
+                    throw new Exception('订单已支付');
+                }
             }
 
             if ($order['pay_status'] == PayEnum::ISPAID) {
-                throw new \Exception('订单已支付');
+                throw new Exception('订单已支付');
             }
             return $order;
         } catch (\Exception $e) {
@@ -193,7 +197,7 @@ class PaymentLogic extends BaseLogic
 
         if ($order['order_amount'] == 0) {
             PayNotifyLogic::handle($from, $order['sn']);
-            return ['sn' => $order['sn']];
+            return ['sn' => $order['sn'],'need_pay'=>0];
         }
 
         $payService = null;
@@ -217,6 +221,7 @@ class PaymentLogic extends BaseLogic
         if (false === $result && !self::hasError()) {
             self::setError($payService->getError());
         }
+        $result['need_pay'] = 1;
         return $result;
     }
 

+ 2 - 0
app/common/service/pay/WeChatPayService.php

@@ -24,6 +24,7 @@ use app\common\model\user\UserAuth;
 use app\common\service\wechat\WeChatConfigService;
 use EasyWeChat\Pay\Application;
 use EasyWeChat\Pay\Message;
+use think\facade\Log;
 
 
 /**
@@ -371,6 +372,7 @@ class WeChatPayService extends BasePayService
         $server = $this->app->getServer();
         // 支付通知
         $server->handlePaid(function (Message $message) {
+            Log::write(json_encode($message, JSON_UNESCAPED_UNICODE));
             if ($message['trade_state'] === 'SUCCESS') {
                 $extra['transaction_id'] = $message['transaction_id'];
                 $attach = $message['attach'];

+ 54 - 0
app/workerapi/controller/PayController.php

@@ -0,0 +1,54 @@
+<?php
+namespace app\workerapi\controller;
+
+use app\api\validate\PayValidate;
+use app\common\enum\user\UserTerminalEnum;
+use app\common\logic\PaymentLogic;
+use app\common\service\pay\AliPayService;
+use app\common\service\pay\WeChatPayService;
+
+/**
+ * 支付
+ * Class PayController
+ * @package app\api\controller
+ */
+class PayController extends \app\workerapi\controller\BaseApiController
+{
+
+    /**
+     * @notes 工程师代支付
+     * @return \think\response\Json
+     */
+    public function prepay()
+    {
+        $params = (new PayValidate())->post()->goCheck();
+        //订单信息
+        $order = PaymentLogic::getPayOrderInfo($params);
+        if (false === $order) {
+            return $this->fail(PaymentLogic::getError(), $params);
+        }
+        //支付流程
+        $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
+        $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl);
+        if (false === $result) {
+            return $this->fail(PaymentLogic::getError(), $params);
+        }
+        $result['sn'] = $order['sn'];
+        return $this->success('', $result);
+    }
+
+
+    /**
+     * @notes 获取支付状态
+     * @return \think\response\Json
+     */
+    public function payStatus()
+    {
+        $params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
+        $result = PaymentLogic::getPayStatus($params);
+        if ($result === false) {
+            return $this->fail(PaymentLogic::getError());
+        }
+        return $this->data($result);
+    }
+}