Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/adminapi/logic/goods/GoodsLogic.php
林海涛 1 tahun lalu
induk
melakukan
a8d91c1005

+ 4 - 0
app/adminapi/logic/goods/GoodsLogic.php

@@ -17,6 +17,7 @@ namespace app\adminapi\logic\goods;
 
 use app\common\model\goods\Goods;
 use app\common\logic\BaseLogic;
+use app\common\model\goods_category\GoodsCategory;
 use think\facade\Db;
 
 
@@ -41,8 +42,10 @@ class GoodsLogic extends BaseLogic
         Db::startTrans();
         try {
             $params['goods_category_id'] = end($params['goods_category_ids']);
+
             Goods::create([
                 'goods_category_ids' => $params['goods_category_ids'],
+                'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'goods_category_id' => $params['goods_category_id'],
                 'goods_name' => $params['goods_name'],
                 'goods_image' => $params['goods_image'],
@@ -92,6 +95,7 @@ class GoodsLogic extends BaseLogic
         try {
             $params['goods_category_id'] = end($params['goods_category_ids']);
             Goods::where('id', $params['id'])->update([
+                'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'goods_category_ids' => $params['goods_category_ids'],
                 'goods_category_id' => $params['goods_category_id'],
                 'goods_name' => $params['goods_name'],

+ 0 - 11
app/api/controller/PayController.php

@@ -34,8 +34,6 @@ class PayController extends BaseApiController
     /**
      * @notes 支付方式
      * @return \think\response\Json
-     * @author 段誉
-     * @date 2023/2/24 17:54
      */
     public function payWay()
     {
@@ -51,8 +49,6 @@ class PayController extends BaseApiController
     /**
      * @notes 预支付
      * @return \think\response\Json
-     * @author 段誉
-     * @date 2023/2/28 14:21
      */
     public function prepay()
     {
@@ -75,8 +71,6 @@ class PayController extends BaseApiController
     /**
      * @notes 获取支付状态
      * @return \think\response\Json
-     * @author 段誉
-     * @date 2023/3/1 16:23
      */
     public function payStatus()
     {
@@ -96,8 +90,6 @@ class PayController extends BaseApiController
      * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
      * @throws \ReflectionException
      * @throws \Throwable
-     * @author 段誉
-     * @date 2023/2/28 14:21
      */
     public function notifyMnp()
     {
@@ -112,8 +104,6 @@ class PayController extends BaseApiController
      * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
      * @throws \ReflectionException
      * @throws \Throwable
-     * @author 段誉
-     * @date 2023/2/28 14:21
      */
     public function notifyOa()
     {
@@ -123,7 +113,6 @@ class PayController extends BaseApiController
     /**
      * @notes 支付宝回调
      * @author mjf
-     * @date 2024/3/18 16:50
      */
     public function aliNotify()
     {

+ 2 - 6
app/api/controller/RechargeController.php

@@ -19,7 +19,7 @@ use app\api\validate\RechargeValidate;
 
 
 /**
- * 充值控制器
+ *
  * Class RechargeController
  * @package app\shopapi\controller
  */
@@ -27,10 +27,8 @@ class RechargeController extends BaseApiController
 {
 
     /**
-     * @notes 获取充值列表
+     * @notes 充值列表
      * @return \think\response\Json
-     * @author 段誉
-     * @date 2023/2/23 18:55
      */
     public function lists()
     {
@@ -41,8 +39,6 @@ class RechargeController extends BaseApiController
     /**
      * @notes 充值
      * @return \think\response\Json
-     * @author 段誉
-     * @date 2023/2/23 18:56
      */
     public function recharge()
     {

+ 31 - 0
app/api/controller/ServiceOrderController.php

@@ -0,0 +1,31 @@
+<?php
+namespace app\api\controller;
+
+use app\api\lists\recharge\ServiceOrderLists;
+use app\api\logic\ServiceOrderLogic;
+use app\api\validate\ServiceOrderValidate;
+
+/**
+ * 订单类
+ */
+class ServiceOrderController extends BaseApiController
+{
+    public function lists()
+    {
+        return $this->dataLists(new ServiceOrderLists());
+    }
+
+    public function submitOrder()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('add', [
+            'user_id' => $this->userId,
+            'terminal' => $this->userInfo['terminal'],
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceOrderLogic::submitOrder($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->data($result);
+    }
+}

+ 2 - 25
app/api/lists/recharge/RechargeLists.php

@@ -1,24 +1,10 @@
 <?php
-// +----------------------------------------------------------------------
-// | likeadmin快速开发前后端分离管理后台(PHP版)
-// +----------------------------------------------------------------------
-// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
-// | 开源版本可自由商用,可去除界面版权logo
-// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
-// | github下载:https://github.com/likeshop-github/likeadmin
-// | 访问官网:https://www.likeadmin.cn
-// | likeadmin团队 版权所有 拥有最终解释权
-// +----------------------------------------------------------------------
-// | author: likeadminTeam
-// +----------------------------------------------------------------------
-
 namespace app\api\lists\recharge;
 
 use app\api\lists\BaseApiDataLists;
 use app\common\enum\PayEnum;
 use app\common\model\recharge\RechargeOrder;
 
-
 /**
  * 充值记录列表
  * Class RechargeLists
@@ -32,24 +18,17 @@ class RechargeLists extends BaseApiDataLists
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
-     * @author 段誉
-     * @date 2023/2/23 18:43
      */
     public function lists(): array
     {
         $lists = RechargeOrder::field('order_amount,create_time')
             ->where([
+                'order_type' => 1,
                 'user_id' => $this->userId,
-                'pay_status' => PayEnum::ISPAID
             ])
             ->order('id', 'desc')
             ->select()
             ->toArray();
-
-        foreach($lists as &$item) {
-            $item['tips'] = '充值' . format_amount($item['order_amount']) . '元';
-        }
-
         return $lists;
     }
 
@@ -57,14 +36,12 @@ class RechargeLists extends BaseApiDataLists
     /**
      * @notes  获取数量
      * @return int
-     * @author 段誉
-     * @date 2023/2/23 18:43
      */
     public function count(): int
     {
         return RechargeOrder::where([
+                'order_type' => 1,
                 'user_id' => $this->userId,
-                'pay_status' => PayEnum::ISPAID
             ])
             ->count();
     }

+ 67 - 0
app/api/lists/recharge/ServiceOrderLists.php

@@ -0,0 +1,67 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\api\lists\recharge;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\enum\PayEnum;
+use app\common\model\recharge\RechargeOrder;
+
+/**
+ * 服务订单列别
+ * Class RechargeLists
+ * @package app\api\lists\recharge
+ */
+class ServiceOrderLists extends BaseApiDataLists
+{
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function lists(): array
+    {
+        $lists = RechargeOrder::with(['order_goods'=>function ($query) {
+            $query->visible(['goods_name','goods_image','goods_number','good_unit']);
+        },'service_work'=>function ($query) {
+            $query->visible(['service_status']);
+        }])
+            ->visible(['id','sn','order_total','order_amount','pay_status','create_time'])
+            ->where([
+                'order_type' => 0,
+                'user_id' => $this->userId,
+            ])
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return RechargeOrder::where([
+                'order_type' => 0,
+                'user_id' => $this->userId,
+            ])
+            ->count();
+    }
+
+}

+ 1 - 8
app/api/logic/RechargeLogic.php

@@ -33,14 +33,13 @@ class RechargeLogic extends BaseLogic
      * @notes 充值
      * @param array $params
      * @return array|false
-     * @author 段誉
-     * @date 2023/2/24 10:43
      */
     public static function recharge(array $params)
     {
         try {
             $data = [
                 'sn' => generate_sn(RechargeOrder::class, 'sn'),
+                'order_type'=>1,//充值订单
                 'order_terminal' => $params['terminal'],
                 'user_id' => $params['user_id'],
                 'pay_status' => PayEnum::UNPAID,
@@ -58,13 +57,10 @@ class RechargeLogic extends BaseLogic
         }
     }
 
-
     /**
      * @notes 充值配置
      * @param $userId
      * @return array
-     * @author 段誉
-     * @date 2023/2/24 16:56
      */
     public static function config($userId)
     {
@@ -79,7 +75,4 @@ class RechargeLogic extends BaseLogic
         ];
     }
 
-
-
-
 }

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

@@ -0,0 +1,117 @@
+<?php
+
+namespace app\api\logic;
+
+use app\common\enum\GoodsEnum;
+use app\common\enum\PayEnum;
+use app\common\enum\WorkEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\goods\Goods;
+use app\common\model\orders\RechargeOrder;
+use app\common\model\recharge\OrderGoods;
+use app\common\model\works\ServiceWork;
+use think\Exception;
+
+
+/**
+ *  订单逻辑层
+ * Class ServiceOrderLogic
+ * @package app\api\logic
+ */
+class ServiceOrderLogic extends BaseLogic
+{
+    /**
+     * 提交订单
+     * @param array $params
+     * @return array|false
+     */
+    public static function submitOrder($params)
+    {
+        try {
+            $goods = Goods::findOrEmpty($params['goods_id']);
+            if($goods->isEmpty()){
+                throw new Exception('产品不存在!');
+            }
+            if($params['user_info']['mobile']){
+                throw new Exception('请先补充您的联系方式后在提交订单');
+            }
+
+            //根据服务工单计算当前订单应支付金额
+            $order_total = $goods['service_total'];
+            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_amount = $goods['base_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;
+            }
+
+            //生成服务工单
+            $work_data = [
+                'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
+                'real_name' => !empty($params['user_info']['real_name'])?$params['user_info']['real_name']:$params['user_info']['nickname'],
+                'mobile' => $params['user_info']['mobile'],
+                'address' => $params['address'],
+                'title' => $goods->goods_name . '*' . $goods->goods_number.$goods->good_unit,
+                'category_type' => $goods['category_type'],
+                'goods_category_ids' => $goods['goods_category_ids'],
+                '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,
+                'appointment_time' => strtotime($params['appointment_time']),
+            ];
+            $service_work = ServiceWork::create($work_data);
+
+            //生成服务订单
+            $data = [
+                'work_id'=> $service_work['id'],
+                'sn' => generate_sn(RechargeOrder::class, 'sn'),
+                'order_type'=>0,//服务订单
+                'order_terminal' => $params['terminal'],
+                'user_id' => $params['user_id'],
+                'pay_status' => $pay_status,
+                'pay_way' => $params['pay_way'],
+                'order_total' => $order_total,
+                'order_amount' => $order_amount,
+            ];
+
+            $order = RechargeOrder::create($data);
+            //生成订单服务详情
+            OrderGoods::create([
+                'sn' => $order['sn'],
+                'goods_id' => $params['goods_id'],
+                'category_type' => $goods['category_type'],
+                'goods_category_ids' => $goods['goods_category_ids'],
+                'goods_category_id' => $goods['goods_category_id'],
+                'goods_name' => $goods['goods_name'],
+                'goods_image' => $goods['goods_image'],
+                'goods_video' => $goods['goods_video'],
+                'goods_number' => $goods['goods_number'],
+                'good_unit' => $goods['good_unit'],
+                'goods_size' => $goods['goods_size'],
+                'goods_type' => $goods['goods_type'],
+                'goods_brand' => $goods['goods_brand'],
+                'install_guide' => $goods['install_guide'],
+                'goods_payment_type'=>$goods['goods_payment_type'],
+                'base_service_fee' => $goods['base_service_fee'],
+                'service_total' => $goods['service_total'],
+                'service_fee' => $goods['service_fee'],
+                'service_image' => $goods['service_image'],
+                'warranty_period'=>$goods['warranty_period'],
+                'fee_schedule' => $goods['fee_schedule'],
+                'goods_status' => $goods['goods_status'],
+            ]);
+
+            return [
+                'order_id' => (int)$order['id'],
+            ];
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+}

+ 0 - 2
app/api/validate/RechargeValidate.php

@@ -50,8 +50,6 @@ class RechargeValidate extends BaseValidate
      * @param $rule
      * @param $data
      * @return bool|string
-     * @author 段誉
-     * @date 2023/2/24 10:42
      */
     protected function checkMoney($money, $rule, $data)
     {

+ 38 - 0
app/api/validate/ServiceOrderValidate.php

@@ -0,0 +1,38 @@
+<?php
+namespace app\api\validate;
+
+use app\common\enum\PayEnum;
+use app\common\service\ConfigService;
+use app\common\validate\BaseValidate;
+
+/**
+ * 服务订单验证器
+ * Class ServiceOrderValidate
+ * @package app\api\validate
+ */
+class ServiceOrderValidate extends BaseValidate
+{
+
+    protected $rule = [
+        'address' => 'require',
+        'appointment_time' => 'require|dateFormat:Y-m-d H:i:s',
+        'pay_way' => 'require',
+        'goods_id' => 'require',
+    ];
+
+
+    protected $message = [
+        'address.require' => '请填写地址',
+        'appointment_time.require' => '请填写预约上门时间',
+        'appointment_time.dateFormat' => '预约上门时间格式错误',
+        'pay_way.require' => '请选择支付方式',
+        'goods_id.require' => '订单商品不存在',
+    ];
+
+
+    public function sceneAdd()
+    {
+        return $this->only(['address','appointment_time','pay_way','goods_id']);
+    }
+
+}

+ 1 - 0
app/common/cache/UserTokenCache.php

@@ -74,6 +74,7 @@ class UserTokenCache extends BaseCache
 
         $userInfo = [
             'user_id' => $user->id,
+            'real_name'=>$user->real_name,
             'nickname' => $user->nickname,
             'token' => $token,
             'sn' => $user->sn,

+ 13 - 0
app/common/enum/GoodsEnum.php

@@ -0,0 +1,13 @@
+<?php
+namespace app\common\enum;
+
+/**
+ * 服务产品
+ */
+class GoodsEnum
+{
+
+    //服务支付类别
+    const UNGOODS_PAYMENT_TYPE = 1;
+    const ISGOODS_PAYMENT_TYPE = 2;
+}

+ 11 - 0
app/common/enum/WorkEnum.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace app\common\enum;
+
+class WorkEnum
+{
+    //工单结算状态
+    const UN_PAY_STATUS = 0;
+    const IS_PAY_STATUS = 1;
+    const EN_PAY_STATUS = 2;
+}

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

@@ -44,11 +44,7 @@ class PaymentLogic extends BaseLogic
     public static function getPayWay($userId, $terminal, $params)
     {
         try {
-            if ($params['from'] == 'recharge') {
-                // 充值
-                $order = RechargeOrder::findOrEmpty($params['order_id'])->toArray();
-            }
-
+            $order = RechargeOrder::findOrEmpty($params['order_id'])->toArray();
             if (empty($order)) {
                 throw new \Exception('待支付订单不存在');
             }
@@ -145,15 +141,10 @@ class PaymentLogic extends BaseLogic
     public static function getPayOrderInfo($params)
     {
         try {
-            switch ($params['from']) {
-                case 'recharge':
-                    $order = RechargeOrder::findOrEmpty($params['order_id']);
-                    if ($order->isEmpty()) {
-                        throw new \Exception('充值订单不存在');
-                    }
-                    break;
+            $order = RechargeOrder::findOrEmpty($params['order_id']);
+            if ($order->isEmpty()) {
+                throw new \Exception('订单不存在');
             }
-
             if ($order['pay_status'] == PayEnum::ISPAID) {
                 throw new \Exception('订单已支付');
             }

+ 1 - 1
app/common/model/goods/Goods.php

@@ -21,7 +21,7 @@ use app\common\model\goods_category\GoodsCategory;
 
 /**
  * Goods模型
- * Class Goods
+ * Class GoodsEnum
  * @package app\common\model\goods
  */
 class Goods extends BaseModel

+ 37 - 0
app/common/model/recharge/OrderGoods.php

@@ -0,0 +1,37 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\recharge;
+
+use app\common\model\BaseModel;
+use app\common\model\goods_category\GoodsCategory;
+
+/**
+ * 订单服务商品镜像模型
+ * Class OrderGoods
+ * @package app\common\model
+ */
+class OrderGoods extends BaseModel
+{
+    protected $type = [
+        'goods_category_ids' =>  'array',
+    ];
+
+    public function goodsCategory()
+    {
+        return $this->hasOne(GoodsCategory::class, 'id', 'goods_category_id')
+            ->field('id,name,picture');
+    }
+
+}

+ 12 - 1
app/common/model/recharge/RechargeOrder.php

@@ -16,10 +16,11 @@ namespace app\common\model\recharge;
 
 use app\common\enum\PayEnum;
 use app\common\model\BaseModel;
+use app\common\model\works\ServiceWork;
 use think\model\concern\SoftDelete;
 
 /**
- * 充值订单模型
+ * 订单模型
  * Class RechargeOrder
  * @package app\common\model
  */
@@ -54,4 +55,14 @@ class RechargeOrder extends BaseModel
     {
         return PayEnum::getPayStatusDesc($data['pay_status']);
     }
+
+    public function serviceWork()
+    {
+        return $this->belongsTo(ServiceWork::class, 'work_id', 'id');
+    }
+
+    public function orderGoods()
+    {
+        return $this->hasOne(OrderGoods::class, 'sn', 'sn');
+    }
 }

+ 0 - 1
app/common/service/wechat/WeChatConfigService.php

@@ -129,7 +129,6 @@ class WeChatConfigService
         if (!empty($apiclientKey) && !file_exists($keyPath)) {
             static::setCert($keyPath, trim($apiclientKey));
         }
-
         return [
             // 商户号
             'mch_id' => $pay['config']['mch_id'] ?? '',