Преглед на файлове

靓号上下架,编辑

lizhen_gitee преди 1 година
родител
ревизия
b636fe932c

+ 101 - 0
application/admin/controller/Uidsale.php

@@ -139,4 +139,105 @@ class Uidsale extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 编辑
+     */
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                $this->error(__('You have no permission'));
+            }
+        }
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+                $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 . '.edit' : $name) : $this->modelValidate;
+                        $row->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('id != '.$ids)->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 = $row->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 updated'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $this->view->assign("row", $row);
+        return $this->view->fetch();
+    }
+
+    /**
+     * 上架
+     */
+    public function shangjia(){
+        $id = input('ids');
+
+        $update = [
+            'is_show' => 1,
+        ];
+        Db::name('uidsale')->where('id',$id)->update($update);
+
+        $this->success('已上架');
+    }
+
+    /**
+     * 下架
+     */
+    public function xiajia(){
+        $id = input('ids');
+
+        $update = [
+            'is_show' => 0,
+        ];
+        Db::name('uidsale')->where('id',$id)->update($update);
+
+        $this->success('已下架');
+    }
+
 }

+ 0 - 35
application/admin/view/uidsale/edit.html

@@ -12,42 +12,7 @@
             <input id="c-type_id" data-rule="required" data-source="uidsaletype/index" data-field="type" class="form-control selectpage" name="row[type_id]" type="text" value="{$row.type_id|htmlentities}">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Is_show')}:</label>
-        <div class="col-xs-12 col-sm-8">
-                        
-            <select  id="c-is_show" data-rule="required" class="form-control selectpicker" name="row[is_show]">
-                {foreach name="isShowList" item="vo"}
-                    <option value="{$key}" {in name="key" value="$row.is_show"}selected{/in}>{$vo}</option>
-                {/foreach}
-            </select>
 
-        </div>
-    </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            
-            <div class="radio">
-            {foreach name="statusList" item="vo"}
-            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label> 
-            {/foreach}
-            </div>
-
-        </div>
-    </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
-        </div>
-    </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Saletime')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-saletime" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[saletime]" type="text" value="{:$row.saletime?datetime($row.saletime):''}">
-        </div>
-    </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 2 - 0
application/admin/view/uidsale/index.html

@@ -35,6 +35,8 @@
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('uidsale/edit')}" 
                            data-operate-del="{:$auth->check('uidsale/del')}" 
+                           data-operate-shangjia="{:$auth->check('uidsale/shangjia')}"
+                           data-operate-xiajia="{:$auth->check('uidsale/xiajia')}"
                            width="100%">
                     </table>
                 </div>

+ 1 - 1
application/api/controller/Uidsale.php

@@ -75,7 +75,7 @@ class Uidsale extends Api
         $info = Db::name('uidsale')->field('id,price,new_id')->where($map)->where('id',$id)->lock(true)->find();
         if(empty($info)){
             Db::rollback();
-            $this->error('此靓号不存在,请刷新重试');
+            $this->error('此靓号已售出或已下架,请刷新重试');
         }
 
         //扣金币

+ 49 - 1
public/assets/js/backend/uidsale.js

@@ -35,7 +35,49 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'saletime', title: __('Saletime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
 //                        {field: 'type_id', title: __('Type_id')},
                         {field: 'uidsaletype.type', title: __('Uidsaletype.type'), operate: 'LIKE'},
-//                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'operate', title: __('Operate'), table: table,
+                            buttons:[
+                                {
+                                    name:'shangjia',
+                                    text:'上架',
+                                    title:'上架',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-success btn-ajax',
+                                    url:'uidsale/shangjia/ids/{ids}?dialog=1',
+                                    target:'_self',
+                                    refresh:true,
+                                    hidden:function(row){
+                                        return (row.status==0 && row.is_show == 0) ? false : true;
+                                    }
+                                },
+                                {
+                                    name:'xiajia',
+                                    text:'下架',
+                                    title:'下架',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-danger btn-ajax',
+                                    url:'uidsale/xiajia/ids/{ids}?dialog=1',
+                                    target:'_self',
+                                    refresh:true,
+                                    hidden:function(row){
+                                        return (row.status==0 && row.is_show == 1) ? false : true;
+                                    }
+                                },
+                                {
+                                    name:'edit',
+                                    text:'编辑',
+                                    title:'编辑',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-dialog',
+                                    url:'uidsale/edit/ids/{ids}?dialog=1',
+                                    target:'_self',
+                                    refresh:true,
+                                    hidden:function(row){
+                                        return (row.status==0 && row.is_show == 0) ? false : true;
+                                    }
+                                }
+                            ],
+                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]
             });
@@ -49,6 +91,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         edit: function () {
             Controller.api.bindevent();
         },
+        shangjia: function () {
+            Controller.api.bindevent();
+        },
+        xiajia: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));