Procházet zdrojové kódy

add - 客咨下单

liugc před 1 rokem
rodič
revize
2246c5ddce

+ 116 - 0
app/adminapi/controller/external/ExternalConsultationController.php

@@ -0,0 +1,116 @@
+<?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\adminapi\controller\external;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\external\ExternalConsultationLists;
+use app\adminapi\logic\external\ExternalConsultationLogic;
+use app\adminapi\validate\external\ExternalConsultationValidate;
+
+
+/**
+ * ExternalConsultation控制器
+ * Class ExternalConsultationController
+ * @package app\adminapi\controller
+ */
+class ExternalConsultationController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function lists()
+    {
+        return $this->dataLists(new ExternalConsultationLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function add()
+    {
+        $params = (new ExternalConsultationValidate())->post()->goCheck('add');
+        $result = ExternalConsultationLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(ExternalConsultationLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function edit()
+    {
+        $params = (new ExternalConsultationValidate())->post()->goCheck('edit');
+        $result = ExternalConsultationLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(ExternalConsultationLogic::getError());
+    }
+
+    public function order()
+    {
+        $params = (new ExternalConsultationValidate())->post()->goCheck('edit');
+        $result = ExternalConsultationLogic::order($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(ExternalConsultationLogic::getError());
+    }
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function delete()
+    {
+        $params = (new ExternalConsultationValidate())->post()->goCheck('delete');
+        ExternalConsultationLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function detail()
+    {
+        $params = (new ExternalConsultationValidate())->goCheck('detail');
+        $result = ExternalConsultationLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 78 - 0
app/adminapi/lists/external/ExternalConsultationLists.php

@@ -0,0 +1,78 @@
+<?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\adminapi\lists\external;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\external\ExternalConsultation;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * ExternalConsultation列表
+ * Class ExternalConsultationLists
+ * @package app\adminapi\lists
+ */
+class ExternalConsultationLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['external_platform_id'],
+            '%like%' => ['user_name', 'mobile', 'unique_code'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function lists(): array
+    {
+        return ExternalConsultation::where($this->searchWhere)
+            ->field(['*'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function count(): int
+    {
+        return ExternalConsultation::where($this->searchWhere)->count();
+    }
+
+}

+ 180 - 0
app/adminapi/logic/external/ExternalConsultationLogic.php

@@ -0,0 +1,180 @@
+<?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\adminapi\logic\external;
+
+
+use app\common\logic\ThirdOrderLogic;
+use app\common\model\external\ExternalConsultation;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * ExternalConsultation逻辑
+ * Class ExternalConsultationLogic
+ * @package app\adminapi\logic
+ */
+class ExternalConsultationLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            ExternalConsultation::create([
+                'external_platform_id' => $params['external_platform_id'],
+                'shop_code' => $params['shop_code'],
+                'shop_name' => $params['shop_name'],
+                'unique_code' => $params['unique_code'],
+                'solution_type' => $params['solution_type'],
+                'form_detail' => $params['form_detail'],
+                'user_name' => $params['user_name'],
+                'mobile' => $params['mobile'],
+                'user_address' => $params['user_address'],
+                'appointment_time' => $params['appointment_time'],
+                'goods_id' => $params['goods_id'],
+                'amount' => $params['amount'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat'],
+                'remark' => $params['remark']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            ExternalConsultation::where('id', $params['id'])->update([
+                'external_platform_id' => $params['external_platform_id'],
+                'shop_code' => $params['shop_code'],
+                'shop_name' => $params['shop_name'],
+                'unique_code' => $params['unique_code'],
+                'solution_type' => $params['solution_type'],
+                'form_detail' => $params['form_detail'],
+                'user_name' => $params['user_name'],
+                'mobile' => $params['mobile'],
+                'user_address' => $params['user_address'],
+                'appointment_time' => $params['appointment_time'],
+                'goods_id' => $params['goods_id'],
+                'amount' => $params['amount'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat'],
+                'remark' => $params['remark']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+    public static function order(array $params): bool
+    {
+        if($params['user_address']){
+            $lon_lat = get_address_lat_lng($params['user_address']);
+            $params['lon'] = $lon_lat['lon'];
+            $params['lat'] = $lon_lat['lat'];
+        }
+        Db::startTrans();
+        try {
+
+            ExternalConsultation::where('id', $params['id'])->update([
+                'external_platform_id' => $params['external_platform_id'],
+                'shop_code' => $params['shop_code'],
+                'shop_name' => $params['shop_name'],
+                'unique_code' => $params['unique_code'],
+                'solution_type' => $params['solution_type'],
+                'form_detail' => $params['form_detail'],
+                'user_name' => $params['user_name'],
+                'mobile' => $params['mobile'],
+                'user_address' => $params['user_address'],
+                'appointment_time' => $params['appointment_time'],
+                'goods_id' => $params['goods_id'],
+                'amount' => $params['amount'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat'],
+                'remark' => $params['remark']
+            ]);
+            // userName mobile goods_id userAddress amount appointment_time lon lat
+            ThirdOrderLogic::submitOrders([
+                'userName' => $params['user_name'],
+                'mobile' => $params['mobile'],
+                'goods_id' => $params['goods_id'],
+                'userAddress' => $params['user_address'],
+                'amount' => $params['amount'],
+                'appointment_time' => $params['appointment_time'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat']
+            ]);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public static function delete(array $params): bool
+    {
+        return ExternalConsultation::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public static function detail($params): array
+    {
+        return ExternalConsultation::findOrEmpty($params['id'])->toArray();
+    }
+}

+ 94 - 0
app/adminapi/validate/external/ExternalConsultationValidate.php

@@ -0,0 +1,94 @@
+<?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\adminapi\validate\external;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * ExternalConsultation验证器
+ * Class ExternalConsultationValidate
+ * @package app\adminapi\validate
+ */
+class ExternalConsultationValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return ExternalConsultationValidate
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function sceneAdd()
+    {
+        return $this->remove('id', true);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return ExternalConsultationValidate
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return ExternalConsultationValidate
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return ExternalConsultationValidate
+     * @author likeadmin
+     * @date 2025/04/23 17:10
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 43 - 0
app/common/model/external/ExternalConsultation.php

@@ -0,0 +1,43 @@
+<?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\external;
+
+
+use app\common\model\BaseModel;
+use app\common\model\goods\Goods;
+
+
+/**
+ * ExternalConsultation模型
+ * Class ExternalConsultation
+ * @package app\common\model
+ */
+class ExternalConsultation extends BaseModel
+{
+    
+    protected $name = 'external_consultation';
+
+    public function goods()
+    {
+        return $this->hasOne(Goods::class, 'id', 'goods_id')
+            ->field('id,goods_name,service_fee');
+    }
+    public function externalPlatform()
+    {
+        return $this->hasOne(ExternalPlatform::class, 'id', 'external_platform_id')
+            ->field('id,name,tel');
+    }
+    
+}