瀏覽代碼

订单详情页面处理

林海涛 1 年之前
父節點
當前提交
04835a7593

+ 93 - 77
app/adminapi/lists/shops/ShopOrdersLists.php

@@ -1,78 +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\lists\shops;
-
-
-use app\adminapi\lists\BaseAdminDataLists;
-use app\common\model\shops\ShopOrders;
-use app\common\lists\ListsSearchInterface;
-
-
-/**
- * ShopOrders列表
- * Class ShopOrdersLists
- * @package app\adminapi\listsshops
- */
-class ShopOrdersLists extends BaseAdminDataLists implements ListsSearchInterface
-{
-
-
-    /**
-     * @notes 设置搜索条件
-     * @return \string[][]
-     * @author likeadmin
-     * @date 2024/08/04 13:49
-     */
-    public function setSearch(): array
-    {
-        return [
-            '=' => ['shop_order_type', 'worker_id', 'real_name', 'mobile', 'pay_time', 'pay_status', 'pay_sn', 'paw_way', 'order_terminal', 'transaction_id', 'refund_status'],
-            '%like%' => ['sn', 'refund_transaction_id'],

-        ];
-    }
-
-
-    /**
-     * @notes 获取列表
-     * @return array
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @author likeadmin
-     * @date 2024/08/04 13:49
-     */
-    public function lists(): array
-    {
-        return ShopOrders::where($this->searchWhere)
-            ->field(['id', 'shop_order_type', 'worker_id', 'sn', 'real_name', 'mobile', 'address', 'pay_time', 'pay_status', 'pay_sn', 'paw_way', 'order_terminal', 'amount_total', 'amount', 'transaction_id', 'refund_status', 'refund_transaction_id'])
-            ->limit($this->limitOffset, $this->limitLength)
-            ->order(['id' => 'desc'])
-            ->select()
-            ->toArray();
-    }
-
-
-    /**
-     * @notes 获取数量
-     * @return int
-     * @author likeadmin
-     * @date 2024/08/04 13:49
-     */
-    public function count(): int
-    {
-        return ShopOrders::where($this->searchWhere)->count();
-    }
-
+<?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\shops;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\shops\ShopOrders;
+use app\common\lists\ListsSearchInterface;
+use think\db\Query;
+
+
+/**
+ * ShopOrders列表
+ * Class ShopOrdersLists
+ * @package app\adminapi\listsshops
+ */
+class ShopOrdersLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/08/04 13:49
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['shop_order_type', 'worker_id', 'real_name', 'mobile', 'pay_status', 'pay_sn', 'paw_way', 'order_terminal', 'transaction_id', 'refund_status'],
+            '%like%' => ['sn', 'refund_transaction_id'],
+
+        ];
+    }
+
+    public function querySearch():array
+    {
+        $where = [];
+        if(isset($this->params['pay_time']) && !empty($this->params['pay_time'])){
+            $time = [strtotime($this->params['pay_time'][0]), strtotime($this->params['pay_time'][1])];
+            $where[] = ['pay_time', 'between', $time];
+        }
+        return $where;
+    }
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/08/04 13:49
+     */
+    public function lists(): array
+    {
+        return ShopOrders::with([
+            'worker'=>function(Query $query) {
+                $query->field("id,worker_number,real_name");
+            },])
+            ->where($this->searchWhere)
+            ->where($this->querySearch())
+            ->field(['id', 'shop_order_type', 'worker_id', 'sn', 'real_name', 'mobile', 'address', 'pay_time', 'pay_status', 'pay_sn', 'paw_way', 'order_terminal', 'amount_total', 'amount', 'transaction_id', 'refund_status', 'refund_transaction_id'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/08/04 13:49
+     */
+    public function count(): int
+    {
+        return ShopOrders::where($this->searchWhere)->where($this->querySearch())->count();
+    }
+
 }

+ 7 - 1
app/adminapi/logic/shops/ShopOrdersLogic.php

@@ -17,6 +17,7 @@ namespace app\adminapi\logic\shops;
 
 use app\common\model\shops\ShopOrders;
 use app\common\logic\BaseLogic;
+use think\db\Query;
 use think\facade\Db;
 
 
@@ -131,6 +132,11 @@ class ShopOrdersLogic extends BaseLogic
      */
     public static function detail($params): array
     {
-        return ShopOrders::findOrEmpty($params['id'])->toArray();
+        return ShopOrders::with([
+            'worker'=>function(Query $query) {
+                $query->field("id,worker_number,real_name");
+            },'orderGoods'=>function(Query $query){
+                $query->field("id,sn,shop_goods_id,goods_name,goods_image,goods_banners,description,specs_type,custom_attribute_items,specs,number,service_total,service_fee")->append(['spec_arr']);
+            }])->findOrEmpty($params['id'])->toArray();
     }
 }

+ 34 - 2
app/common/model/shops/ShopOrderGoods.php

@@ -15,7 +15,39 @@ class ShopOrderGoods extends BaseModel
 {
     
     protected $name = 'shop_order_goods';
-    
+    protected $type = [
+        'goods_category_ids' =>  'array',
+        'goods_banners' => 'array',
+    ];
 
-    
+
+    public function getSpecArrAttr($value,$data)
+    {
+        $value = [];
+        if(in_array($data['specs_type'], [1,2])){
+           $value = json_decode($data['specs'],true);
+        }
+        if($data['specs_type']== 3){
+            $customAttributeItems = json_decode($data['custom_attribute_items'],true);
+            $specs = json_decode($data['specs'],true);
+            foreach ($specs as $k=>$v){
+                $specStrArr = explode('-',$v);
+                $val = [];
+                foreach($customAttributeItems as $kk=>$vv){
+                    if($specStrArr[0] == $vv['sign']){
+                        $val['title'] = $vv['title'];
+                        $val['sign'] = $vv['sign'];
+                        foreach($vv['spec_items'] as $kkk=>$vvv){
+                            if($specStrArr[1] == $vvv['spec_sign']){
+                                $val += $vvv;
+                            }
+                        }
+                        break;
+                    }
+                }
+                $value[] = $val;
+            }
+        }
+        return $value;
+    }
 }

+ 9 - 3
app/common/model/shops/ShopOrders.php

@@ -3,7 +3,7 @@ namespace app\common\model\shops;
 
 
 use app\common\model\BaseModel;
-
+use app\common\model\master_worker\MasterWorker;
 
 
 /**
@@ -15,7 +15,13 @@ class ShopOrders extends BaseModel
 {
     
     protected $name = 'shop_orders';
-    
+    public function worker()
+    {
+        return $this->belongsTo(MasterWorker::class, 'worker_id', 'id');
+    }
 
-    
+    public function orderGoods()
+    {
+        return $this->hasMany(ShopOrderGoods::class, 'sn', 'sn');
+    }
 }