Просмотр исходного кода

增加订单列表,订单详情

林海涛 1 год назад
Родитель
Сommit
b376a5e3b2

+ 31 - 1
app/common/model/shops/ShopOrderGoods.php

@@ -3,7 +3,8 @@ namespace app\common\model\shops;
 
 
 
 
 use app\common\model\BaseModel;
 use app\common\model\BaseModel;
-
+use app\common\model\dict\DictData;
+use think\facade\Cache;
 
 
 
 
 /**
 /**
@@ -50,4 +51,33 @@ class ShopOrderGoods extends BaseModel
         }
         }
         return $value;
         return $value;
     }
     }
+
+    public function goodsSpecsInventory()
+    {
+        return $this->hasOne(ShopGoodSpecsInventory::class,'id','goods_specs_inventory_id');
+    }
+
+    public function getDeliveryTypeTextAttr($value,$data):string
+    {
+        $default = Cache::get('DELIVERY_TYPE');
+        if (!$default) {
+            $status = DictData::whereIn('type_value', 'delivery_type')->column('name','value');
+            Cache::set('DELIVERY_TYPE', json_encode($status,true),5);
+        } else {
+            $status = json_decode($default,true);
+        }
+        return $status[$data['delivery_type']] ?? '';
+    }
+
+    public function getShopGoodsTypeTextAttr($value,$data):string
+    {
+        $default = Cache::get('SHOP_GOODS_TYPE');
+        if (!$default) {
+            $status = DictData::whereIn('type_value', 'shop_goods_type')->column('name','value');
+            Cache::set('SHOP_GOODS_TYPE', json_encode($status,true),5);
+        } else {
+            $status = json_decode($default,true);
+        }
+        return $status[$data['shop_goods_type']] ?? '';
+    }
 }
 }

+ 27 - 0
app/common/model/shops/ShopOrders.php

@@ -2,6 +2,8 @@
 namespace app\common\model\shops;
 namespace app\common\model\shops;
 
 
 
 
+use app\common\enum\PayEnum;
+use app\common\enum\RefundEnum;
 use app\common\model\BaseModel;
 use app\common\model\BaseModel;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorker;
 
 
@@ -24,4 +26,29 @@ class ShopOrders extends BaseModel
     {
     {
         return $this->hasMany(ShopOrderGoods::class, 'sn', 'sn');
         return $this->hasMany(ShopOrderGoods::class, 'sn', 'sn');
     }
     }
+
+    public function getPayWayTextAttr($value, $data)
+    {
+        return PayEnum::getPayDesc($data['paw_way']);
+    }
+
+    public function getPayStatusTextAttr($value, $data)
+    {
+        $status = [
+            0 => '未支付',
+            1 => '已支付',
+            2 => '已取消'
+        ];
+        return $status[$data['pay_status']] ?? '';
+    }
+
+    public function getRefundStatusTextAttr($value,$data)
+    {
+        $status = [
+            0 => '未退款',
+            1 => '已退款',
+            2 => '退款失败'
+        ];
+        return $status[$data['refund_status']] ?? '';
+    }
 }
 }

+ 65 - 3
app/workerapi/controller/shops/AddressController.php

@@ -3,12 +3,74 @@
 namespace app\workerapi\controller\shops;
 namespace app\workerapi\controller\shops;
 
 
 use app\workerapi\controller\BaseApiController;
 use app\workerapi\controller\BaseApiController;
-use app\workerapi\lists\shops\ShopAddressLists;
+use app\workerapi\logic\shops\ShopAddressLogic;
+use app\workerapi\validate\shops\ShopAddressValidate;
+
 
 
 class AddressController extends BaseApiController
 class AddressController extends BaseApiController
 {
 {
-    public function addressLists()
+    public function lists()
+    {
+        $result = ShopAddressLogic::getAddressList($this->userId);
+        return $this->data($result);
+    }
+
+    public function add()
+    {
+        $params = (new ShopAddressValidate())->post()->goCheck('add',[
+            'worker_id'=>$this->userId
+        ]);
+        $result = ShopAddressLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(ShopAddressLogic::getError());
+    }
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     */
+    public function edit()
+    {
+        $params = (new ShopAddressValidate())->post()->goCheck('edit',[
+            'worker_id'=>$this->userId
+        ]);
+        $result = ShopAddressLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(ShopAddressLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     */
+    public function delete()
+    {
+
+        $params = (new ShopAddressValidate())->goCheck('delete',[
+            'worker_id'=>$this->userId
+        ]);
+        ShopAddressLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public function detail()
     {
     {
-        return $this->dataLists(new ShopAddressLists());
+        $params = (new ShopAddressValidate())->goCheck('detail',[
+            'worker_id'=>$this->userId
+        ]);
+        $result = ShopAddressLogic::detail($params);
+        return $this->data($result);
     }
     }
 }
 }

+ 18 - 0
app/workerapi/controller/shops/OrderController.php

@@ -2,11 +2,29 @@
 namespace app\workerapi\controller\shops;
 namespace app\workerapi\controller\shops;
 
 
 use app\workerapi\controller\BaseApiController;
 use app\workerapi\controller\BaseApiController;
+use app\workerapi\lists\shops\ShopOrderLists;
+use app\workerapi\logic\shops\ShopOrderLogic;
+use app\workerapi\validate\shops\ShopOrderValidate;
 
 
 /**
 /**
  * 商城订单
  * 商城订单
  */
  */
 class OrderController extends BaseApiController
 class OrderController extends BaseApiController
 {
 {
+    public function lists()
+    {
+        return $this->dataLists(new ShopOrderLists());
+    }
 
 
+    public function detail()
+    {
+        $params = (new ShopOrderValidate())->goCheck('detail',[
+            'worker_id' => $this->userId,
+        ]);
+        $result = ShopOrderLogic::detail($params);
+        if (false === $result) {
+            return $this->fail(ShopOrderLogic::getError());
+        }
+        return $this->data($result);
+    }
 }
 }

+ 50 - 0
app/workerapi/lists/shops/ShopOrderLists.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\workerapi\lists\shops;
+
+use app\common\model\shops\ShopOrders;
+use app\workerapi\lists\BaseWorkerDataLists;
+use think\db\Query;
+
+class ShopOrderLists extends BaseWorkerDataLists
+{
+    protected $count = 0;
+    public function querySearch():array
+    {
+        $where = [];
+        $where[] = ['worker_id', '=', $this->userId];
+        if(isset($this->params['shop_order_type']) && $this->params['shop_order_type'] != 'all'){
+            $where[] = ['shop_order_type', '=', $this->params['shop_order_type']];
+        }
+        return $where;
+
+    }
+    public function lists():array
+    {
+        $lists = ShopOrders::with(['orderGoods'=>function(Query $query){
+            $query->field(['sn','goods_name','goods_image','number','service_fee','company_name','delivery_type','shop_goods_type','goods_specs_inventory_id','specs_type','custom_attribute_items','specs'])->append(['spec_arr','delivery_type_text','shop_goods_type_text']);
+            $query->with(['goodsSpecsInventory'=>function (Query $query) {
+                $query->field(['id','remaining_inventory']);
+            }]);
+        }])
+            ->where($this->querySearch())
+            ->field('id, sn, pay_time, paw_way, pay_status, refund_status, create_time, amount_total, amount')
+            ->append(['pay_way_text','pay_status_text','refund_status_text'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+        foreach($lists as &$item){
+            foreach($item['orderGoods'] as &$val){
+                $val['remaining_inventory'] = isset($val['goodsSpecsInventory']['remaining_inventory']) ? $val['goodsSpecsInventory']['remaining_inventory']:0;
+                unset($val['goodsSpecsInventory'],$val['custom_attribute_items'],$val['specs'],$val['sn'],$val['goods_specs_inventory_id']);
+            }
+        }
+        return $lists;
+    }
+
+    public function count(): int
+    {
+        return ShopOrders::where($this->querySearch())->count();
+    }
+}

+ 115 - 0
app/workerapi/logic/shops/ShopAddressLogic.php

@@ -0,0 +1,115 @@
+<?php
+namespace app\workerapi\logic\shops;
+use app\common\logic\BaseLogic;
+use app\common\model\article\Article;
+use app\common\model\decorate\DecoratePage;
+use app\common\model\decorate\DecorateTabbar;
+use app\common\model\setting\PostageRegion;
+use app\common\model\shops\ShopAddress;
+use app\common\model\user\UserAddress;
+use app\common\service\ConfigService;
+use app\common\service\FileService;
+use think\facade\Db;
+
+/**
+ * UserAddressLogic
+ * Class UserAddressLogic
+ * @package app\api\logic
+ */
+class ShopAddressLogic extends BaseLogic
+{
+    /**
+     * 获取用户地址列表
+     * @return array
+     */
+    public static function getAddressList($worker_id)
+    {
+        return ShopAddress::where('worker_id',$worker_id)->select()->toArray();
+    }
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            ShopAddress::create([
+                'worker_id' => $params['worker_id'],
+                'area' => $params['area'],
+                'address' => $params['address'],
+                'house_number' => $params['house_number'],
+                'contact_number' => $params['contact_number'],
+                'contact_people' => $params['contact_people'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            ShopAddress::where(['id'=> $params['id'],'worker_id'=>$params['worker_id']])->update([
+                'worker_id' => $params['worker_id'],
+                'area' => $params['area'],
+                'address' => $params['address'],
+                'house_number' => $params['house_number'],
+                'contact_number' => $params['contact_number'],
+                'contact_people' => $params['contact_people'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public static function delete(array $params): bool
+    {
+
+        return ShopAddress::where(['id'=> $params['id'],'worker_id'=>$params['worker_id']])->delete();
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public static function detail($params): array
+    {
+        return ShopAddress::where(['id'=> $params['id'],'worker_id'=>$params['worker_id']])->findOrEmpty()->toArray();
+    }
+}

+ 43 - 0
app/workerapi/logic/shops/ShopOrderLogic.php

@@ -0,0 +1,43 @@
+<?php
+namespace app\workerapi\logic\shops;
+use app\common\logic\BaseLogic;
+use app\common\model\article\Article;
+use app\common\model\decorate\DecoratePage;
+use app\common\model\decorate\DecorateTabbar;
+use app\common\model\setting\PostageRegion;
+use app\common\model\shops\ShopAddress;
+use app\common\model\shops\ShopOrders;
+use app\common\model\user\UserAddress;
+use app\common\service\ConfigService;
+use app\common\service\FileService;
+use think\db\Query;
+use think\facade\Db;
+
+
+/**
+ * 订单
+ */
+class ShopOrderLogic extends BaseLogic
+{
+
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/07/18 13:51
+     */
+    public static function detail($params): array
+    {
+        $detail = ShopOrders::with(['orderGoods'=>function(Query $query){
+            $query->field(['sn','goods_name','goods_image','number','service_fee','company_name','delivery_type','shop_goods_type','goods_specs_inventory_id','specs_type','custom_attribute_items','specs'])->append(['spec_arr','delivery_type_text','shop_goods_type_text']);
+        }])->field('id, sn, real_name,mobile, address,pay_time, paw_way,pay_sn, pay_status, refund_status, refund_transaction_id,create_time, amount_total, amount')
+        ->append(['pay_way_text','pay_status_text','refund_status_text'])->where(['sn'=> $params['sn'],'worker_id'=>$params['worker_id']])->findOrEmpty()->toArray();
+        foreach($detail['orderGoods'] as &$val){
+            unset($val['goodsSpecsInventory'],$val['custom_attribute_items'],$val['specs'],$val['sn'],$val['goods_specs_inventory_id']);
+        }
+        return $detail;
+    }
+}

+ 61 - 0
app/workerapi/validate/shops/ShopAddressValidate.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\workerapi\validate\shops;
+
+use app\common\validate\BaseValidate;
+
+class ShopAddressValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'worker_id' => 'require',
+        'area' => 'require',
+        'address' => 'require',
+        'house_number' => 'require',
+        'contact_number' => 'require',
+        'contact_people' => 'require',
+
+    ];
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'worker_id' => '用户ID',
+        'area' => '城市',
+        'address' => '具体地址',
+        'house_number' => '门牌号',
+        'contact_number' => '联系号码',
+        'contact_people' => '联系人',
+    ];
+
+    public function sceneAdd()
+    {
+        return $this->only(['worker_id','area','address','house_number','contact_number','contact_people']);
+    }
+
+    public function sceneEdit()
+    {
+        return $this->only(['id','worker_id','area','address','house_number','contact_number','contact_people']);
+    }
+
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * 获取场景详细信息
+     *
+     * 此方法主要用于获取当前场景的唯一标识符
+     * 它通过仅暴露场景ID来限制返回的信息量,以满足特定需求
+     *
+     * @return array 包含场景ID的数组
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+}

+ 51 - 0
app/workerapi/validate/shops/ShopOrderValidate.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\workerapi\validate\shops;
+
+use app\common\validate\BaseValidate;
+
+class ShopOrderValidate  extends BaseValidate
+{
+
+    protected $rule = [
+        'sn'=>'require',
+        'address' => 'require',
+        'real_name' => 'require',
+        'goods_specs_inventory_ids' => 'require|array',
+        'pay_way' => 'require',
+        'mobile' => 'require',
+    ];
+
+
+    protected $message = [
+        'sn.require' => '订单编号错误',
+        'pay_way.require' => '请选择支付方式',
+        'goods_specs_inventory_ids.require' => '订单商品不存在',
+        'mobile.require' => '联系电话不存在',
+        'real_name.require' => '联系人不存在',
+        'address.require' => '请填写地址',
+    ];
+
+
+    public function sceneDetail()
+    {
+        return $this->only(['sn']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return ShopGoodsValidate
+     * @author likeadmin
+     * @date 2024/08/04 11:07
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['ids']);
+    }
+
+    public function sceneEdit()
+    {
+        return $this->only(['id', 'number']);
+    }
+}