Selaa lähdekoodia

模版后台管理

bianjunhui 1 vuosi sitten
vanhempi
commit
2845a2667d

+ 37 - 0
application/admin/controller/sms/Log.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\admin\controller\sms;
+
+use app\common\controller\Backend;
+
+/**
+ * 
+ *
+ * @icon fa fa-circle-o
+ */
+class Log extends Backend
+{
+
+    /**
+     * Log模型对象
+     * @var \app\admin\model\sms\Log
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\sms\Log;
+        $this->view->assign("statusList", $this->model->getStatusList());
+    }
+
+
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+}

+ 156 - 0
application/admin/controller/sms/Template.php

@@ -0,0 +1,156 @@
+<?php
+
+namespace app\admin\controller\sms;
+
+use app\admin\model\UserGroup;
+use app\common\controller\Backend;
+use think\Db;
+use think\exception\DbException;
+use think\exception\PDOException;
+use think\exception\ValidateException;
+
+/**
+ * 
+ *
+ * @icon fa fa-circle-o
+ */
+class Template extends Backend
+{
+
+    /**
+     * Template模型对象
+     * @var \app\admin\model\sms\Template
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\sms\Template;
+        $this->view->assign("statusList", $this->model->getStatusList());
+    }
+    public function getType()
+    {
+        $list[0]['id']=0;
+        $list[0]['name']='分';
+        $list[1]['id']=1;
+        $list[1]['name']='时';
+        $list[2]['id']=2;
+        $list[2]['name']='天';
+
+
+        $i=$this->request->request('keyValue');
+        if ($i) {
+            return json(['list' => $list[$i], 'total' => count($list[$i])]);
+        }
+        return json(['list' => $list, 'total' => count($list)]);
+    }
+
+    /**
+     * 添加
+     *
+     * @return string
+     * @throws \think\Exception
+     */
+    public function add()
+    {
+        if (false === $this->request->isPost()) {
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if($params['type']==2){
+            $params['sendtime']=$params['times']*24*60*60;
+        }elseif($params['type']==1){
+            $params['sendtime']=$params['times']*60*60;
+        }else{
+            $params['sendtime']=$params['times']*60;
+        }
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $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()->validate($validate);
+            }
+            $result = $this->model->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('No rows were inserted'));
+        }
+        $this->success();
+    }
+    /**
+     * 编辑
+     *
+     * @param $ids
+     * @return string
+     * @throws DbException
+     * @throws \think\Exception
+     */
+    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) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        if($params['type']==2){
+            $params['sendtime']=$params['times']*24*60*60;
+        }elseif($params['type']==1){
+            $params['sendtime']=$params['times']*60*60;
+        }else{
+            $params['sendtime']=$params['times']*60;
+        }
+        $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()->validate($validate);
+            }
+            $result = $row->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+
+
+}

+ 5 - 0
application/admin/lang/zh-cn/sms/log.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+
+];

+ 5 - 0
application/admin/lang/zh-cn/sms/template.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+
+];

+ 49 - 0
application/admin/model/sms/Log.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\admin\model\sms;
+
+use think\Model;
+
+
+class Log extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'sms_log';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'status_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return ['1' => __('启用'),'2' => __('关闭')];
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+
+
+}

+ 86 - 0
application/admin/model/sms/Template.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace app\admin\model\sms;
+
+use think\Model;
+
+
+class Template extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'sms_template';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'addtime_text',
+        'uptime_text',
+        'status_text',
+        'sendtime_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return ['1' => __('启用'),'2' => __('关闭')];
+    }
+
+
+    public function getAddtimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['addtime']) ? $data['addtime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getUptimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['uptime']) ? $data['uptime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getSendtimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['sendtime']) ? $data['sendtime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setAddtimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setUptimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setSendtimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+}

+ 27 - 0
application/admin/validate/sms/Log.php

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

+ 27 - 0
application/admin/validate/sms/Template.php

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

+ 106 - 0
application/admin/view/sms/log/add.html

@@ -0,0 +1,106 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Addtime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-addtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[addtime]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Uptime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uptime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[uptime]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </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="10"}checked{/in} /> {$vo}</label> 
+            {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Quote_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-quote_id" data-rule="required" data-source="quote/index" class="form-control selectpage" name="row[quote_id]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Mobile')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-mobile" class="form-control" name="row[mobile]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Ymobile')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ymobile" class="form-control" name="row[ymobile]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-template_id" data-rule="required" data-source="template/index" class="form-control selectpage" name="row[template_id]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-remarks" class="form-control" name="row[remarks]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_body')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-template_body" class="form-control " rows="5" name="row[template_body]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Bizid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-bizId" class="form-control" name="row[bizId]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Requestid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-requestId" class="form-control" name="row[requestId]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sign')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sign" class="form-control" name="row[sign]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Querynums')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-querynums" data-rule="required" class="form-control" name="row[querynums]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sendnums')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sendnums" data-rule="required" class="form-control" name="row[sendnums]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Email')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-email" class="form-control" name="row[email]" type="text">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 106 - 0
application/admin/view/sms/log/edit.html

@@ -0,0 +1,106 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Addtime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-addtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[addtime]" type="text" value="{:$row.addtime?datetime($row.addtime):''}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Uptime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uptime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[uptime]" type="text" value="{:$row.uptime?datetime($row.uptime):''}">
+        </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">{:__('Quote_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-quote_id" data-rule="required" data-source="quote/index" class="form-control selectpage" name="row[quote_id]" type="text" value="{$row.quote_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Mobile')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-mobile" class="form-control" name="row[mobile]" type="text" value="{$row.mobile|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Ymobile')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ymobile" class="form-control" name="row[ymobile]" type="text" value="{$row.ymobile|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-template_id" data-rule="required" data-source="template/index" class="form-control selectpage" name="row[template_id]" type="text" value="{$row.template_id|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-remarks" class="form-control" name="row[remarks]" type="text" value="{$row.remarks|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_body')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-template_body" class="form-control " rows="5" name="row[template_body]" cols="50">{$row.template_body|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Bizid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-bizId" class="form-control" name="row[bizId]" type="text" value="{$row.bizId|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Requestid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-requestId" class="form-control" name="row[requestId]" type="text" value="{$row.requestId|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sign')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sign" class="form-control" name="row[sign]" type="text" value="{$row.sign|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Querynums')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-querynums" data-rule="required" class="form-control" name="row[querynums]" type="number" value="{$row.querynums|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sendnums')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sendnums" data-rule="required" class="form-control" name="row[sendnums]" type="number" value="{$row.sendnums|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Email')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-email" class="form-control" name="row[email]" type="text" value="{$row.email|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 34 - 0
application/admin/view/sms/log/index.html

@@ -0,0 +1,34 @@
+<div class="panel panel-default panel-intro">
+    
+    <div class="panel-heading">
+        {:build_heading(null,FALSE)}
+    </div>
+
+
+    <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 class="dropdown btn-group {:$auth->check('sms/log/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('sms/log/edit')}"
+                           data-operate-del="{:$auth->check('sms/log/del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 60 - 0
application/admin/view/sms/template/add.html

@@ -0,0 +1,60 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group" hidden>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Addtime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-addtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[addtime]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </div>
+    </div>
+    <div class="form-group" hidden>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Uptime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uptime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[uptime]" type="text" value="{:date('Y-m-d H:i:s')}">
+        </div>
+    </div>
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" class="form-control" data-rule="required" name="row[name]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-type" data-rule="required" data-source="sms/template/getType" class="form-control selectpage" name="row[type]" type="text" value="">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Times')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-times" class="form-control"  data-rule="required" name="row[times]" type="number">
+        </div>
+    </div>
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_body')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-template_body" data-rule="required" class="form-control " rows="5" name="row[template_body]" cols="50"></textarea>
+        </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="1"}checked{/in} /> {$vo}</label>
+                {/foreach}
+            </div>
+
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 53 - 0
application/admin/view/sms/template/edit.html

@@ -0,0 +1,53 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group" hidden>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Uptime')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-uptime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[uptime]" type="text" value="{:$row.uptime?datetime($row.uptime):''}">
+        </div>
+    </div>
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" class="form-control" data-rule="required"  name="row[name]" type="text" value="{$row.name|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-type" data-rule="required" data-source="sms/template/getType" class="form-control selectpage" name="row[type]" type="text" value="{$row.type|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Times')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-times" class="form-control"  data-rule="required"  name="row[times]" type="number" value="{$row.times|htmlentities}">
+        </div>
+    </div>
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Template_body')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-template_body" data-rule="required"  class="form-control " rows="5" name="row[template_body]" cols="50">{$row.template_body|htmlentities}</textarea>
+        </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 layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 45 - 0
application/admin/view/sms/template/index.html

@@ -0,0 +1,45 @@
+<div class="panel panel-default panel-intro">
+    
+    <div class="panel-heading">
+        {:build_heading(null,FALSE)}
+        <ul class="nav nav-tabs" data-field="status">
+            <li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
+            {foreach name="statusList" item="vo"}
+            <li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
+            {/foreach}
+        </ul>
+    </div>
+
+
+    <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>
+                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('sms/template/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('sms/template/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('sms/template/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        
+
+                        <div class="dropdown btn-group {:$auth->check('sms/template/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('sms/template/edit')}"
+                           data-operate-del="{:$auth->check('sms/template/del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 199 - 0
application/api/common.php

@@ -1 +1,200 @@
 <?php
+
+use think\Db;
+
+function getCountryMobile($countryCode){
+
+    $where['country_id']=$countryCode;
+    $lists = Db::name('directory_country')->where($where)->find();
+    $country = $lists['iso2_code'];
+    $countrys_en = [ "China", "Afghanistan", "Albania", "Algera",
+        "Andorra", "Angola", "Anguilla", "Ascension",
+        "Antigua and Barbuda", "Argentina", "Armenia", "Aruba",
+        "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",
+        "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
+        "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina",
+        "Botwana", "Brazill", "Brunei", "Bulgaria", "Burkina Faso",
+        "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
+        "Cayman Islands", "Central African Republic", "Chad", "Chile",
+        "Colombia", "Comoros", "Republic of the Congo",
+        "Democratic Republic of the Congo", "Cook Islands", "Costa Rica",
+        "Cote divoire", "Croatia", "Cuba", "Cyprus", "+Czech Republic",
+        "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
+        "Egypt", "EISalvador", "Estonia", "Ethiopia", "Faroe Islands",
+        "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
+        "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar",
+        "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam",
+        "Guatemala", "Guinea", "Guernsey", "Guinea", "Guyana", "Haiti",
+        "Honduras", "Hong Kong", "Myanmar", "Hungary", "Iceland", "Indea",
+        "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel",
+        "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazeakhstan",
+        "Kenya", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia",
+        "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
+        "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar",
+        "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique",
+        "Mauritania", "Mauritius", "Mayotte", "Mexico", "Moldova",
+        "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco",
+        "Mozambique", "Namibia", "Nepal", "Netherlands",
+        "Netherlands Antillse", "New Caledonia", "NewZealand", "Nicaragua",
+        "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestinian",
+        "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
+        "Poland", "Portugal", "PuertoRico", "Qotar", "Reunion", "Romania",
+        "Russia", "Rwanda", "Samoa Eastern", "Samoa Western", "San Marino",
+        "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
+        "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
+        "South Africa", "Korea", "Spain", "SriLanka", "St Kitts and Nevis",
+        "St.Lucia", "St.Vincent", "Sudan", "Suriname", "Swaziland",
+        "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan",
+        "Tanzania", "Thailand", "Timor Leste", "Togo", "Tonga",
+        "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
+        "Turks and Caicos Islands", "Uganda", "Ukraine",
+        "United Arab Emirates", "United Kingdom", "USA", "Uruguay",
+        "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands",
+        "Yemen", "Zambia", "Zimbabwe" ];
+    $countrys = array_keys($countrys_en,$country,true);
+    if(empty($countrys)){
+        $country=$lists['iso3_code'];
+        $countrys =array_keys($countrys_en,$country,true);
+    }
+    if($countrys[0]){
+        $countryMobile =getCountryCode($countrys[0]);
+    }else{
+        $countryMobile ='+1';
+    }
+    $countryMobile = str_replace('+','',$countryMobile);
+    return (int)$countryMobile;
+}
+
+//获取国家手机编号
+function getCountryCode($countryCode){
+    $codes = [ "+86", "+93", "+355", "+213", "+376", "+244", "+1264",
+        "+247", "+1268", "+54", "+374", "+297", "+61", "+43", "+994",
+        "+1242", "+973", "+880", "+1246", "+375", "+32", "+501", "+229",
+        "+1441", "+975", "+591", "+387", "+267", "+55", "+673", "+359",
+        "+226", "+257", "+855", "+237", "+1", "+238", "+1345", "+236",
+        "+235", "+56", "+57", "+269", "+242", "+243", "+682", "+506",
+        "+225", "+385", "+53", "+357", "+420", "+45", "+253", "+1767",
+        "+1809", "+593", "+20", "+503", "+372", "+251", "+298", "+679",
+        "+358", "+33", "+594", "+689", "+241", "+220", "+995", "+94",
+        "+233", "+350", "+30", "+299", "+1473", "+590", "+1671", "+502",
+        "+240", "+44", "+224", "+592", "+509", "+504", "+852", "+95",
+        "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972",
+        "+93", "+1876", "+81", "+44", "+962", "+7", "+254", "+383", "+965",
+        "+996", "+856", "+371", "+961", "+266", "+231", "+218", "+423",
+        "+370", "+352", "+853", "+389", "+261", "+265", "+60", "+960",
+        "+223", "+356", "+596", "+222", "+230", "+262", "+52", "+373",
+        "+377", "+976", "+382", "+1664", "+212", "+258", "+264", "+977",
+        "+31", "+599", "+687", "+64", "+505", "+227", "+234", "+47",
+        "+968", "+92", "+970", "+507", "+675", "+595", "+51", "+63", "+48",
+        "+351", "+1", "+974", "+262", "+40", "+7", "+250", "+684", "+685",
+        "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65",
+        "+421", "+386", "+27", "+82", "+34", "+94", "+1869", "+1758",
+        "+1784", "+249", "+597", "+268", "+46", "+41", "+963", "+886",
+        "+992", "+255", "+66", "+670", "+228", "+676", "+1868", "+216",
+        "+90", "+993", "+1649", "+256", "+380", "+971", "+44", "+1",
+        "+598", "+998", "+678", "+58", "+84", "+1340", "+967", "+260",
+        "+263" ];
+    return $codes[$countryCode];
+}
+
+function checkMobile($countryMobile,$mobile,$countryCode)
+{
+    $mobile= str_replace('-', '', $mobile);
+    $mobile= str_replace('_', '', $mobile);
+    $mobile= str_replace('(', '', $mobile);
+    $mobile= str_replace(')', '', $mobile);
+    $mobile= str_replace('+', '', $mobile);
+    $mobile= str_replace(' ', '', $mobile);
+    $mobile=trim($mobile);
+    $lenth=strlen($mobile);
+    $data['status']=5;//不发送
+    $data['mobile']=$mobile;//不发送
+    $frist =(int)substr($mobile, 0, 1 );
+    if($countryMobile==1){//美国 加拿大
+        $code=0;
+        if($lenth==11&&$frist==1){//例:14696305087
+            $data['mobile'] = $mobile;
+            $code = substr($mobile , 1 , 3);
+            //$data['status']=1;//待发送
+        }
+        if($lenth==10&&$frist!=1){
+            $data['mobile'] = $countryMobile.$mobile;
+            $code = substr($mobile , 0 , 3);
+            //$data['status']=1;//待发送
+        }
+        if($code){
+            $re=checkMobileCode($code);
+            if($re){
+                $data['status']=1;//待发送
+            }
+        }
+        $data['sign']='13013071800';//签名
+    }
+
+    if($countryMobile==44){//UK
+        if($lenth==10&&$frist==7){
+            $data['mobile'] = $countryMobile.$mobile;
+            $data['status']=1;//待发送
+        }
+
+        if($lenth==11&&$frist==0){
+            $mobile =substr($mobile,1);
+            $frists =(int)substr($mobile, 0, 1 );
+            if($frists==7){
+                $data['mobile'] = $countryMobile.$mobile;
+                $data['status']=1;//待发送
+            }
+        }
+        if($lenth==12&&$frist==4){
+            $mobile=substr($mobile,2);
+            $frists =(int)substr($mobile, 0, 1 );
+            if($frists==7){
+                $data['mobile'] = $countryMobile.$mobile;
+                $data['status']=1;//待发送
+            }
+        }
+    }
+
+    if($countryMobile==33){//France
+        if($lenth==9){
+            if($frist==7||$frist==6){
+                $data['mobile'] = $countryMobile.$mobile;
+                $data['status']=1;//待发送
+            }
+
+        }
+
+        if($lenth==10&&$frist==0){
+            $mobile =substr($mobile,1);
+            $frists =(int)substr($mobile, 0, 1 );
+            if($frists==7||$frists==6){
+                $data['mobile'] = $countryMobile.$mobile;
+                $data['status']=1;//待发送
+            }
+        }
+        if($lenth==11&&$frist==3){
+            $mobile=substr($mobile,0,2);
+            $frists =(int)substr($mobile, 0, 1 );
+            if($frists==7||$frists==6){
+                $data['mobile'] = $countryMobile.$mobile;
+                $data['status']=1;//待发送
+            }
+        }
+    }
+
+    return $data;
+}
+
+function  checkMobileCode($code){
+    $lists = Db::name('directory_country_code')->select();
+    $token=[];
+    foreach ($lists as $v){
+        $token[]=$v['code'];
+    }
+    if (in_array($code, $token)) {
+        return true;
+    }else{
+        return false;
+    }
+
+}

+ 89 - 0
application/api/controller/Assms.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\library\Sms as Smslib;
+use app\common\model\User;
+use think\Db;
+use think\Exception;
+use think\exception\PDOException;
+use think\helper\hash\Md5;
+use think\Hook;
+
+/**
+ * 手机短信接口
+ */
+class Assms extends Api
+{
+    protected $noNeedLogin = '*';
+    protected $noNeedRight = '*';
+
+    public function addSmsLog(){
+        $post=$this->request->post();
+        $sign =$post['sign'];
+        if($sign!=Md5('longyi_as')){
+            $this->error('sign error');
+        }
+        $this->addSmsQuote($post);
+        $this->success(__('success'));
+    }
+
+    public function addSmsQuote($quote)
+    {
+        $quote_id= $quote['quote_id'];
+        $name = $quote['name'];
+        $mobile =$quote['mobile'];
+        $email =$quote['email'];
+        $countryCode = $quote['countryCode'];
+        $countryMobile =911;
+        if(!$mobile){
+            return ;
+        }
+        if($countryCode){
+            $countryMobile = getCountryMobile($countryCode);
+        }
+        if($mobile){
+            $datas =checkMobile($countryMobile,$mobile,$countryCode);
+            $mobiles=$datas['mobile'];
+            //删除手机号、购物车ID相同待发送短信信息
+            $where['mobile']=$mobiles;
+            $where['status']=1;
+            Db::name('sms_log')->where($where)->delete();
+            unset($where);
+            $where['status']=1;
+            $template= Db::name('sms_template')->where($where)->select();
+            $data=array();
+            //循环添加发送短信
+            foreach ($template as $k=> $v){
+                $template_id = $v['template_id'];
+                $data[$k]['email'] =$email;
+                $data[$k]['ymobile'] =$mobile;
+                $data[$k]['quote_id']=$quote_id;
+                $data[$k]['template_id']=$template_id;
+                $data[$k]['status']=$datas['status'];
+                $data[$k]['mobile']=$datas['mobile'];
+                $data[$k]['addtime']=time();
+                $data[$k]['uptime']=time()+$v['sendtime'];
+                $data[$k]['remarks']=$countryMobile;
+                $data[$k]['template_body']= $this->getMssage($v['template_body'],$name);
+                $data[$k]['template_name']= $v['name'];
+            }
+            try {
+                Db::name('sms_log')->insertAll($data);
+            }catch (\PDOException $e){
+                $e->getMessage();
+
+            } catch (\Exception $e) {
+                var_dump($e->getMessage());
+            }
+
+        }
+
+    }
+    public function  getMssage($template_body,$name){
+        $search = '{#NAME}';
+        $message=str_replace($search,$name,$template_body);
+        return $message;
+    }
+}