lizhen_gitee пре 1 година
родитељ
комит
9430c558ec

+ 67 - 1
application/admin/controller/Uidsale.php

@@ -3,7 +3,7 @@
 namespace app\admin\controller;
 
 use app\common\controller\Backend;
-
+use think\Db;
 /**
  * 靓号
  *
@@ -73,4 +73,70 @@ class Uidsale extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 添加
+     */
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+
+                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
+                    $params[$this->dataLimitField] = $this->auth->id;
+                }
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
+                        $this->model->validateFailException(true)->validate($validate);
+                    }
+
+                    $new_id = $params['new_id'];
+                    //检查用户表
+                    $find = Db::name('user')->where('u_id',$new_id)->find();
+                    if($find){
+                        Db::rollback();
+                        $this->error('此靓号已经有用户在使用了');
+                    }
+                    //检查靓号表
+                    $find = Db::name('uidsale')->where('new_id',$new_id)->find();
+                    if($find){
+                        Db::rollback();
+                        $this->error('靓号商城已经有此靓号了');
+                    }
+                    //检查靓号背包表
+                    $find = Db::name('uidsale_bag')->where('u_id',$new_id)->find();
+                    if($find){
+                        Db::rollback();
+                        $this->error('此靓号已经有用户在使用了');
+                    }
+
+                    $result = $this->model->allowField(true)->save($params);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        return $this->view->fetch();
+    }
+
 }

+ 3 - 0
application/common/library/Auth.php

@@ -180,9 +180,12 @@ class Auth
 
         $invite_no = User::column("invite_no");
 
+        //用户id防重复
         $ids = User::column("u_id");
         $uidsale = Db::name('uidsale')->column('new_id');
+        $uidsale_bag = Db::name('uidsale_bag')->column('u_id');
         $ids = array_merge($ids, $uidsale);
+        $ids = array_merge($ids, $uidsale_bag);
 
         $ip = request()->ip();
         $time = time();

+ 4 - 4
public/assets/js/backend/uidsale.js

@@ -27,14 +27,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {checkbox: true},
                         {field: 'id', title: __('Id')},
                         {field: 'new_id', title: __('New_id')},
-                        {field: 'type_id', title: __('Type_id')},
-                        {field: 'is_show', title: __('Is_show'), searchList: {"1":__('Is_show 1'),"0":__('Is_show 0')}, formatter: Table.api.formatter.normal},
+                        {field: 'price', title: __('Price')},
                         {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
+                        {field: 'is_show', title: __('Is_show'), searchList: {"1":__('Is_show 1'),"0":__('Is_show 0')}, formatter: Table.api.formatter.normal},
                         {field: 'user_id', title: __('User_id')},
+                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                         {field: 'saletime', title: __('Saletime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
-                        {field: 'price', title: __('Price')},
+//                        {field: 'type_id', title: __('Type_id')},
                         {field: 'uidsaletype.type', title: __('Uidsaletype.type'), operate: 'LIKE'},
-                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
 //                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]