瀏覽代碼

Merge branch 'master' of http://git.bocai108.com:10180/Ethan/Home-Data

Jonlin 6 年之前
父節點
當前提交
a3112a67ba

+ 18 - 10
application/admin/controller/Order.php

@@ -4,6 +4,10 @@ namespace app\admin\controller;
 
 use think\Validate;
 use think\Lang;
+use app\admin\model\User;
+use app\admin\model\Product;
+
+use think\Db;
 
 class Order extends AdminControl
 {
@@ -22,34 +26,38 @@ class Order extends AdminControl
     {
         $model_order = Model('Order');
         $order_identity = input('order_identity', '');
-        $user_id = intval(input('user_id', 0));
-        $product_id = intval(input('product_id', 0));
+        $user_id = trim(input('user_id', ''));
+        $product_id = trim(input('product_id', ''));
         $timeRang = trim(input('timeRang', ''));
 
-         $where = [];
+        $where = [];
         if ($order_identity != '') {
             $where['order_identity'] = $order_identity;
         }
 
         if ($user_id) {
-            $where['user_id'] = $user_id;
+            $umodel = (new User())->getIdsByEmailLike($user_id);
+            $uids = array_merge([0], $umodel);
+            $where['user_id'] = ['IN', $uids];
         }
 
         if ($product_id) {
-            $where['product_id'] = $product_id;
+            $pmodel = (new Product())->getIdsByNameLike($product_id);
+            $pids = array_merge([0], $pmodel);
+            $where['product_id'] = ['IN', $pids];
         }
 
-        if ($timeRang){
-            $t1 = substr($timeRang,0,10);
-            $t2 = substr($timeRang,-10,10);
-            $where['order_buyTime']=[[">=",$t1],['<=',$t2]];
+        if ($timeRang) {
+            $t1 = substr($timeRang, 0, 10);
+            $t2 = substr($timeRang, -10, 10);
+            $where['order_buyTime'] = [[">=", $t1], ['<=', $t2]];
         }
 
         $order_list = $model_order->getOrdList($where, '*', 10);
         $this->assign('order_list', $order_list);
         $this->assign('show_page', $order_list->render());
         $this->setAdminCurItem('index');
-        $this->assign('oinput', ['order_identity' => input("order_identity",''), 'user_id' => input("user_id",''), 'product_id' => input("product_id",""),'timeRang'=>$timeRang]);
+        $this->assign('oinput', ['order_identity' => input("order_identity", ''), 'user_id' => input("user_id", ''), 'product_id' => input("product_id", ""), 'timeRang' => $timeRang]);
         return $this->fetch();
     }
 

+ 2 - 1
application/admin/controller/User.php

@@ -5,6 +5,7 @@ namespace app\admin\controller;
 use think\Validate;
 use think\Lang;
 use app\admin\model\Userinfo;
+use app\common\model\User as UserModel;
 
 class User extends AdminControl
 {
@@ -21,7 +22,7 @@ class User extends AdminControl
      */
     public function index()
     {
-        $model_user = Model('User');
+        $model_user = new UserModel();
         $title = input('post.title');
         $time = input('post.timeRang');
         if (!empty($time)) {

+ 14 - 2
application/admin/model/Order.php

@@ -6,17 +6,29 @@ use think\Model;
 
 class Order extends Model
 {
+    protected $pk = 'order_id';
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'user_id', 'user_id');
+    }
+
+    public function product()
+    {
+        return $this->belongsTo('Product', 'product_id', 'product_id');
+    }
+
     public function getOrdList($condition, $fileds = '*', $limit = 10)
     {
         if (empty($condition)) {
             $result = $this
                 ->field($fileds)
-                ->order('order_id','desc')
+                ->order('order_id', 'desc')
                 ->paginate($limit);
         } else {
             $result = $this
                 ->where($condition)
-                ->order('order_id','desc')
+                ->order('order_id', 'desc')
                 ->paginate($limit);
         }
         return $result;

+ 27 - 0
application/admin/model/Product.php

@@ -6,6 +6,28 @@ use think\Model;
 
 class Product extends Model
 {
+    protected $pk = 'product_id';
+
+    public function porder()
+    {
+        return $this->hasMany('Order', 'product_id', 'product_id');
+    }
+
+
+    //模糊查询时使用,返回地商品的ID数组
+    public function getIdsByNameLike($name)
+    {
+        $return = [];
+        $ret = $this->field('product_id')->where(['product_name' => ['like', "%$name%"]])->select();
+        if ($ret) {
+            foreach ($ret as $val) {
+                $return[] = $val->product_id;
+            }
+        }
+        return $return;
+    }
+
+
     public function getSonList($condition)
     {
         $result = $this
@@ -13,6 +35,7 @@ class Product extends Model
             ->paginate(10);
         return $result;
     }
+
     public function getFartherList()
     {
         $result = $this
@@ -20,6 +43,7 @@ class Product extends Model
             ->select();
         return $result;
     }
+
     public function findProduct($condition)
     {
         $result = $this
@@ -27,6 +51,7 @@ class Product extends Model
             ->find();
         return $result;
     }
+
     public function updateProduct($id, $data)
     {
         $result = $this
@@ -34,12 +59,14 @@ class Product extends Model
             ->update($data);
         return $result;
     }
+
     public function addProduct($data)
     {
         $result = $this
             ->insert($data);
         return $result;
     }
+
     public function deleteProduct($condition)
     {
         $result = $this

+ 29 - 0
application/admin/model/User.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+class User extends Model
+{
+    protected $pk = 'user_id';
+
+    public function uorder()
+    {
+        return $this->hasMany('Order', 'user_id', 'user_id');
+    }
+
+    //模糊查询时使用,返回地用户的ID数组
+    public function getIdsByEmailLike($email)
+    {
+        $return = [] ;
+        $ret = $this->field('user_id')->where(['user_email'=>['like', "%$email%"]])->select();
+        if ($ret){
+            foreach ($ret as $val){
+                $return[] = $val->user_id;
+            }
+        }
+        return $return ;
+    }
+
+}

+ 6 - 6
application/admin/view/order/index.html

@@ -50,11 +50,11 @@
                                value="{$oinput.order_identity}" class="layui-input">
                     </div>
                     <div class="layui-inline">
-                        <input type="text" name="user_id" placeholder="用户ID" autocomplete="off"
+                        <input type="text" name="user_id" placeholder="用户邮箱" autocomplete="off"
                                value="{$oinput.user_id}" class="layui-input">
                     </div>
                     <div class="layui-inline">
-                        <input type="text" name="product_id" placeholder="产品ID" autocomplete="off"
+                        <input type="text" name="product_id" placeholder="产品名称" autocomplete="off"
                                value="{$oinput.product_id}" class="layui-input">
                     </div>
 
@@ -84,8 +84,8 @@
             <tr>
                 <th>{$Think.lang.order_id}</th>
                 <th>{$Think.lang.order_identity}</th>
-                <th>{$Think.lang.order_uid}</th>
-                <th>{$Think.lang.order_pid}</th>
+                <th>用户邮箱</th>
+                <th>产品名称</th>
                 <th>{$Think.lang.order_daynumber}</th>
                 <th>{$Think.lang.order_buytime}</th>
                 <th>{$Think.lang.order_money}</th>
@@ -98,8 +98,8 @@
             <tr>
                 <th>{$order.order_id}</th>
                 <th>{$order.order_identity}</th>
-                <th>{$order.user_id}</th>
-                <th>{$order.product_id}</th>
+                <th>{$order.user.user_email}</th>
+                <th>{$order.product.product_name}</th>
                 <th>{$order.order_dayNumber}</th>
                 <th>{$order.order_buyTime}</th>
                 <th>{$order.order_money}</th>