Sfoglia il codice sorgente

工单+订单相关功能

whitefang 1 anno fa
parent
commit
2400a1b2e1

+ 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,7 +42,9 @@ class GoodsLogic extends BaseLogic
         Db::startTrans();
         try {
             $params['goods_category_id'] = end($params['goods_category_ids']);
+
             Goods::create([
+                'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'goods_category_ids' => json_encode($params['goods_category_ids'],true),
                 'goods_category_id' => $params['goods_category_id'],
                 'goods_name' => $params['goods_name'],
@@ -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'],

+ 1 - 5
app/api/controller/RechargeController.php

@@ -19,7 +19,7 @@ use app\api\validate\RechargeValidate;
 
 
 /**
- * 充值控制器
+ *
  * Class RechargeController
  * @package app\shopapi\controller
  */
@@ -29,8 +29,6 @@ class RechargeController extends BaseApiController
     /**
      * @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()
     {

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

@@ -0,0 +1,25 @@
+<?php
+namespace app\api\controller;
+
+use app\api\logic\ServiceOrderLogic;
+use app\api\validate\ServiceOrderValidate;
+
+/**
+ * 订单类
+ */
+class ServiceOrderController extends BaseApiController
+{
+    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 - 4
app/api/lists/recharge/RechargeLists.php

@@ -32,13 +32,12 @@ 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
             ])
@@ -57,12 +56,11 @@ 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
             ])

+ 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 [
+                'work_sn' => (int)$service_work['work_sn'],
+            ];
+        } 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;
+}

+ 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');
+    }
+
+}