Ver Fonte

修改商品代码

邹景立 há 3 anos atrás
pai
commit
d30dc421b5

+ 1 - 2
app/data/controller/api/Auth.php

@@ -92,5 +92,4 @@ abstract class Auth extends Controller
             $this->error('账户已被冻结!');
         }
     }
-
-}
+}

+ 5 - 5
app/data/controller/api/auth/News.php

@@ -43,8 +43,8 @@ class News extends Auth
      */
     public function getComment()
     {
-        $query = $this->_query(DataNewsXCollect::class)->where(['uuid' => $this->uuid, 'type' => 4]);
-        $result = $query->whereIn('status', [1, 2])->order('id desc')->page(true, false, false, 15);
+        $query = DataNewsXCollect::mQuery()->where(['uuid' => $this->uuid, 'type' => 4]);
+        $result = $query->whereIn('status', [1, 2])->order('id desc')->page(true, false);
         NewsService::instance()->buildListByUidAndCode($result);
         $this->success('获取评论列表成功', $result);
     }
@@ -118,7 +118,7 @@ class News extends Auth
     public function getCollect()
     {
         $map = ['uuid' => $this->uuid, 'type' => 1];
-        $query = $this->_query('DataNewsXCollect')->where($map);
+        $query = DataNewsXCollect::mQuery()->where($map);
         $result = $query->order('id desc')->page(true, false, false, 15);
         NewsService::instance()->buildListByUidAndCode($result['list']);
         $this->success('获取收藏记录成功!', $result);
@@ -174,7 +174,7 @@ class News extends Auth
      */
     public function getLike()
     {
-        $query = $this->_query(DataNewsXCollect::class);
+        $query = DataNewsXCollect::mQuery();
         $query->where(['uuid' => $this->uuid, 'type' => 2, 'status' => 2]);
         $result = $query->order('id desc')->page(true, false, false, 15);
         NewsService::instance()->buildListByUidAndCode($result['list']);
@@ -206,7 +206,7 @@ class News extends Auth
      */
     public function getHistory()
     {
-        $query = $this->_query(DataNewsXCollect::class);
+        $query = DataNewsXCollect::mQuery();
         $query->where(['uuid' => $this->uuid, 'type' => 3, 'status' => 2]);
         $result = $query->order('id desc')->page(true, false, false, 15);
         NewsService::instance()->buildListByUidAndCode($result['list']);

+ 1 - 1
app/data/controller/api/auth/Order.php

@@ -45,7 +45,7 @@ class Order extends Auth
     public function get()
     {
         $map = ['uuid' => $this->uuid, 'deleted_status' => 0];
-        $query = $this->_query(ShopOrder::class)->in('status')->equal('order_no');
+        $query = ShopOrder::mQuery()->in('status')->equal('order_no');
         $result = $query->where($map)->order('id desc')->page(true, false, false, 20);
         if (count($result['list']) > 0) OrderService::instance()->buildData($result['list']);
         $this->success('获取订单数据成功!', $result);

+ 1 - 1
app/data/controller/api/auth/Rebate.php

@@ -24,7 +24,7 @@ class Rebate extends Auth
     {
         $date = trim(input('date', date('Y-m')), '-');
         [$map, $year] = [['uuid' => $this->uuid], substr($date, 0, 4)];
-        $query = $this->_query('DataUserRebate')->where($map)->equal('type,status')->whereLike('date', "{$date}%");
+        $query = DataUserRebate::mQuery()->where($map)->equal('type,status')->whereLike('date', "{$date}%");
         $this->success('获取返利统计', array_merge($query->order('id desc')->page(true, false, false, 10), [
             'total' => [
                 '年度' => $this->_query('DataUserRebate')->where($map)->equal('type,status')->whereLike('date', "{$year}%")->db()->sum('amount'),

+ 1 - 1
app/data/controller/api/auth/Transfer.php

@@ -105,7 +105,7 @@ class Transfer extends Auth
      */
     public function get()
     {
-        $query = $this->_query(DataUserTransfer::mk())->where(['uuid' => $this->uuid]);
+        $query = DataUserTransfer::mQuery()->where(['uuid' => $this->uuid]);
         $result = $query->like('date,code')->in('status')->order('id desc')->page(true, false, false, 10);
         // 统计历史数据
         $map = [['uuid', '=', $this->uuid], ['status', '>', 0]];

+ 6 - 12
app/data/controller/base/Discount.php

@@ -2,6 +2,7 @@
 
 namespace app\data\controller\base;
 
+use app\data\model\BaseUserDiscount;
 use app\data\service\UserUpgradeService;
 use think\admin\Controller;
 
@@ -13,12 +14,6 @@ use think\admin\Controller;
 class Discount extends Controller
 {
     /**
-     * 绑定数据表
-     * @var string
-     */
-    private $table = 'BaseUserDiscount';
-
-    /**
      * 折扣方案管理
      * @auth true
      * @menu true
@@ -29,7 +24,7 @@ class Discount extends Controller
     public function index()
     {
         $this->title = '折扣方案管理';
-        $query = $this->_query($this->table);
+        $query = BaseUserDiscount::mQuery();
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
 
@@ -53,7 +48,7 @@ class Discount extends Controller
      */
     public function add()
     {
-        $this->_form($this->table, 'form');
+        BaseUserDiscount::mForm('form');
     }
 
     /**
@@ -65,7 +60,7 @@ class Discount extends Controller
      */
     public function edit()
     {
-        $this->_form($this->table, 'form');
+        BaseUserDiscount::mForm('form');
     }
 
     /**
@@ -97,7 +92,7 @@ class Discount extends Controller
      */
     public function state()
     {
-        $this->_save($this->table);
+        BaseUserDiscount::mSave();
     }
 
     /**
@@ -107,7 +102,6 @@ class Discount extends Controller
      */
     public function remove()
     {
-        $this->_delete($this->table);
+        BaseUserDiscount::mDelete();
     }
-
 }

+ 6 - 6
app/data/controller/base/Message.php

@@ -2,6 +2,7 @@
 
 namespace app\data\controller\base;
 
+use app\data\model\BaseUserMessage;
 use think\admin\Controller;
 
 /**
@@ -28,7 +29,7 @@ class Message extends Controller
     public function index()
     {
         $this->title = '系统通知管理';
-        $query = $this->_query($this->table);
+        $query = BaseUserMessage::mQuery();
         $query->like('name')->equal('status')->dateBetween('create_at');
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
@@ -42,7 +43,7 @@ class Message extends Controller
      */
     public function add()
     {
-        $this->_form($this->table, 'form');
+        BaseUserMessage::mForm('form');
     }
 
     /**
@@ -54,7 +55,7 @@ class Message extends Controller
      */
     public function edit()
     {
-        $this->_form($this->table, 'form');
+        BaseUserMessage::mForm('form');
     }
 
     /**
@@ -75,7 +76,7 @@ class Message extends Controller
      */
     public function state()
     {
-        $this->_save($this->table, $this->_vali([
+        BaseUserMessage::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));
@@ -88,7 +89,6 @@ class Message extends Controller
      */
     public function remove()
     {
-        $this->_delete($this->table);
+        BaseUserMessage::mDelete();
     }
-
 }

+ 6 - 6
app/data/controller/base/Payment.php

@@ -2,6 +2,7 @@
 
 namespace app\data\controller\base;
 
+use app\data\model\BaseUserPayment;
 use app\data\service\PaymentService;
 use app\data\service\UserAdminService;
 use think\admin\Controller;
@@ -37,7 +38,7 @@ class Payment extends Controller
     public function index()
     {
         $this->title = '支付通道管理';
-        $query = $this->_query($this->table);
+        $query = BaseUserPayment::mQuery();
         $query->where(['deleted' => 0])->order('sort desc,id desc');
         $query->like('name,code')->equal('type,status')->dateBetween('create_at')->page();
     }
@@ -52,7 +53,7 @@ class Payment extends Controller
     public function add()
     {
         $this->title = '添加支付通道';
-        $this->_form($this->table, 'form');
+        BaseUserPayment::mForm('form');
     }
 
     /**
@@ -65,7 +66,7 @@ class Payment extends Controller
     public function edit()
     {
         $this->title = '编辑支付通道';
-        $this->_form($this->table, 'form');
+        BaseUserPayment::mForm('form');
     }
 
     /**
@@ -113,7 +114,7 @@ class Payment extends Controller
      */
     public function state()
     {
-        $this->_save($this->table, $this->_vali([
+        BaseUserPayment::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));
@@ -126,7 +127,6 @@ class Payment extends Controller
      */
     public function remove()
     {
-        $this->_delete($this->table);
+        BaseUserPayment::mDelete();
     }
-
 }

+ 18 - 16
app/data/controller/base/Upgrade.php

@@ -14,12 +14,6 @@ use think\admin\Controller;
 class Upgrade extends Controller
 {
     /**
-     * 绑定数据表
-     * @var string
-     */
-    private $table = 'BaseUserUpgrade';
-
-    /**
      * 用户等级管理
      * @auth true
      * @menu true
@@ -30,7 +24,7 @@ class Upgrade extends Controller
     public function index()
     {
         $this->title = '用户等级管理';
-        $this->_query(BaseUserUpgrade::class)->order('number asc')->page();
+        BaseUserUpgrade::mQuery()->order('number asc')->page();
     }
 
     /**
@@ -56,7 +50,7 @@ class Upgrade extends Controller
      */
     public function add()
     {
-        $this->_form(BaseUserUpgrade::class, 'form');
+        BaseUserUpgrade::mForm('form');
     }
 
     /**
@@ -68,7 +62,7 @@ class Upgrade extends Controller
      */
     public function edit()
     {
-        $this->_form(BaseUserUpgrade::class, 'form');
+        BaseUserUpgrade::mForm('form');
     }
 
     /**
@@ -107,15 +101,20 @@ class Upgrade extends Controller
     /**
      * 表单结果处理
      * @param boolean $state
+     * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     public function _form_result(bool $state)
     {
         if ($state) {
-            $order = 'number asc,utime desc';
-            if (input('old_number', 100) <= input('number', 0)) $order = 'number asc,utime asc';
-            foreach (BaseUserUpgrade::mk()->order($order)->cursor() as $k => $vo) {
-                BaseUserUpgrade::mk()->where(['id' => $vo['id']])->update(['number' => $k]);
+            if (input('old_number', 100) <= input('number', 0)) {
+                $order = 'number asc,utime asc';
+            } else {
+                $order = 'number asc,utime desc';
+            }
+            foreach (BaseUserUpgrade::mk()->order($order)->select() as $number => $upgrade) {
+                $upgrade->save(['number' => $number]);
             }
         }
     }
@@ -136,7 +135,7 @@ class Upgrade extends Controller
      */
     public function state()
     {
-        $this->_save(BaseUserUpgrade::class);
+        BaseUserUpgrade::mSave();
     }
 
     /**
@@ -146,13 +145,15 @@ class Upgrade extends Controller
      */
     public function remove()
     {
-        $this->_delete(BaseUserUpgrade::class);
+        BaseUserUpgrade::mDelete();
     }
 
     /**
      * 状态变更处理
      * @auth true
+     * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     protected function _save_result()
     {
@@ -161,11 +162,12 @@ class Upgrade extends Controller
 
     /**
      * 删除结果处理
+     * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     protected function _delete_result()
     {
         $this->_form_result(true);
     }
-
 }

+ 6 - 7
app/data/controller/news/Item.php

@@ -26,7 +26,7 @@ class Item extends Controller
     public function index()
     {
         $this->title = '文章内容管理';
-        $query = $this->_query(DataNewsItem::class);
+        $query = DataNewsItem::mQuery();
         $query->like('mark,name')->dateBetween('create_at');
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
@@ -40,7 +40,7 @@ class Item extends Controller
      */
     public function select()
     {
-        $query = $this->_query(DataNewsItem::class);
+        $query = DataNewsItem::mQuery();
         $query->equal('status')->like('name')->dateBetween('create_at');
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
@@ -64,7 +64,7 @@ class Item extends Controller
     public function add()
     {
         $this->title = '添加文章内容';
-        $this->_form(DataNewsItem::class, 'form');
+        DataNewsItem::mForm('form');
     }
 
     /**
@@ -77,7 +77,7 @@ class Item extends Controller
     public function edit()
     {
         $this->title = '编辑文章内容';
-        $this->_form(DataNewsItem::class, 'form');
+        DataNewsItem::mForm('form');
     }
 
     /**
@@ -119,7 +119,7 @@ class Item extends Controller
      */
     public function state()
     {
-        $this->_save(DataNewsItem::class, $this->_vali([
+        DataNewsItem::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));
@@ -132,7 +132,6 @@ class Item extends Controller
      */
     public function remove()
     {
-        $this->_delete(DataNewsItem::class);
+        DataNewsItem::mDelete();
     }
-
 }

+ 5 - 6
app/data/controller/news/Mark.php

@@ -22,7 +22,7 @@ class Mark extends Controller
     public function index()
     {
         $this->title = '文章标签管理';
-        $query = $this->_query(DataNewsMark::class);
+        $query = DataNewsMark::mQuery();
         $query->like('name')->equal('status')->dateBetween('create_at');
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
@@ -36,7 +36,7 @@ class Mark extends Controller
      */
     public function add()
     {
-        $this->_form(DataNewsMark::class, 'form');
+        DataNewsMark::mForm('form');
     }
 
     /**
@@ -48,7 +48,7 @@ class Mark extends Controller
      */
     public function edit()
     {
-        $this->_form(DataNewsMark::class, 'form');
+        DataNewsMark::mForm('form');
     }
 
     /**
@@ -58,7 +58,7 @@ class Mark extends Controller
      */
     public function state()
     {
-        $this->_save(DataNewsMark::class, $this->_vali([
+        DataNewsMark::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));
@@ -71,7 +71,6 @@ class Mark extends Controller
      */
     public function remove()
     {
-        $this->_delete(DataNewsMark::class);
+        DataNewsMark::mDelete();
     }
-
 }

+ 5 - 5
app/data/controller/shop/Cate.php

@@ -24,7 +24,7 @@ class Cate extends Controller
     public function index()
     {
         $this->title = "商品分类管理";
-        $query = $this->_query(ShopGoodsCate::class)->like('name')->dateBetween('create_at');
+        $query = ShopGoodsCate::mQuery()->like('name')->dateBetween('create_at');
         $query->equal('status')->where(['deleted' => 0])->order('sort desc,id desc')->page(false);
     }
 
@@ -49,7 +49,7 @@ class Cate extends Controller
      */
     public function add()
     {
-        $this->_form(ShopGoodsCate::mk(), 'form');
+        ShopGoodsCate::mForm('form');
     }
 
     /**
@@ -61,7 +61,7 @@ class Cate extends Controller
      */
     public function edit()
     {
-        $this->_form(ShopGoodsCate::class, 'form');
+        ShopGoodsCate::mForm('form');
     }
 
     /**
@@ -91,7 +91,7 @@ class Cate extends Controller
      */
     public function state()
     {
-        $this->_save(ShopGoodsCate::mk(), $this->_vali([
+        ShopGoodsCate::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));
@@ -104,6 +104,6 @@ class Cate extends Controller
      */
     public function remove()
     {
-        $this->_delete(ShopGoodsCate::mk());
+        ShopGoodsCate::mDelete();
     }
 }

+ 17 - 13
app/data/controller/shop/Goods.php

@@ -2,7 +2,10 @@
 
 namespace app\data\controller\shop;
 
+use app\data\model\BaseUserDiscount;
+use app\data\model\BaseUserPayment;
 use app\data\model\ShopGoods;
+use app\data\model\ShopGoodsItem;
 use app\data\model\ShopGoodsStock;
 use app\data\service\ExpressService;
 use app\data\service\GoodsService;
@@ -34,12 +37,14 @@ class Goods extends Controller
     public function index()
     {
         $this->title = '商品数据管理';
-        $query = $this->_query(ShopGoods::class);
+
+        $query = ShopGoods::mQuery();
         // 加载对应数据
         $this->type = $this->request->get('type', 'index');
         if ($this->type === 'index') $query->where(['deleted' => 0]);
         elseif ($this->type === 'recycle') $query->where(['deleted' => 1]);
         else $this->error("无法加载 {$this->type} 数据列表!");
+
         // 列表排序并显示
         $query->like('code,name')->like('marks,cateids', ',');
         $query->equal('status,vip_entry,truck_type,rebate_type')->order('sort desc,id desc')->page();
@@ -54,7 +59,7 @@ class Goods extends Controller
      */
     public function select()
     {
-        $query = $this->_query(ShopGoods::mk());
+        $query = ShopGoods::mQuery();
         $query->equal('status')->like('code,name,marks')->in('cateids');
         $query->where(['deleted' => 0])->order('sort desc,id desc')->page();
     }
@@ -84,7 +89,7 @@ class Goods extends Controller
     {
         $this->mode = 'add';
         $this->title = '添加商品数据';
-        $this->_form(ShopGoods::mk(), 'form', 'code');
+        ShopGoods::mForm('form', 'code');
     }
 
     /**
@@ -98,7 +103,7 @@ class Goods extends Controller
     {
         $this->mode = 'edit';
         $this->title = '编辑商品数据';
-        $this->_form(ShopGoods::mk(), 'form', 'code');
+        ShopGoods::mForm('form', 'code');
     }
 
     /**
@@ -112,7 +117,7 @@ class Goods extends Controller
     {
         $this->mode = 'copy';
         $this->title = '复制编辑商品';
-        $this->_form(ShopGoods::mk(), 'form', 'code');
+        ShopGoods::mForm('form', 'code');
     }
 
     /**
@@ -147,11 +152,11 @@ class Goods extends Controller
             $this->cates = GoodsService::instance()->getCateData();
             $this->trucks = ExpressService::instance()->templates();
             $this->upgrades = UserUpgradeService::instance()->levels();
-            $this->payments = $this->app->db->name('BaseUserPayment')->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('type,code,name', 'code');
-            $this->discounts = $this->app->db->name('BaseUserDiscount')->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('id,name,items', 'id');
+            $this->payments = BaseUserPayment::mk()->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('type,code,name', 'code');
+            $this->discounts = BaseUserDiscount::mk()->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('id,name,items', 'id');
             // 商品规格处理
             $fields = 'goods_sku `sku`,goods_code,goods_spec `key`,price_selling `selling`,price_market `market`,number_virtual `virtual`,number_express `express`,reward_balance `balance`,reward_integral `integral`,status';
-            $data['data_items'] = json_encode($this->app->db->name('ShopGoodsItem')->where(['goods_code' => $data['code']])->column($fields, 'goods_spec'), JSON_UNESCAPED_UNICODE);
+            $data['data_items'] = json_encode(ShopGoodsItem::mk()->where(['goods_code' => $data['code']])->column($fields, 'goods_spec'), JSON_UNESCAPED_UNICODE);
         } elseif ($this->request->isPost()) {
             if (empty($data['cover'])) $this->error('商品图片不能为空!');
             if (empty($data['slider'])) $this->error('轮播图片不能为空!');
@@ -167,8 +172,8 @@ class Goods extends Controller
             if (empty($count)) $this->error('无效的的商品价格信息!');
             $data['marks'] = arr2str($data['marks'] ?? []);
             $data['payment'] = arr2str($data['payment'] ?? []);
-            $this->app->db->name('ShopGoodsItem')->where(['goods_code' => $data['code']])->update(['status' => 0]);
-            foreach ($items as $item) data_save('ShopGoodsItem', [
+            ShopGoodsItem::mk()->where(['goods_code' => $data['code']])->update(['status' => 0]);
+            foreach ($items as $item) data_save(ShopGoodsItem::class, [
                 'goods_sku'       => $item['sku'],
                 'goods_spec'      => $item['key'],
                 'goods_code'      => $data['code'],
@@ -243,7 +248,7 @@ class Goods extends Controller
      */
     public function state()
     {
-        $this->_save(ShopGoods::mk(), $this->_vali([
+        ShopGoods::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]), 'code');
@@ -256,10 +261,9 @@ class Goods extends Controller
      */
     public function remove()
     {
-        $this->_save(ShopGoods::mk(), $this->_vali([
+        ShopGoods::mSave($this->_vali([
             'deleted.in:0,1'  => '状态值范围异常!',
             'deleted.require' => '状态值不能为空!',
         ]), 'code');
     }
-
 }

+ 6 - 7
app/data/controller/shop/Mark.php

@@ -22,7 +22,7 @@ class Mark extends Controller
     public function index()
     {
         $this->title = '商品标签管理';
-        $query = $this->_query(ShopGoodsMark::mk());
+        $query = ShopGoodsMark::mQuery();
         $query->like('name')->dateBetween('create_at');
         $query->equal('status')->order('sort desc,id desc')->page();
     }
@@ -36,7 +36,7 @@ class Mark extends Controller
      */
     public function select()
     {
-        $this->_query(ShopGoodsMark::mk())->order('sort desc,id desc')->page();
+        ShopGoodsMark::mQuery()->order('sort desc,id desc')->page();
     }
 
     /**
@@ -48,7 +48,7 @@ class Mark extends Controller
      */
     public function add()
     {
-        $this->_form(ShopGoodsMark::mk(), 'form');
+        ShopGoodsMark::mForm('form');
     }
 
     /**
@@ -60,7 +60,7 @@ class Mark extends Controller
      */
     public function edit()
     {
-        $this->_form(ShopGoodsMark::mk(), 'form');
+        ShopGoodsMark::mForm('form');
     }
 
     /**
@@ -70,7 +70,7 @@ class Mark extends Controller
      */
     public function state()
     {
-        $this->_save(ShopGoodsMark::mk());
+        ShopGoodsMark::mSave();
     }
 
     /**
@@ -80,7 +80,6 @@ class Mark extends Controller
      */
     public function remove()
     {
-        $this->_delete(ShopGoodsMark::mk());
+        ShopGoodsMark::mDelete();
     }
-
 }

+ 11 - 11
app/data/controller/shop/Order.php

@@ -20,12 +20,6 @@ use think\exception\HttpResponseException;
 class Order extends Controller
 {
     /**
-     * 绑定数据表
-     * @var string
-     */
-    private $table = 'ShopOrder';
-
-    /**
      * 支付方式
      * @var array
      */
@@ -56,23 +50,29 @@ class Order extends Controller
         foreach (ShopOrder::mk()->field('status,count(1) total')->group('status')->cursor() as $vo) {
             [$this->total["t{$vo['status']}"] = $vo['total'], $this->total["ta"] += $vo['total']];
         }
+
         // 订单列表查询
-        $query = $this->_query(ShopOrder::mk());
+        $query = ShopOrder::mQuery();
         $query->like('order_no,truck_name,truck_phone,truck_province|truck_area|truck_address#address,truck_send_no,truck_send_name');
         $query->equal('status,payment_type,payment_status')->dateBetween('create_at,payment_datetime,cancel_datetime,truck_datetime,truck_send_datetime');
+
         // 发货信息搜索
-        $db = $this->_query(ShopOrderSend::class)->like('address_name#truck_address_name,address_phone#truck_address_phone,address_province|address_city|address_area|address_content#truck_address_content')->db();
+        $db = ShopOrderSend::mQuery()->like('address_name#truck_address_name,address_phone#truck_address_phone,address_province|address_city|address_area|address_content#truck_address_content')->db();
         if ($db->getOptions('where')) $query->whereRaw("order_no in {$db->field('order_no')->buildSql()}");
+
         // 用户搜索查询
-        $db = $this->_query(DataUser::class)->like('phone#user_phone,nickname#user_nickname')->db();
+        $db = DataUser::mQuery()->like('phone#user_phone,nickname#user_nickname')->db();
         if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
+
         // 代理搜索查询
-        $db = $this->_query(DataUser::class)->like('phone#from_phone,nickname#from_nickname')->db();
+        $db = DataUser::mQuery()->like('phone#from_phone,nickname#from_nickname')->db();
         if ($db->getOptions('where')) $query->whereRaw("puid1 in {$db->field('id')->buildSql()}");
+
         // 列表选项卡
         if (is_numeric($this->type = trim(input('type', 'ta'), 't'))) {
             $query->where(['status' => $this->type]);
         }
+
         // 分页排序处理
         $query->where(['deleted_status' => 0])->order('id desc')->page();
     }
@@ -102,7 +102,7 @@ class Order extends Controller
     public function audit()
     {
         if ($this->request->isGet()) {
-            $this->_form(ShopOrder::mk(), '', 'order_no');
+            ShopOrder::mForm('', 'order_no');
         } else {
             $data = $this->_vali([
                 'order_no.require' => '订单单号不能为空!',

+ 13 - 6
app/data/controller/shop/Send.php

@@ -3,6 +3,7 @@
 namespace app\data\controller\shop;
 
 use app\data\model\BasePostageCompany;
+use app\data\model\DataUser;
 use app\data\model\ShopOrder;
 use app\data\model\ShopOrderSend;
 use app\data\service\ExpressService;
@@ -38,20 +39,25 @@ class Send extends Controller
             $this->total["t{$vo['status']}"] = $vo['total'];
             $this->total["ta"] += $vo['total'];
         }
+
         // 订单列表查询
-        $query = $this->_query(ShopOrderSend::class);
+        $query = ShopOrderSend::mQuery();
         $query->dateBetween('address_datetime,send_datetime')->equal('status')->like('send_number#truck_number,order_no');
         $query->like('address_phone,address_name,address_province|address_city|address_area|address_content#address_content');
+
         // 用户搜索查询
-        $db = $this->_query('DataUser')->like('phone#user_phone,nickname#user_nickname')->db();
+        $db = DataUser::mQuery()->like('phone#user_phone,nickname#user_nickname')->db();
         if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
+
         // 订单搜索查询
         $db = ShopOrder::mk()->whereIn('status', [4, 5, 6])->where(['truck_type' => 1]);
         $query->whereRaw("order_no in {$db->field('order_no')->buildSql()}");
+
         // 列表选项卡状态
         if (is_numeric($this->type = trim(input('type', 'ta'), 't'))) {
             $query->where(['status' => $this->type]);
         }
+
         // 列表排序显示
         $query->order('id desc')->page();
     }
@@ -102,7 +108,7 @@ class Send extends Controller
             $query = BasePostageCompany::mk()->where(['deleted' => 0, 'status' => 1]);
             $this->items = $query->order('sort desc,id desc')->select()->toArray();
         }
-        $this->_form('ShopOrderSend', 'truck_form', 'order_no');
+        ShopOrderSend::mForm('truck_form', 'order_no');
     }
 
     /**
@@ -118,22 +124,23 @@ class Send extends Controller
             $map = ['order_no' => $vo['order_no']];
             $order = ShopOrder::mk()->where($map)->find();
             if (empty($order)) $this->error('订单查询异常,请稍候再试!');
+
             // 配送快递公司填写
             $map = ['code_1|code_2|code_3' => $vo['company_code']];
             $company = BasePostageCompany::mk()->where($map)->find();
             if (empty($company)) $this->error('配送快递公司异常,请重新选择快递公司!');
+
             $vo['status'] = 2;
             $vo['company_name'] = $company['name'];
             $vo['send_datetime'] = $vo['send_datetime'] ?? date('Y-m-d H:i:s');
-            // 更新订单发货状态
             if ($order['status'] === 3) {
                 $map = ['order_no' => $vo['order_no']];
+                // 更新订单发货状态
                 ShopOrder::mk()->where($map)->update(['status' => 4]);
             }
         }
     }
-
-
+    
     /**
      * 快递追踪查询
      * @auth true

+ 1 - 1
app/data/controller/total/Portal.php

@@ -28,7 +28,7 @@ class Portal extends Controller
         $this->goodsTotal = ShopGoods::mk()->cache(true, 60)->where(['deleted' => 0])->count();
         $this->orderTotal = ShopOrder::mk()->cache(true, 60)->whereRaw('status >= 4')->count();
         $this->amountTotal = ShopOrder::mk()->cache(true, 60)->whereRaw('status >= 4')->sum('amount_total');
-        // 近十天用户及交易趋势
+        // 近十天用户及交易趋势
         $this->days = $this->app->cache->get('portals', []);
         if (empty($this->days)) {
             for ($i = 15; $i >= 0; $i--) {

+ 14 - 9
app/data/controller/user/Admin.php

@@ -39,15 +39,19 @@ class Admin extends Controller
 
         // 设置页面标题
         $this->title = '普通用户管理';
+
         // 创建查询对象
-        $query = $this->_query(DataUser::class)->order('id desc');
+        $query = DataUser::mQuery()->order('id desc');
+
         // 数据筛选选项
         $this->type = ltrim(input('type', 'ta'), 't');
         if (is_numeric($this->type)) $query->where(['vip_code' => $this->type]);
         elseif ($this->type === 'o') $query->whereNotIn('vip_code', array_keys($ls));
+
         // 用户搜索查询
-        $db = $this->_query(DataUser::class)->equal('vip_code#from_vipcode')->like('phone#from_phone,username|nickname#from_username')->db();
+        $db = DataUser::mQuery()->equal('vip_code#from_vipcode')->like('phone#from_phone,username|nickname#from_username')->db();
         if ($db->getOptions('where')) $query->whereRaw("pid1 in {$db->field('id')->buildSql()}");
+
         // 数据查询分页
         $query->like('phone,username|nickname#username')->equal('status,vip_code')->dateBetween('create_at')->page();
     }
@@ -74,7 +78,7 @@ class Admin extends Controller
     {
         $this->title = '用户团队关系';
         $map = ['pid1' => input('from', 0)];
-        $this->_query(DataUser::class)->where($map)->page(false);
+        DataUser::mQuery()->where($map)->page(false);
     }
 
     /**
@@ -118,9 +122,7 @@ class Admin extends Controller
         $user = DataUser::mk()->where($map)->find();
         if (empty($user)) $this->error('用户不符合操作要求!');
         // 修改指定用户代理数据
-        DataUser::mk()->where(['id' => $user['id']])->update([
-            'pid0' => 0, 'pid1' => 0, 'pid2' => 0, 'pids' => 1, 'path' => '-', 'layer' => 1,
-        ]);
+        $user->save(['pid0' => 0, 'pid1' => 0, 'pid2' => 0, 'pids' => 1, 'path' => '-', 'layer' => 1]);
         // 刷新用户等级及上级等级
         UserUpgradeService::instance()->upgrade($user['id'], true);
         sysoplog('前端用户管理', "设置用户[{$map['id']}]为总部用户");
@@ -139,13 +141,16 @@ class Admin extends Controller
         if ($this->request->isGet()) {
             $this->upgrades = UserUpgradeService::instance()->levels();
             $data = $this->_vali(['uuid.require' => '待操作UID不能为空!']);
+
             // 排除下级用户
             $path = DataUser::mk()->where(['id' => $data['uuid']])->value('path', '-');
             $subids = DataUser::mk()->whereLike('path', "{$path}{$data['uuid']}-%")->column('id');
-            $query = $this->_query(DataUser::class)->order('id desc')->whereNotIn('id', array_merge($subids, array_values($data)));
+            $query = DataUser::mQuery()->order('id desc')->whereNotIn('id', array_merge($subids, array_values($data)));
+
             // 用户搜索查询
-            $db = $this->_query(DataUser::class)->equal('vip_code#from_vipcode')->like('phone#from_phone,username|nickname#from_username')->db();
+            $db = DataUser::mQuery()->equal('vip_code#from_vipcode')->like('phone#from_phone,username|nickname#from_username')->db();
             if ($db->getOptions('where')) $query->whereRaw("pid1 in {$db->field('id')->buildSql()}");
+
             // 数据查询分页
             $query->like('phone,username|nickname#username')->whereRaw('vip_code>0')->equal('status,vip_code')->dateBetween('create_at')->page();
         } else {
@@ -172,7 +177,7 @@ class Admin extends Controller
      */
     public function state()
     {
-        $this->_save(DataUser::class, $this->_vali([
+        DataUser::mSave($this->_vali([
             'status.in:0,1'  => '状态值范围异常!',
             'status.require' => '状态值不能为空!',
         ]));

+ 6 - 12
app/data/controller/user/Balance.php

@@ -4,6 +4,7 @@ namespace app\data\controller\user;
 
 use app\admin\model\SystemUser;
 use app\data\model\DataUser;
+use app\data\model\DataUserBalance;
 use app\data\service\UserAdminService;
 use app\data\service\UserBalanceService;
 use app\data\service\UserUpgradeService;
@@ -19,12 +20,6 @@ use think\admin\service\AdminService;
 class Balance extends Controller
 {
     /**
-     * 绑定数据表
-     * @var string
-     */
-    private $table = 'DataUserBalance';
-
-    /**
      * 余额充值管理
      * @auth true
      * @menu true
@@ -38,11 +33,11 @@ class Balance extends Controller
         // 统计用户余额
         $this->balance = UserBalanceService::instance()->amount(0);
         // 现有余额类型
-        $this->names = $this->app->db->name($this->table)->group('name')->column('name');
+        $this->names = DataUserBalance::mk()->group('name')->column('name');
         // 创建查询对象
-        $query = $this->_query($this->table)->equal('name,upgrade');
+        $query = DataUserBalance::mQuery()->equal('name,upgrade');
         // 用户搜索查询
-        $db = $this->_query('DataUser')->like('phone#user_phone,nickname#user_nickname')->db();
+        $db = DataUser::mQuery()->like('phone#user_phone,nickname#user_nickname')->db();
         if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
         // 数据查询分页
         $query->where(['deleted' => 0])->like('code,remark')->dateBetween('create_at')->order('id desc')->page();
@@ -76,7 +71,7 @@ class Balance extends Controller
         $data = $this->_vali(['uuid.require' => '用户UID不能为空!']);
         $this->user = DataUser::mk()->where(['id' => $data['uuid']])->find();
         if (empty($this->user)) $this->error('待充值的用户不存在!');
-        $this->_form($this->table, 'form');
+        DataUserBalance::mForm('form');
     }
 
     /**
@@ -120,8 +115,7 @@ class Balance extends Controller
      */
     public function remove()
     {
-        $db = $this->app->db->name($this->table);
-        $this->_delete($db->whereLike('code', "B%"));
+        DataUserBalance::mDelete('', [['code', 'like', 'B%']]);
     }
 
     /**

+ 3 - 4
app/data/controller/user/Message.php

@@ -24,7 +24,7 @@ class Message extends Controller
     public function index()
     {
         $this->title = '短信发送管理';
-        $query = $this->_query(DataUserMessage::mk());
+        $query = DataUserMessage::mQuery();
         $query->equal('status')->like('phone,content');
         $query->dateBetween('create_at')->order('id desc')->page();
     }
@@ -57,7 +57,6 @@ class Message extends Controller
      */
     public function remove()
     {
-        $this->_delete(DataUserMessage::mk());
+        DataUserMessage::mDelete();
     }
-
-}
+}

+ 1 - 2
app/data/controller/user/Rebate.php

@@ -32,7 +32,7 @@ class Rebate extends Controller
         $this->types = RebateService::PRIZES;
         $this->rebate = UserRebateService::instance()->amount(0);
         // 创建查询对象
-        $query = $this->_query(DataUserRebate::class)->equal('type')->like('name,order_no');
+        $query = DataUserRebate::mQuery()->equal('type')->like('name,order_no');
         // 会员条件查询
         $db = $this->_query('DataUser')->like('nickname#order_nickname,phone#order_phone')->db();
         if ($db->getOptions('where')) $query->whereRaw("order_uuid in {$db->field('id')->buildSql()}");
@@ -90,5 +90,4 @@ class Rebate extends Controller
             $this->success('奖励修改成功');
         }
     }
-
 }

+ 1 - 1
app/data/controller/user/Transfer.php

@@ -139,7 +139,7 @@ class Transfer extends Controller
     private function _audit()
     {
         if ($this->request->isGet()) {
-            $this->_form(DataUserTransfer::mk(), 'audit', 'code');
+            DataUserTransfer::mForm('audit', 'code');
         } else {
             $data = $this->_vali([
                 'code.require'        => '打款单号不能为空!',

+ 5 - 4
app/data/service/ExpressService.php

@@ -2,6 +2,8 @@
 
 namespace app\data\service;
 
+use app\data\model\BasePostageRegion;
+use app\data\model\BasePostageTemplate;
 use think\admin\extend\DataExtend;
 use think\admin\Service;
 use think\admin\service\InterfaceService;
@@ -28,7 +30,7 @@ class ExpressService extends Service
     {
         if (empty($codes)) return [0, $truckCount, '', '邮费模板编码为空!'];
         $map = [['status', '=', 1], ['deleted', '=', 0], ['code', 'in', $codes]];
-        $template = $this->app->db->name('BasePostageTemplate')->where($map)->order('sort desc,id desc')->find();
+        $template = BasePostageTemplate::mk()->where($map)->order('sort desc,id desc')->find();
         if (empty($template)) return [0, $truckCount, '', '邮费模板编码无效!'];
         $rule = json_decode($template['normal'] ?: '[]', true) ?: [];
         foreach (json_decode($template['content'] ?: '[]', true) ?: [] as $item) {
@@ -56,8 +58,7 @@ class ExpressService extends Service
      */
     public function templates(): array
     {
-        $map = ['status' => 1, 'deleted' => 0];
-        $query = $this->app->db->name('BasePostageTemplate')->where($map);
+        $query = BasePostageTemplate::mk()->where(['status' => 1, 'deleted' => 0]);
         return $query->order('sort desc,id desc')->column('code,name,normal,content', 'code');
     }
 
@@ -69,7 +70,7 @@ class ExpressService extends Service
      */
     public function region(int $level = 3, ?int $status = null): array
     {
-        $query = $this->app->db->name('BasePostageRegion');
+        $query = BasePostageRegion::mk();
         if (is_numeric($level)) $query->where('level', '<=', $level);
         if (is_numeric($status)) $query->where(['status' => $status]);
         $items = DataExtend::arr2tree($query->column('id,pid,name,status', 'id'), 'id', 'pid', 'subs');

+ 1 - 4
app/data/service/MessageService.php

@@ -155,9 +155,7 @@ class MessageService extends Service
     public function send(string $phone, string $content): array
     {
         [$state, $message, $record] = $this->_request('v2/sendSms', ['mobile' => $phone, 'content' => $content]);
-        DataUserMessage::mk()->insert([
-            'phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0,
-        ]);
+        DataUserMessage::mk()->insert(['phone' => $phone, 'content' => $content, 'result' => $message, 'status' => $state ? 1 : 0]);
         return [$state, $message, $record];
     }
 
@@ -174,5 +172,4 @@ class MessageService extends Service
         $this->password = sysconf('zt.password');
         return $this;
     }
-
 }

+ 9 - 7
app/data/service/NewsService.php

@@ -2,6 +2,9 @@
 
 namespace app\data\service;
 
+use app\data\model\DataNewsItem;
+use app\data\model\DataNewsMark;
+use app\data\model\DataNewsXCollect;
 use think\admin\Service;
 
 /**
@@ -19,7 +22,7 @@ class NewsService extends Service
      */
     public function syncNewsTotal(string $code, array $total = []): void
     {
-        $query = $this->app->db->name('DataNewsXCollect')->field('type,count(1) count');
+        $query = DataNewsXCollect::mk()->field('type,count(1) count');
         foreach ($query->where(['code' => $code, 'status' => 2])->group('type')->cursor() as $item) {
             $total[$item['type']] = $item['count'];
         }
@@ -39,8 +42,8 @@ class NewsService extends Service
             /*! 绑定文章内容 */
             $codes = array_unique(array_column($list, 'code'));
             $colls = 'id,code,name,cover,mark,status,deleted,create_at,num_like,num_read,num_comment,num_collect';
-            $items = $this->app->db->name('DataNewsItem')->whereIn('code', $codes)->column($colls, 'code');
-            $marks = $this->app->db->name('DataNewsMark')->where(['status' => 1])->column('name');
+            $items = DataNewsItem::mk()->whereIn('code', $codes)->column($colls, 'code');
+            $marks = DataNewsMark::mk()->where(['status' => 1])->column('name');
             foreach ($items as &$vo) $vo['mark'] = str2arr($vo['mark'] ?: '', ',', $marks);
             foreach ($list as &$vo) $vo['record'] = $items[$vo['code']] ?? [];
             /*! 绑定用户数据 */
@@ -60,11 +63,11 @@ class NewsService extends Service
     {
         if (count($list) > 0) {
             [$code2, $code1] = [[], []];
-            $marks = $this->app->db->name('DataNewsMark')->where(['status' => 1])->column('name');
+            $marks = DataNewsMark::mk()->where(['status' => 1])->column('name');
             if ($uuid > 0) {
                 $map = [['uuid', '=', $uuid], ['code', 'in', array_unique(array_column($list, 'code'))]];
-                $code1 = $this->app->db->name('DataNewsXCollect')->where($map)->where(['type' => 1])->column('code');
-                $code2 = $this->app->db->name('DataNewsXCollect')->where($map)->where(['type' => 2])->column('code');
+                $code1 = DataNewsXCollect::mk()->where($map)->where(['type' => 1])->column('code');
+                $code2 = DataNewsXCollect::mk()->where($map)->where(['type' => 2])->column('code');
             }
             foreach ($list as &$vo) {
                 $vo['mark'] = str2arr($vo['mark'] ?: '', ',', $marks);
@@ -74,5 +77,4 @@ class NewsService extends Service
         }
         return $list;
     }
-
 }

+ 0 - 1
app/data/service/OrderService.php

@@ -147,5 +147,4 @@ class OrderService extends Service
         }
         return $data;
     }
-
 }

+ 11 - 16
app/data/service/UserAdminService.php

@@ -61,19 +61,15 @@ class UserAdminService extends Service
      */
     public function set(array $map, array $data, string $type, bool $force = false): array
     {
+        $user = DataUser::mk()->where($map)->where(['deleted' => 0])->find();
+        // 更新或写入用户数据
         unset($data['id'], $data['deleted'], $data['create_at']);
-        if ($uuid = DataUser::mk()->where($map)->where(['deleted' => 0])->value('id')) {
-            if (!empty($data)) {
-                $map = ['id' => $uuid, 'deleted' => 0];
-                DataUser::mk()->strict(false)->where($map)->update($data);
-            }
-        } else {
-            $uuid = DataUser::mk()->strict(false)->insertGetId($data);
-        }
-        if ($force) {
-            UserTokenService::instance()->token(intval($uuid), $type);
-        }
-        return $this->get($uuid, $type);
+        if (empty($user)) ($user = DataUser::mk())->save($data);
+        elseif (!empty($data)) $user->save($data);
+        // 强行刷新用户认证令牌
+        if ($force) UserTokenService::instance()->token($user['id'], $type);
+        // 返回当前用户资料数据
+        return $this->get($user['id'], $type);
     }
 
     /**
@@ -89,10 +85,9 @@ class UserAdminService extends Service
     public function get(int $uuid, ?string $type = null): array
     {
         $user = DataUser::mk()->where(['id' => $uuid, 'deleted' => 0])->find();
-        if (empty($user)) throw new Exception('指定UID用户不存在');
+        if (empty($user)) throw new Exception('用户还没有注册!');
         if (!is_null($type)) {
-            $map = ['uuid' => $uuid, 'type' => $type];
-            $data = DataUserToken::mk()->where($map)->find();
+            $data = DataUserToken::mk()->where(['uuid' => $uuid, 'type' => $type])->find();
             if (empty($data)) {
                 [$state, $info, $data] = UserTokenService::instance()->token($uuid, $type);
                 if (empty($state) || empty($data)) throw new Exception($info);
@@ -100,7 +95,7 @@ class UserAdminService extends Service
             $user['token'] = ['token' => $data['token'], 'expire' => $data['time']];
         }
         unset($user['deleted'], $user['password']);
-        return $user;
+        return $user->toArray();
     }
 
     /**

+ 0 - 2
app/data/service/UserBalanceService.php

@@ -46,7 +46,6 @@ class UserBalanceService extends Service
      * @param int $uuid 用户UID
      * @param array $nots 排除的订单
      * @return array [total, count]
-     * @throws \think\db\exception\DbException
      */
     public function amount(int $uuid, array $nots = []): array
     {
@@ -64,5 +63,4 @@ class UserBalanceService extends Service
         }
         return [$total, $count];
     }
-
 }

+ 6 - 11
app/data/service/UserUpgradeService.php

@@ -40,7 +40,7 @@ class UserUpgradeService extends Service
     public function bindAgent(int $uuid, int $pid0 = 0, int $mode = 1): array
     {
         $user = DataUser::mk()->where(['id' => $uuid])->find();
-        if (empty($user)) return [0, '用户查询失败'];
+        if (empty($user)) return [0, '查询用户资料失败'];
         if ($user['pids'] && in_array($mode, [0, 1])) return [1, '已经绑定代理'];
         // 检查代理用户
         if (empty($pid0)) $pid0 = $user['pid0'];
@@ -49,23 +49,18 @@ class UserUpgradeService extends Service
         // 检查代理资格
         $agent = DataUser::mk()->where(['id' => $pid0])->find();
         if (empty($agent['vip_code'])) return [0, '代理无推荐资格'];
-        if (stripos($agent['path'], "-{$uuid}-") !== false) return [0, '不能绑定下属'];
+        if (strpos($agent['path'], "-{$uuid}-") !== false) return [0, '不能绑定下属'];
         try {
             $this->app->db->transaction(function () use ($user, $agent, $mode) {
                 // 更新用户代理
                 $path1 = rtrim($agent['path'] ?: '-', '-') . "-{$agent['id']}-";
-                DataUser::mk()->where(['id' => $user['id']])->update([
-                    'pid0' => $agent['id'], 'pid1' => $agent['id'], 'pid2' => $agent['pid1'],
-                    'pids' => $mode > 0 ? 1 : 0, 'path' => $path1, 'layer' => substr_count($path1, '-'),
-                ]);
+                $user->save(['pid0' => $agent['id'], 'pid1' => $agent['id'], 'pid2' => $agent['pid1'], 'pids' => $mode > 0 ? 1 : 0, 'path' => $path1, 'layer' => substr_count($path1, '-')]);
                 // 更新下级代理
                 $path2 = "{$user['path']}{$user['id']}-";
                 if (DataUser::mk()->whereLike('path', "{$path2}%")->count() > 0) {
-                    foreach (DataUser::mk()->whereLike('path', "{$path2}%")->order('layer desc')->select() as $vo) {
-                        $attr = array_reverse(str2arr($path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $vo['path']), '-'));
-                        DataUser::mk()->where(['id' => $vo['id']])->update([
-                            'pid0' => $attr[0] ?? 0, 'pid1' => $attr[0] ?? 0, 'pid2' => $attr[1] ?? 0, 'path' => $path3, 'layer' => substr_count($path3, '-'),
-                        ]);
+                    foreach (DataUser::mk()->whereLike('path', "{$path2}%")->order('layer desc')->select() as $item) {
+                        $attr = array_reverse(str2arr($path3 = preg_replace("#^{$path2}#", "{$path1}{$user['id']}-", $item['path']), '-'));
+                        $item->save(['pid0' => $attr[0] ?? 0, 'pid1' => $attr[0] ?? 0, 'pid2' => $attr[1] ?? 0, 'path' => $path3, 'layer' => substr_count($path3, '-')]);
                     }
                 }
             });