xxxrrrdddd 3 年之前
父节点
当前提交
0c39ad4a48

+ 4 - 0
application/admin/controller/Mobile.php

@@ -6,10 +6,12 @@ use app\admin\library\Auth;
 use app\common\controller\Backend;
 use app\common\library\MobileConstant;
 use app\common\service\MobileImport;
+use app\common\service\MobilePriceLogService;
 use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
 use PhpOffice\PhpSpreadsheet\Reader\Csv;
 use PhpOffice\PhpSpreadsheet\Reader\Xls;
 use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
+use think\App;
 use think\Db;
 use think\Exception;
 use think\exception\PDOException;
@@ -167,6 +169,7 @@ class Mobile extends Backend
                 $data['province_id']=\app\common\model\Area::getIdByName($data['province']);
                 $data['city_id']=\app\common\model\Area::getIdByName($data['city']);
             }
+            (new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
             $mobile->allowField(true)->save($data);
             $describe=$data['describe']??'';
             $mobile->info()->update(compact('describe'));
@@ -190,6 +193,7 @@ class Mobile extends Backend
                 $data['province_id']=\app\common\model\Area::getIdByName($data['province']);
                 $data['city_id']=\app\common\model\Area::getIdByName($data['city']);
             }
+            (new MobilePriceLogService)->setMobile($mobile)->setAdminId($this->auth->id)->setBeforePrice($mobile['amount_base'])->setAfterPrice($data['amount_base'])->log();
             $mobile->allowField(true)->save($data);
             $describe=$data['describe']??'';
             $mobile->info()->update(compact('describe'));

+ 81 - 0
application/admin/controller/MobilePriceLog.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ *  改价记录
+ *
+ * @icon fa fa-circle-o
+ */
+class MobilePriceLog extends Backend
+{
+    
+    /**
+     * MobilePriceLog模型对象
+     * @var \app\admin\model\MobilePriceLog
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\MobilePriceLog;
+
+    }
+
+    public function import()
+    {
+        parent::import();
+    }
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+    
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        $mobile_id=input('ids');
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $map=[];
+            if($mobile_id){
+                $map['mobile_id']=$mobile_id;
+            }
+            $list = $this->model
+                ->where($map)
+                    ->with(['admin'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                $row->visible(['id','admin_id','mobile_id','no','before_price','after_price','create_time']);
+                $row->visible(['admin']);
+				$row->getRelation('admin')->visible(['nickname']);
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+}

+ 12 - 0
application/admin/lang/zh-cn/mobile_price_log.php

@@ -0,0 +1,12 @@
+<?php
+
+return [
+    'Admin_id'       => '操作员',
+    'Mobile_id'      => '商品ID',
+    'No'             => '手机号',
+    'Before_price'   => '原来售价',
+    'After_price'    => '变动售价',
+    'Create_time'    => '创建时间',
+    'Update_time'    => '更新时间',
+    'Admin.nickname' => '昵称'
+];

+ 15 - 0
application/admin/model/MobilePriceLog.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class MobilePriceLog extends \app\common\model\MobilePriceLog
+{
+
+    public function admin()
+    {
+        return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 27 - 0
application/admin/validate/MobilePriceLog.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+class MobilePriceLog extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 22 - 0
application/admin/view/mobile_price_log/index.html

@@ -0,0 +1,22 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="0"
+                           data-operate-del="0"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 21 - 0
application/common/model/MobilePriceLog.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+use Yansongda\Supports\Str;
+
+/**
+ * 配置模型
+ */
+class MobilePriceLog extends Model
+{
+
+
+
+
+
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = true;
+}

+ 62 - 0
application/common/service/MobilePriceLogService.php

@@ -0,0 +1,62 @@
+<?php
+namespace app\common\service;
+
+use app\common\model\Mobile;
+use app\common\model\MobilePriceLog;
+
+class MobilePriceLogService{
+    protected $admin_id;
+    /** @var Mobile */
+    protected $mobile;
+    protected $before_price;
+    protected $after_price;
+
+    /**
+     * @param mixed $before_price
+     */
+    public function setBeforePrice($before_price)
+    {
+        $this->before_price = $before_price;
+        return $this;
+    }
+
+    /**
+     * @param mixed $after_price
+     */
+    public function setAfterPrice($after_price)
+    {
+        $this->after_price = $after_price;
+        return $this;
+    }
+
+
+    /**
+     * @param mixed $admin_id
+     */
+    public function setAdminId($admin_id)
+    {
+        $this->admin_id = $admin_id;
+        return $this;
+    }
+
+    /**
+     * @param Mobile $mobile
+     */
+    public function setMobile(Mobile $mobile)
+    {
+        $this->mobile = $mobile;
+        return $this;
+    }
+
+    public function log(){
+        if($this->before_price!=$this->after_price){
+            MobilePriceLog::create([
+                'admin_id'=>$this->admin_id,
+                'mobile_id'=>$this->mobile->id,
+                'no'=>$this->mobile->no,
+                'before_price'=>$this->before_price,
+                'after_price'=>$this->after_price,
+            ]);
+        }
+    }
+}

+ 2 - 2
public/assets/js/backend/mobile.js

@@ -76,7 +76,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     text: __('记录'),
                                     title: __('记录'),
                                     classname: 'btn btn-xs btn-info btn-dialog',
-                                    url: 'example/bootstraptable/detail',
+                                    url: 'mobile_price_log/index?a=1',
                                     callback: function (data) {
                                     },
                                     visible: function (row) {
@@ -119,7 +119,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     text: __('记录'),
                                     title: __('记录'),
                                     classname: 'btn btn-xs btn-info btn-dialog',
-                                    url: 'example/bootstraptable/detail',
+                                    url: 'mobile_price_log/index?a=1',
                                     callback: function (data) {
                                     },
                                     visible: function (row) {

+ 57 - 0
public/assets/js/backend/mobile_price_log.js

@@ -0,0 +1,57 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'mobile_price_log/index' + location.search,
+                    add_url: 'mobile_price_log/add',
+                    edit_url: 'mobile_price_log/edit',
+                    del_url: 'mobile_price_log/del',
+                    multi_url: 'mobile_price_log/multi',
+                    import_url: 'mobile_price_log/import',
+                    table: 'mobile_price_log',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('ID')},
+                        {field: 'mobile_id', title: __('Mobile_id')},
+                        {field: 'no', title: __('No')},
+                        {field: 'before_price', title: __('Before_price'), operate:'BETWEEN'},
+                        {field: 'after_price', title: __('After_price'), operate:'BETWEEN'},
+                        {field: 'create_time', title: __('Create_time'),formatter: Table.api.formatter.datetime},
+                        {field: 'admin_id', title: __('Admin_id')},
+                        {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
+                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});