Ver Fonte

first commit

root há 1 ano atrás
commit
c5f4f10452
100 ficheiros alterados com 29508 adições e 0 exclusões
  1. 7 0
      apidoc.json
  2. 1 0
      app/.htaccess
  3. 22 0
      app/AppService.php
  4. 205 0
      app/BaseController.php
  5. 58 0
      app/ExceptionHandle.php
  6. 8 0
      app/Request.php
  7. 2 0
      app/admin/common.php
  8. 7 0
      app/admin/config/jump.php
  9. 19 0
      app/admin/config/session.php
  10. 167 0
      app/admin/controller/Account.php
  11. 415 0
      app/admin/controller/Activity.php
  12. 321 0
      app/admin/controller/Admin.php
  13. 895 0
      app/admin/controller/AdminControl.php
  14. 194 0
      app/admin/controller/Adminlog.php
  15. 407 0
      app/admin/controller/Adv.php
  16. 380 0
      app/admin/controller/Appadv.php
  17. 71 0
      app/admin/controller/Arrivalnotice.php
  18. 354 0
      app/admin/controller/Article.php
  19. 256 0
      app/admin/controller/Articleclass.php
  20. 552 0
      app/admin/controller/Bill.php
  21. 248 0
      app/admin/controller/Bonus.php
  22. 457 0
      app/admin/controller/Brand.php
  23. 158 0
      app/admin/controller/Chain.php
  24. 65 0
      app/admin/controller/Common.php
  25. 660 0
      app/admin/controller/Complain.php
  26. 348 0
      app/admin/controller/Config.php
  27. 224 0
      app/admin/controller/Consulting.php
  28. 715 0
      app/admin/controller/Dashboard.php
  29. 339 0
      app/admin/controller/Database.php
  30. 216 0
      app/admin/controller/Document.php
  31. 568 0
      app/admin/controller/EditablePage.php
  32. 143 0
      app/admin/controller/Evaluate.php
  33. 254 0
      app/admin/controller/Exppoints.php
  34. 206 0
      app/admin/controller/Express.php
  35. 61 0
      app/admin/controller/Feedback.php
  36. 138 0
      app/admin/controller/Flea.php
  37. 495 0
      app/admin/controller/Fleaclass.php
  38. 80 0
      app/admin/controller/Fleaclassindex.php
  39. 237 0
      app/admin/controller/Flearegion.php
  40. 178 0
      app/admin/controller/Fleaseo.php
  41. 283 0
      app/admin/controller/Goods.php
  42. 169 0
      app/admin/controller/Goodsalbum.php
  43. 688 0
      app/admin/controller/Goodsclass.php
  44. 78 0
      app/admin/controller/Goodsvideo.php
  45. 588 0
      app/admin/controller/Groupbuy.php
  46. 110 0
      app/admin/controller/Index.php
  47. 446 0
      app/admin/controller/Inform.php
  48. 138 0
      app/admin/controller/InstantMessage.php
  49. 442 0
      app/admin/controller/Inviter.php
  50. 189 0
      app/admin/controller/Link.php
  51. 406 0
      app/admin/controller/LiveApply.php
  52. 125 0
      app/admin/controller/LiveGoods.php
  53. 82 0
      app/admin/controller/LiveSetting.php
  54. 105 0
      app/admin/controller/Login.php
  55. 265 0
      app/admin/controller/Mallconsult.php
  56. 276 0
      app/admin/controller/Mallvouchertemplate.php
  57. 291 0
      app/admin/controller/Marketmanage.php
  58. 284 0
      app/admin/controller/Member.php
  59. 140 0
      app/admin/controller/MemberAuth.php
  60. 90 0
      app/admin/controller/Membergrade.php
  61. 832 0
      app/admin/controller/Message.php
  62. 141 0
      app/admin/controller/Navigation.php
  63. 135 0
      app/admin/controller/Notice.php
  64. 183 0
      app/admin/controller/Offpayarea.php
  65. 105 0
      app/admin/controller/Operation.php
  66. 370 0
      app/admin/controller/Order.php
  67. 555 0
      app/admin/controller/Ownshop.php
  68. 223 0
      app/admin/controller/Payment.php
  69. 176 0
      app/admin/controller/Pointorder.php
  70. 504 0
      app/admin/controller/Pointprod.php
  71. 278 0
      app/admin/controller/Points.php
  72. 891 0
      app/admin/controller/Predeposit.php
  73. 227 0
      app/admin/controller/Promotionbargain.php
  74. 162 0
      app/admin/controller/Promotionbooth.php
  75. 186 0
      app/admin/controller/Promotionbundling.php
  76. 214 0
      app/admin/controller/Promotionmansong.php
  77. 142 0
      app/admin/controller/Promotionmgdiscount.php
  78. 202 0
      app/admin/controller/Promotionpintuan.php
  79. 191 0
      app/admin/controller/Promotionpresell.php
  80. 251 0
      app/admin/controller/Promotionwholesale.php
  81. 252 0
      app/admin/controller/Promotionxianshi.php
  82. 303 0
      app/admin/controller/Rechargecard.php
  83. 461 0
      app/admin/controller/Refund.php
  84. 340 0
      app/admin/controller/Region.php
  85. 379 0
      app/admin/controller/Returnmanage.php
  86. 53 0
      app/admin/controller/Seo.php
  87. 167 0
      app/admin/controller/Snsmalbum.php
  88. 266 0
      app/admin/controller/Snsmember.php
  89. 157 0
      app/admin/controller/Spec.php
  90. 296 0
      app/admin/controller/Stataftersale.php
  91. 273 0
      app/admin/controller/Statgeneral.php
  92. 316 0
      app/admin/controller/Statgoods.php
  93. 494 0
      app/admin/controller/Statindustry.php
  94. 367 0
      app/admin/controller/Statmarketing.php
  95. 889 0
      app/admin/controller/Statmember.php
  96. 932 0
      app/admin/controller/Statstore.php
  97. 666 0
      app/admin/controller/Stattrade.php
  98. 1073 0
      app/admin/controller/Store.php
  99. 189 0
      app/admin/controller/Storeclass.php
  100. 341 0
      app/admin/controller/Storedeposit.php

+ 7 - 0
apidoc.json

@@ -0,0 +1,7 @@
+{
+  "name": "DSMall多店铺B2B2C商城",
+  "version": "6.1.8",
+  "description": "DSMall多店铺B2B2C商城",
+  "title": "DSMall多店铺B2B2C商城",
+  "url" : "http://dsmall.csdeshang.com/"
+}

+ 1 - 0
app/.htaccess

@@ -0,0 +1 @@
+deny from all

+ 22 - 0
app/AppService.php

@@ -0,0 +1,22 @@
+<?php
+declare (strict_types = 1);
+
+namespace app;
+
+use think\Service;
+
+/**
+ * 应用服务类
+ */
+class AppService extends Service
+{
+    public function register()
+    {
+        // 服务注册
+    }
+
+    public function boot()
+    {
+        // 服务启动
+    }
+}

+ 205 - 0
app/BaseController.php

@@ -0,0 +1,205 @@
+<?php
+declare (strict_types = 1);
+
+namespace app;
+
+use think\App;
+use think\exception\ValidateException;
+use think\Validate;
+use think\facade\View;
+use think\exception\HttpResponseException;
+use think\Response;
+/**
+ * 控制器基础类
+ */
+abstract class BaseController
+{
+    /**
+     * Request实例
+     * @var \think\Request
+     */
+    protected $request;
+
+    /**
+     * 应用实例
+     * @var \think\App
+     */
+    protected $app;
+
+    /**
+     * 是否批量验证
+     * @var bool
+     */
+    protected $batchValidate = false;
+
+    /**
+     * 控制器中间件
+     * @var array
+     */
+    protected $middleware = [];
+
+    /**
+     * 构造方法
+     * @access public
+     * @param  App  $app  应用对象
+     */
+    public function __construct(App $app)
+    {
+        $this->app     = $app;
+        $this->request = $this->app->request;
+
+        // 控制器初始化
+        $this->initialize();
+    }
+
+    // 初始化
+    protected function initialize()
+    {}
+
+    /**
+     * 验证数据
+     * @access protected
+     * @param  array        $data     数据
+     * @param  string|array $validate 验证器名或者验证规则数组
+     * @param  array        $message  提示信息
+     * @param  bool         $batch    是否批量验证
+     * @return array|string|true
+     * @throws ValidateException
+     */
+    protected function validate(array $data, $validate, array $message = [], bool $batch = false)
+    {
+        if (is_array($validate)) {
+            $v = new Validate();
+            $v->rule($validate);
+        } else {
+            if (strpos($validate, '.')) {
+                // 支持场景
+                [$validate, $scene] = explode('.', $validate);
+            }
+            $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
+            $v     = new $class();
+            if (!empty($scene)) {
+                $v->scene($scene);
+            }
+        }
+
+        $v->message($message);
+
+        // 是否批量验证
+        if ($batch || $this->batchValidate) {
+            $v->batch(true);
+        }
+
+        return $v->failException(true)->check($data);
+    }
+    
+    /**
+     * 操作成功跳转的快捷方法
+     * @access protected
+     * @param  mixed $msg 提示信息
+     * @param  string $url 跳转的URL地址
+     * @param  mixed $data 返回的数据
+     * @param  integer $wait 跳转等待时间
+     * @param  array $header 发送的Header信息
+     * @return void
+     */
+    protected function success($msg = '', string $url = null, $data = '', int $wait = 3, array $header = [])
+    {
+        if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
+            $url = $_SERVER["HTTP_REFERER"];
+        } elseif ($url) {
+            $url=(string)$url;
+            $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : (string)$this->app->route->buildUrl($url);
+        }
+
+        $result = [
+            'code' => 1,
+            'msg' => $msg,
+            'data' => $data,
+            'url' => $url,
+            'wait' => $wait,
+        ];
+
+        $type = $this->getResponseType();
+        // 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
+        if ('html' == strtolower($type)) {
+            $type = 'view';
+            $response = Response::create($this->app->config->get('jump.dispatch_success_tmpl'), $type)->assign($result)->header($header);
+        } else {
+            $response = Response::create($result, $type)->header($header);
+        }
+
+        throw new HttpResponseException($response);
+    }
+
+    /**
+     * 操作错误跳转的快捷方法
+     * @access protected
+     * @param  mixed $msg 提示信息
+     * @param  string $url 跳转的URL地址
+     * @param  mixed $data 返回的数据
+     * @param  integer $wait 跳转等待时间
+     * @param  array $header 发送的Header信息
+     * @return void
+     */
+    protected function error($msg = '', string $url = null, $data = '', int $wait = 3, array $header = [])
+    {
+        if (is_null($url)) {
+            $url = $this->request->isAjax() ? '' : 'javascript:history.back(-1);';
+        } elseif ($url) {
+            $url=(string)$url;
+            $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : (string)$this->app->route->buildUrl($url);
+        }
+
+        $result = [
+            'code' => 0,
+            'msg' => $msg,
+            'data' => $data,
+            'url' => $url,
+            'wait' => $wait,
+        ];
+
+        $type = $this->getResponseType();
+
+        if ('html' == strtolower($type)) {
+            $type = 'view';
+            $response = Response::create($this->app->config->get('jump.dispatch_error_tmpl'), $type)->assign($result)->header($header);
+        } else {
+            $response = Response::create($result, $type)->header($header);
+        }
+
+        throw new HttpResponseException($response);
+    }
+
+    /**
+     * URL重定向
+     * @access protected
+     * @param  string $url 跳转的URL表达式
+     * @param  integer $code http code
+     * @param  array $with 隐式传参
+     * @return void
+     */
+    protected function redirect($url, $params = [], $code = 302, $with = [])
+    {
+        $url=(string)$url;
+        $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : (string)$this->app->route->buildUrl($url,$params);
+        
+        $response = Response::create($url, 'redirect');
+
+        $response->code($code)->with($with);
+
+        throw new HttpResponseException($response);
+    }
+
+    /**
+     * 获取当前的 response 输出类型
+     * @access protected
+     * @return string
+     */
+    protected function getResponseType()
+    {
+        return request()->isAjax()
+            ? 'json'
+            : 'html';
+    }
+}

+ 58 - 0
app/ExceptionHandle.php

@@ -0,0 +1,58 @@
+<?php
+namespace app;
+
+use think\db\exception\DataNotFoundException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\Handle;
+use think\exception\HttpException;
+use think\exception\HttpResponseException;
+use think\exception\ValidateException;
+use think\Response;
+use Throwable;
+
+/**
+ * 应用异常处理类
+ */
+class ExceptionHandle extends Handle
+{
+    /**
+     * 不需要记录信息(日志)的异常类列表
+     * @var array
+     */
+    protected $ignoreReport = [
+        HttpException::class,
+        HttpResponseException::class,
+        ModelNotFoundException::class,
+        DataNotFoundException::class,
+        ValidateException::class,
+    ];
+
+    /**
+     * 记录异常信息(包括日志或者其它方式记录)
+     *
+     * @access public
+     * @param  Throwable $exception
+     * @return void
+     */
+    public function report(Throwable $exception): void
+    {
+        // 使用内置的方式记录异常日志
+        parent::report($exception);
+    }
+
+    /**
+     * Render an exception into an HTTP response.
+     *
+     * @access public
+     * @param \think\Request   $request
+     * @param Throwable $e
+     * @return Response
+     */
+    public function render($request, Throwable $e): Response
+    {
+        // 添加自定义异常处理机制
+
+        // 其他错误交给系统处理
+        return parent::render($request, $e);
+    }
+}

+ 8 - 0
app/Request.php

@@ -0,0 +1,8 @@
+<?php
+namespace app;
+
+// 应用请求对象类
+class Request extends \think\Request
+{
+protected $filter = ['htmlspecialchars'];
+}

+ 2 - 0
app/admin/common.php

@@ -0,0 +1,2 @@
+<?php
+

+ 7 - 0
app/admin/config/jump.php

@@ -0,0 +1,7 @@
+<?php
+return[
+    //默认错误跳转对应的模板文件
+    'dispatch_error_tmpl' => 'public:dispatch_jump',
+    //默认成功跳转对应的模板文件
+    'dispatch_success_tmpl' => 'public:dispatch_jump',
+];

+ 19 - 0
app/admin/config/session.php

@@ -0,0 +1,19 @@
+<?php
+// +----------------------------------------------------------------------
+// | 会话设置
+// +----------------------------------------------------------------------
+
+return [
+    // session name
+    'name'           => 'PHPSESSID',
+    // SESSION_ID的提交变量,解决flash上传跨域
+    'var_session_id' => '',
+    // 驱动方式 支持file cache
+    'type'           => 'file',
+    // 存储连接标识 当type使用cache的时候有效
+    'store'          => null,
+    // 过期时间
+    'expire'         => 86400,
+    // 前缀
+    'prefix'         => 'admin',
+];

+ 167 - 0
app/admin/controller/Account.php

@@ -0,0 +1,167 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Account extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/account.lang.php');
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/config.lang.php');
+    }
+
+    /**
+     * 设置
+     */
+    public function setting() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('setting');
+            return View::fetch();
+        } else {
+            $update_array=array();
+            $update_array['auto_register'] = input('post.auto_register');
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log(lang('ds_edit').lang('ds_account'),1);
+                $this->success(lang('ds_common_save_succ'));
+            }else{
+                $this->log(lang('ds_edit').lang('ds_account'),0);
+            }
+        }
+    }
+    
+    /**
+     * QQ互联
+     */
+    function qq() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+
+            //输出子菜单
+            $this->setAdminCurItem('qq');
+            return View::fetch('qq');
+        } else {
+            $update_array = array();
+            $update_array['qq_isuse'] = input('post.qq_isuse');
+            $update_array['qq_appid'] = input('post.qq_appid');
+            $update_array['qq_appkey'] = input('post.qq_appkey');
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit').lang('qq_settings'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit').lang('qq_settings'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * sina微博设置
+     */
+    public function sina() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+
+            //输出子菜单
+            $this->setAdminCurItem('sina');
+            return View::fetch('sina');
+        } else {
+            $update_array = array();
+            $update_array['sina_isuse'] = input('post.sina_isuse');
+            $update_array['sina_wb_akey'] = input('post.sina_wb_akey');
+            $update_array['sina_wb_skey'] = input('post.sina_wb_skey');
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit').lang('sina_settings'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit').lang('sina_settings'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 微信登录设置
+     */
+    public function wx() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            //输出子菜单
+            $this->setAdminCurItem('wx');
+            return View::fetch('wx');
+        } else {
+            $update_array = array();
+            $update_array['weixin_isuse'] = input('post.weixin_isuse');
+            $update_array['weixin_appid'] = input('post.weixin_appid');
+            $update_array['weixin_secret'] = input('post.weixin_secret');
+            
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log(lang('account_synchronous_login'));
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'setting',
+                'text' => lang('account_setting'),
+                'url' => (string)url('Account/setting')
+            ),
+            array(
+                'name' => 'qq',
+                'text' => lang('qq_interconnection'),
+                'url' => (string)url('Account/qq')
+            ),
+            array(
+                'name' => 'sina',
+                'text' => lang('sina_interconnection'),
+                'url' => (string)url('Account/sina')
+            ),
+            array(
+                'name' => 'wx',
+                'text' => lang('wx_login'),
+                'url' => (string)url('Account/wx')
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 415 - 0
app/admin/controller/Activity.php

@@ -0,0 +1,415 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Activity extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/activity.lang.php');
+    }
+
+    /**
+     * 活动列表/删除活动
+     */
+    public function index() {
+        $activity_model = model('activity');
+        //条件
+        $condition = array();
+        $condition[] = array('activity_type','=','1'); //只显示商品活动
+        //状态
+        if ((input('param.searchstate'))) {
+            $state = intval(input('param.searchstate')) - 1;
+            $condition[] = array('activity_state','=',"$state");
+        }
+        //标题
+        if ((input('param.searchtitle'))) {
+            $condition[]=array('activity_title','like', "%" . input('param.searchtitle') . "%");
+        }
+        //有效期范围
+        if ((input('param.searchstartdate')) && (input('param.searchenddate'))) {
+            $startdate = strtotime(input('param.searchstartdate'));
+            $enddate = strtotime(input('param.searchenddate'));
+            if ($enddate > 0) {
+                $enddate += 86400;
+            }
+            $condition[]=array('activity_enddate','>=',$startdate);
+            $condition[]=array('activity_startdate','<=',$enddate);
+        }
+        //活动列表
+        $activity_list = $activity_model->getActivityList($condition, 10 , 'activity_sort asc');
+        //输出
+        View::assign('show_page', $activity_model->page_info->render());
+        View::assign('activity_list', $activity_list);
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 新建活动/保存新建活动
+     */
+    public function add() {
+        if (request()->isPost()) {
+            //提交表单
+            $data = [
+                'activity_title' => input('post.activity_title'),
+                'activity_startdate' => strtotime(input('post.activity_startdate')),
+                'activity_enddate' => strtotime(input('post.activity_enddate')),
+                'activity_type' => input('post.activity_type'),
+                'activity_banner' => $_FILES['activity_banner']['name'],
+                'activity_banner_mobile' => $_FILES['activity_banner_mobile']['name'],
+                'activity_sort' => intval(input('post.activity_sort'))
+            ];
+            $activity_validate = ds_validate('activity');
+            if (!$activity_validate->scene('add')->check($data)) {
+                $this->error($activity_validate->getError());
+            }
+
+            $file_name = '';
+            if (!empty($_FILES['activity_banner']['name'])) {
+                $res=ds_upload_pic(ATTACH_ACTIVITY,'activity_banner');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+            //保存
+            $data['activity_banner'] = $file_name;
+            
+            $file_name_mobile = '';
+            if (!empty($_FILES['activity_banner_mobile']['name'])) {
+                $res=ds_upload_pic(ATTACH_ACTIVITY,'activity_banner_mobile');
+                if($res['code']){
+                    $file_name_mobile=$res['data']['file_name'];
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+            //保存
+            $data['activity_banner_mobile'] = $file_name_mobile;
+            $data['activity_desc'] = trim(input('post.activity_desc'));
+            $data['activity_state'] = intval(input('post.activity_state'));
+
+            $activity_model = model('activity');
+            $result = $activity_model->addActivity($data);
+            if ($result) {
+                $this->log(lang('ds_add') . lang('activity_index') . '[' . input('post.activity_title') . ']', null);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                //添加失败则删除刚刚上传的图片,节省空间资源
+                @unlink($upload_file . DIRECTORY_SEPARATOR . $file_name);
+                @unlink($upload_file . DIRECTORY_SEPARATOR . $file_name_mobile);
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+            $activity = array(
+                'activity_type' => '1',
+                'activity_startdate' => TIMESTAMP,
+                'activity_enddate' => TIMESTAMP,
+                'activity_banner' => '',
+                'activity_desc' => '',
+                'activity_state' => '1',
+            );
+            View::assign('activity', $activity);
+            return View::fetch('form');
+        }
+    }
+
+    /**
+     * 异步修改
+     */
+    public function ajax() {
+        if (in_array(input('param.branch'), array('activity_title', 'activity_sort'))) {
+            $activity_model = model('activity');
+            $update_array = array();
+            switch (input('param.branch')) {
+                /**
+                 * 活动主题
+                 */
+                case 'activity_title':
+                    if (trim(input('param.value')) == '')
+                        exit;
+                    break;
+                /**
+                 * 排序
+                 */
+                case 'activity_sort':
+                    if (preg_match('/^\d+$/', trim(input('param.value'))) <= 0 or intval(trim(input('param.value'))) < 0 or intval(trim(input('param.value'))) > 255)
+                        exit;
+                    break;
+                default:
+                    exit;
+            }
+            $update_array[input('param.column')] = trim(input('param.value'));
+            if ($activity_model->editActivity($update_array, intval(input('param.id'))))
+                echo 'true';
+        }elseif (in_array(input('param.branch'), array('activitydetail_sort'))) {
+            $activitydetail_model = model('activitydetail');
+            $update_array = array();
+            switch (input('param.branch')) {
+                /**
+                 * 排序
+                 */
+                case 'activitydetail_sort':
+                    if (preg_match('/^\d+$/', trim(input('param.value'))) <= 0 or intval(trim(input('param.value'))) < 0 or intval(trim(input('param.value'))) > 255)
+                        exit;
+                    break;
+                default:
+                    exit;
+            }
+            $update_array[input('param.column')] = trim(input('param.value'));
+            if ($activitydetail_model->editActivitydetail($update_array, array(array('activitydetail_id','=',intval(input('param.id'))))))
+                echo 'true';
+        }
+    }
+
+    /**
+     * 删除活动
+     */
+    public function del() {
+        $id = intval(input('param.activity_id'));
+        if ($id <= 0) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+
+        $activity_model = model('activity');
+        $activitydetail_model = model('activitydetail');
+        //获取可以删除的数据
+        $activity_info = $activity_model->getOneActivityById($id);
+        if (empty($activity_info) || ($activity_info['activity_state'] && $activity_info['activity_enddate']>TIMESTAMP)) {//没有符合条件的活动信息直接返回成功信息
+            ds_json_encode(10001, lang('activity_index_help3'));
+        }
+        $id_arr = array($activity_info['activity_id']);
+        $condition = array();
+        $condition[] = array('activity_id','in',$id_arr);
+        //只有关闭或者过期的活动,能删除
+        if ($activitydetail_model->getActivitydetailList($condition)) {
+            if (!$activitydetail_model->delActivitydetail($condition)) {
+                ds_json_encode(10001, lang('activity_del_fail'));
+            }
+        }
+        try {
+            //删除数据先删除横幅图片,节省空间资源
+            foreach ($id_arr as $v) {
+                $this->delBanner(intval($v));
+            }
+        } catch (Exception $e) {
+            ds_json_encode(10001, $e->getMessage());
+        }
+        if ($activity_model->delActivity($condition)) {
+            $this->log(lang('ds_del') . lang('activity_index') . '[ID:' . $id . ']', null);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        }
+        ds_json_encode(10001, lang('activity_del_fail'));
+    }
+
+    /**
+     * 编辑活动/保存编辑活动
+     */
+    public function edit() {
+        $activity_id = intval(input('param.activity_id'));
+        if ($activity_id<=0) {
+            $this->error(lang('miss_argument'));
+        }
+        $activity_model = model('activity');
+        $activity = $activity_model->getOneActivityById($activity_id);
+        if (!request()->isPost()) {
+            View::assign('activity', $activity);
+            return View::fetch('form');
+        } else {
+            //提交表单
+            $data = [
+                'activity_title' => input('post.activity_title'),
+                'activity_startdate' => strtotime(input('post.activity_startdate')),
+                'activity_enddate' => strtotime(input('post.activity_enddate')),
+                'activity_type' => input('post.activity_type'),
+                'activity_sort' => intval(input('post.activity_sort'))
+            ];
+            $activity_validate = ds_validate('activity');
+            if (!$activity_validate->scene('edit')->check($data)) {
+                $this->error($activity_validate->getError());
+            }
+            //构造更新内容
+            $file_name = '';
+            if ($_FILES['activity_banner']['name'] != '') {
+                $res=ds_upload_pic(ATTACH_ACTIVITY,'activity_banner');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+					$data['activity_banner'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+                
+            }
+            $file_name_mobile = '';
+            if ($_FILES['activity_banner_mobile']['name'] != '') {
+                $res=ds_upload_pic(ATTACH_ACTIVITY,'activity_banner_mobile');
+                if($res['code']){
+                    $file_name_mobile=$res['data']['file_name'];
+					$data['activity_banner_mobile'] = $file_name_mobile;
+                }else{
+                    $this->error($res['msg']);
+                }
+                
+            }
+            $data['activity_desc'] = trim(input('post.activity_desc'));
+            $data['activity_state'] = intval(input('post.activity_state'));
+            
+            $result = $activity_model->editActivity($data, $activity_id);
+            if ($result) {
+                //删除图片
+                @unlink($upload_file . DIRECTORY_SEPARATOR .$activity['activity_banner']);
+                @unlink($upload_file . DIRECTORY_SEPARATOR .$activity['activity_banner_mobile']);
+                $this->log(lang('ds_edit') . lang('activity_index') . '[ID:' . $activity_id . ']', null);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                if ($_FILES['activity_banner']['name'] != '') {
+                    @unlink($upload_file . DIRECTORY_SEPARATOR .$file_name);
+                }
+                if ($_FILES['activity_banner_mobile']['name'] != '') {
+                    @unlink($upload_file . DIRECTORY_SEPARATOR .$file_name_mobile);
+                }
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 活动细节列表
+     */
+    public function detail() {
+        $activity_id = intval(input('param.id'));
+        if ($activity_id <= 0) {
+            $this->error(lang('miss_argument'));
+        }
+        //条件
+        $condition_arr = array();
+        $condition_arr[] = array('activity_id','=',$activity_id);
+        //审核状态
+        if ((input('param.searchstate'))) {
+            $state = intval(input('param.searchstate')) - 1;
+            $condition_arr[] = array('activitydetail_state','=',"$state");
+        }
+        //店铺名称
+        if ((input('param.searchstore'))) {
+            $condition_arr[] = array('store_name','like', "%" . input('param.searchstore') . "%");
+        }
+        //商品名称
+        if ((input('param.searchgoods'))) {
+            $condition_arr[] = array('item_name','like', "%" . input('param.searchgoods') . "%");
+        }
+
+        $activitydetail_model = model('activitydetail');
+        $activitydetail_list = $activitydetail_model->getActivitydetailList($condition_arr, 10);
+        //输出到模板
+        View::assign('show_page', $activitydetail_model->page_info->render());
+        View::assign('activitydetail_list', $activitydetail_list);
+        $this->setAdminCurItem('detail');
+        return View::fetch();
+    }
+
+    /**
+     * 活动内容处理
+     */
+    public function deal() {
+        $activitydetail_id = input('param.activitydetail_id');
+        $activitydetail_id_array = ds_delete_param($activitydetail_id);
+        if ($activitydetail_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('activitydetail_id','in',$activitydetail_id_array);
+
+        //创建活动内容对象
+        $activitydetail_state = intval(input('param.state'));
+        $result = model('activitydetail')->editActivitydetail(array('activitydetail_state' => $activitydetail_state),$condition);
+        if ($result>=0) {
+            $this->log(lang('ds_edit') . lang('activity_index') . '[ID:' . $activitydetail_id . ']', null);
+            if (input('param.ajax')) {
+                ds_json_encode(10000,lang('ds_common_op_succ'));
+            }else{
+                $this->success(lang('ds_common_op_succ'));
+            }
+            
+        } else {
+            if (input('param.ajax')) {
+                ds_json_encode(10001,lang('ds_common_op_fail'));
+            }else{
+                $this->error(lang('ds_common_op_fail'));
+            }
+            
+        }
+    }
+    /**
+     * 删除活动内容
+     */
+    public function del_detail() {
+        $activitydetail_id = input('param.activitydetail_id');
+        $activitydetail_id_array = ds_delete_param($activitydetail_id);
+        if ($activitydetail_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+
+        $activitydetail_model = model('activitydetail');
+        //条件
+        $condition_arr = array();
+        $condition_arr[] =array('activitydetail_id','in',$activitydetail_id_array);
+        $condition_arr[] = array('activitydetail_state','in',array('0','2'));//未审核和已拒绝
+        if ($activitydetail_model->delActivitydetail($condition_arr)) {
+            $this->log(lang('ds_del') . lang('activity_index_content') . '[ID:' . implode(',', $activitydetail_id_array) . ']', null);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 根据活动编号删除横幅图片
+     *
+     * @param int $id
+     */
+    private function delBanner($id) {
+        $activity_model = model('activity');
+        $row = $activity_model->getOneActivityById($id);
+        //删除图片文件
+        @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ACTIVITY . DIRECTORY_SEPARATOR . $row['activity_banner']);
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string)url('Activity/index')
+            ), array(
+                'name' => 'add',
+                'text' => lang('ds_new'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Activity/add')."','".lang('ds_new')."')"
+            ),
+        );
+        if (request()->action() == 'detail') {
+            $menu_array[] = array(
+                'name' => 'detail', 'text' => lang('processing_application'), 'url' => 'javascript:void(0)'
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 321 - 0
app/admin/controller/Admin.php

@@ -0,0 +1,321 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Admin extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/admin.lang.php');
+    }
+
+    /**
+     * 管理员列表
+     */
+    public function admin() {
+        $admin_mod = model('admin');
+        $condition = array();
+        $admin_list = $admin_mod->getAdminList($condition, 10);
+        View::assign('admin_list', $admin_list);
+        View::assign('show_page', $admin_mod->page_info->render());
+        $this->setAdminCurItem('admin');
+        return View::fetch('admin');
+    }
+
+    /**
+     * 管理员删除
+     */
+    public function admin_del() {
+        $admin_id = intval(input('param.admin_id'));
+        if (!empty($admin_id)) {
+            if ($admin_id == 1) {
+                $this->error(lang('ds_common_save_fail'));
+            }
+            $admin_mod = model('admin');
+            $admin_mod->delAdmin(array(array('admin_id' ,'=', $admin_id)));
+            $this->log(lang('ds_del') . lang('limit_admin') . '[ID:' . $admin_id . ']', 1);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 管理员添加
+     */
+    public function admin_add() {
+        $admin_model = model('admin');
+        if (!request()->isPost()) {
+            //得到权限组
+            $gadmin = $admin_model->getGadminList('gname,gid');
+            View::assign('gadmin', $gadmin);
+            return View::fetch('admin_form');
+        } else {
+            $data['admin_name'] = input('post.admin_name');
+            $data['admin_gid'] = input('post.gid');
+            $data['admin_password'] = md5(input('post.admin_password'));
+            if(empty(input('post.admin_password'))){
+                $this->error(lang('admin_add_password_null'));
+            }
+            $admin_validate = ds_validate('admin');
+            if (!$admin_validate->scene('admin_add')->check($data)) {
+                $this->error($admin_validate->getError());
+            }
+            //判断是否重名
+            $admin_info=$admin_model->getOneAdmin(array(array('admin_name','=',$data['admin_name'])));
+            if($admin_info){
+                $this->error(lang('admin_add_admin_not_exists'));
+            }
+            $rs = $admin_model->addAdmin($data);
+            if ($rs) {
+                $this->log(lang('ds_add') . lang('limit_admin') . '[' . input('post.admin_name') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $admin_model = model('admin');
+        switch (input('get.branch')) {
+            //管理人员名称验证
+            case 'check_admin_name':
+                $condition[]=array('admin_name','=',input('get.admin_name'));
+                $admin_info = $admin_model->infoAdmin($condition);
+                if (!empty($admin_info)) {
+                    exit('false');
+                } else {
+                    exit('true');
+                }
+                break;
+            //权限组名称验证
+            case 'check_gadmin_name':
+                $condition = array();
+                if (is_numeric(input('param.gid'))) {
+                    $condition[]=array('gid','<>', intval(input('param.gid')));
+                }
+                $condition[]=array('gname','=',input('get.gname'));
+                $info = $admin_model->getOneGadmin($condition);
+                if (!empty($info)) {
+                    exit('false');
+                } else {
+                    exit('true');
+                }
+                break;
+        }
+    }
+
+    /**
+     * 设置管理员权限
+     */
+    public function admin_edit() {
+        $admin_id = intval(input('param.admin_id'));
+        if (request()->isPost()) {
+            //没有更改密码
+            if (input('post.admin_password') != '') {
+                $data['admin_password'] = md5(input('post.admin_password'));
+            }
+            $data['admin_gid'] = intval(input('post.gid'));
+            //查询管理员信息
+            $admin_model = model('admin');
+            $result = $admin_model->editAdmin($data, $admin_id);
+            if ($result) {
+                $this->log(lang('ds_edit') . lang('limit_admin') . '[ID:' . $admin_id . ']', 1);
+                dsLayerOpenSuccess(lang('admin_edit_success'));
+            } else {
+                $this->error(lang('admin_edit_fail'));
+            }
+        } else {
+            //查询用户信息
+            $admin_model = model('admin');
+            $admin = $admin_model->getOneAdmin(array(array('admin_id' ,'=', $admin_id)));
+            if (!is_array($admin) || count($admin) <= 0) {
+                $this->error(lang('admin_edit_admin_error'), (string)url('admin/admin'));
+            }
+            View::assign('admin', $admin);
+
+            //得到权限组
+            $gadmin = $admin_model->getGadminList('gname,gid');
+            View::assign('gadmin', $gadmin);
+            return View::fetch('admin_form');
+        }
+    }
+
+    /**
+     * 取得所有权限项
+     *
+     * @return array
+     */
+    private function permission() {
+        $limit = $this->limitList();
+        if (is_array($limit)) {
+            foreach ($limit as $k => $v) {
+                if (is_array($v['child'])) {
+                    $tmp = array();
+                    foreach ($v['child'] as $key => $value) {
+                        $controller = (!empty($value['controller'])) ? $value['controller'] : $v['controller'];
+                        if (strpos($controller, '|') == false) {//controller参数不带|
+                            $limit[$k]['child'][$key]['action'] = rtrim($controller . '.' . str_replace('|', '|' . $controller . '.', $value['action']), '.');
+                        } else {//controller参数带|
+                            $tmp_str = '';
+                            if (empty($value['action'])) {
+                                $limit[$k]['child'][$key]['action'] = $controller;
+                            } elseif (strpos($value['action'], '|') == false) {//action参数不带|
+                                foreach (explode('|', $controller) as $v1) {
+                                    $tmp_str .= "$v1.{$value['action']}|";
+                                }
+                                $limit[$k]['child'][$key]['action'] = rtrim($tmp_str, '|');
+                            } elseif (strpos($value['action'], '|') != false && strpos($controller, '|') != false) {//action,controller都带|,交差权限
+                                foreach (explode('|', $controller) as $v1) {
+                                    foreach (explode('|', $value['action']) as $v2) {
+                                        $tmp_str .= "$v1.$v2|";
+                                    }
+                                }
+                                $limit[$k]['child'][$key]['action'] = rtrim($tmp_str, '|');
+                            }
+                        }
+                    }
+                }
+            }
+            return $limit;
+        } else {
+            return array();
+        }
+    }
+
+    /**
+     * 权限组
+     */
+    public function gadmin() {
+        $admin_model = model('admin');
+        $gadmin_list = $admin_model->getGadminList();
+        View::assign('gadmin_list', $gadmin_list);
+        $this->setAdminCurItem('gadmin');
+        return View::fetch('gadmin');
+    }
+
+    /**
+     * 添加权限组
+     */
+    public function gadmin_add() {
+        if (!request()->isPost()) {
+            View::assign('limit', $this->permission());
+            return View::fetch('gadmin_add');
+        } else {
+            $limit_str = '';
+            $permission_array = input('post.permission/a');
+            if (is_array($permission_array)) {
+                $limit_str = implode('|', $permission_array);
+            }
+            $data['glimits'] = ds_encrypt($limit_str, MD5_KEY . md5(input('post.gname')));
+            $data['gname'] = input('post.gname');
+            $admin_model = model('admin');
+            if ($admin_model->addGadmin($data)) {
+                $this->log(lang('ds_add') . lang('limit_gadmin') . '[' . input('post.gname') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 设置权限组权限
+     */
+    public function gadmin_set() {
+        $gid = intval(input('param.gid'));
+        $admin_model = model('admin');
+        $ginfo = $admin_model->getOneGadmin(array(array('gid' ,'=', $gid)));
+        if (empty($ginfo)) {
+            $this->error(lang('admin_set_admin_not_exists'));
+        }
+        if (!request()->isPost()) {
+            //解析已有权限
+            $hlimit = ds_decrypt($ginfo['glimits'], MD5_KEY . md5($ginfo['gname']));
+            $ginfo['glimits'] = explode('|', $hlimit);
+            View::assign('ginfo', $ginfo);
+            View::assign('limit', $this->permission());
+            return View::fetch('gadmin_set');
+        } else {
+            $limit_str = '';
+            $permission_array = input('post.permission/a');
+            if (is_array($permission_array)) {
+                $limit_str = implode('|', $permission_array);
+            }
+            $limit_str = ds_encrypt($limit_str, MD5_KEY . md5(input('post.gname')));
+            $data['glimits'] = $limit_str;
+            $data['gname'] = input('post.gname');
+            $update = $admin_model->editGadmin(array(array('gid' ,'=', $gid)), $data);
+            if ($update) {
+                $this->log(lang('ds_edit') . lang('limit_gadmin') . '[' . input('post.gname') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_succ'));
+            }
+        }
+    }
+
+    /**
+     * 组删除
+     */
+    public function gadmin_del() {
+        if (is_numeric(input('param.gid'))) {
+            $admin_model = model('admin');
+            $admin_model->delGadmin(array(array('gid' ,'=', intval(input('param.gid')))));
+            $this->log(lang('ds_del') . lang('limit_gadmin') . '[ID' . intval(input('param.gid')) . ']', 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10000, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'admin',
+                'text' => lang('limit_admin'),
+                'url' => (string)url('admin/admin')
+            ),
+            array(
+                'name' => 'admin_add',
+                'text' => lang('admin_add_limit_admin'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('admin/admin_add') . "','".lang('admin_add_limit_admin')."')"
+            ),
+            array(
+                'name' => 'gadmin',
+                'text' => lang('limit_gadmin'),
+                'url' => (string)url('admin/gadmin')
+            ),
+            array(
+                'name' => 'gadmin_add',
+                'text' => lang('admin_add_limit_gadmin'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('admin/gadmin_add') . "','".lang('admin_add_limit_gadmin')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 895 - 0
app/admin/controller/AdminControl.php

@@ -0,0 +1,895 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use app\BaseController;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class AdminControl extends BaseController {
+
+    /**
+     * 管理员资料 name id group
+     */
+    protected $admin_info;
+
+    protected $permission;
+    public function initialize() {
+        $config_list = rkcache('config', true);
+        config($config_list,'ds_config');
+        
+        if(request()->controller()!='Login'){
+            $this->admin_info = $this->systemLogin();
+
+            if ($this->admin_info['admin_id'] != 1) {
+                // 验证权限
+                $this->checkPermission();
+            }
+            $this->setMenuList();
+        }
+    }
+
+    /**
+     * 取得当前管理员信息
+     *
+     * @param
+     * @return 数组类型的返回结果
+     */
+    protected final function getAdminInfo() {
+        return $this->admin_info;
+    }
+
+    /**
+     * 系统后台登录验证
+     *
+     * @param
+     * @return array 数组类型的返回结果
+     */
+    protected final function systemLogin() {
+        $admin_info = array(
+            'admin_id' => session('admin_id'),
+            'admin_name' => session('admin_name'),
+            'admin_gid' => session('admin_gid'),
+            'admin_is_super' => session('admin_is_super'),
+        );
+        if (empty($admin_info['admin_id']) || empty($admin_info['admin_name']) || !isset($admin_info['admin_gid']) || !isset($admin_info['admin_is_super'])) {
+            session(null);
+            $this->redirect('admin/Login/index');
+        }
+
+        return $admin_info;
+    }
+
+    public function setMenuList() {
+        $menu_list = $this->menuList();
+
+        $menu_list=$this->parseMenu($menu_list);
+        View::assign('menu_list', $menu_list);
+    }
+
+    /**
+     * 验证当前管理员权限是否可以进行操作
+     *
+     * @param string $link_nav
+     * @return
+     */
+    protected final function checkPermission($link_nav = null){
+        if ($this->admin_info['admin_is_super'] == 1) return true;
+
+        $controller = request()->controller();
+        $action = request()->action();
+        if (empty($this->permission)){
+            
+            $admin_model=model('admin');
+            $gadmin = $admin_model->getOneGadmin(array('gid'=>$this->admin_info['admin_gid']));
+            
+            $permission = ds_decrypt($gadmin['glimits'],MD5_KEY.md5($gadmin['gname']));
+            $this->permission = $permission = explode('|',$permission);
+        }else{
+            $permission = $this->permission;
+        }
+        //显示隐藏小导航,成功与否都直接返回
+        if (is_array($link_nav)){
+            if (!in_array("{$link_nav['controller']}.{$link_nav['action']}",$permission) && !in_array($link_nav['controller'],$permission)){
+                return false;
+            }else{
+                return true;
+            }
+        }
+        //以下几项不需要验证
+        $tmp = array('Index','Dashboard','Login');
+        if (in_array($controller,$tmp)){
+            return true;
+        }
+        if (in_array($controller,$permission) || in_array("$controller.$action",$permission)){
+            return true;
+        }else{
+            $extlimit = array('ajax','export_step1');
+            if (in_array($action,$extlimit) && (in_array($controller,$permission) || strpos(serialize($permission),'"'.$controller.'.'))){
+                return true;
+            }
+            //带前缀的都通过
+            foreach ($permission as $v) {
+                if (!empty($v) && strpos("$controller.$action",$v.'_') !== false) {
+                    return true;break;
+                }
+            }
+        }
+        if($this->admin_info['admin_name']!='dsmall'){
+            $this->error(lang('ds_assign_right'),'Dashboard/welcome');
+        }else if(request()->isPost() || preg_match('/del/',request()->action())){
+            $this->error(lang('ds_assign_right'));
+        }
+    }
+
+    /**
+     * 过滤掉无权查看的菜单
+     *
+     * @param array $menu
+     * @return array
+     */
+    private final function parseMenu($menu = array()) {
+        if ($this->admin_info['admin_is_super'] == 1) {
+            return $menu;
+        }
+        foreach ($menu as $k => $v) {
+            foreach ($v['children'] as $ck => $cv) {
+                $tmp = explode(',', $cv['args']);
+                //以下几项不需要验证
+                $except = array('Index', 'Dashboard', 'Login');
+                if (in_array($tmp[1], $except))
+                    continue;
+                if (!in_array($tmp[1], array_values($this->permission)) && !in_array($tmp[1].'.'.$tmp[0], array_values($this->permission))) {
+                    if($this->admin_info['admin_name']!='dsmall'){
+                        unset($menu[$k]['children'][$ck]);
+                    }
+                }
+            }
+            if (empty($menu[$k]['children'])) {
+                unset($menu[$k]);
+                unset($menu[$k]['children']);
+            }
+        }
+        return $menu;
+    }
+
+    /**
+     * 记录系统日志
+     *
+     * @param $lang 日志语言包
+     * @param $state 1成功0失败null不出现成功失败提示
+     * @param $admin_name
+     * @param $admin_id
+     */
+    protected final function log($lang = '', $state = 1, $admin_name = '', $admin_id = 0) {
+        if ($admin_name == '') {
+            $admin_name = session('admin_name');
+            $admin_id = session('admin_id');
+        }
+        $data = array();
+        if (is_null($state)) {
+            $state = null;
+        } else {
+            $state = $state ? '' : lang('ds_fail');
+        }
+        $data['adminlog_content'] = $lang . $state;
+        $data['adminlog_time'] = TIMESTAMP;
+        $data['admin_name'] = $admin_name;
+        $data['admin_id'] = $admin_id;
+        $data['adminlog_ip'] = request()->ip();
+        $data['adminlog_url'] = request()->controller() . '&' . request()->action();
+        
+        $adminlog_model=model('adminlog');
+        return $adminlog_model->addAdminlog($data);
+    }
+
+    /**
+     * 添加到任务队列
+     *
+     * @param array $goods_array
+     * @param boolean $ifdel 是否删除以原记录
+     */
+    protected function addcron($data = array(), $ifdel = false) {
+        $cron_model = model('cron');
+        if (isset($data[0])) { // 批量插入
+            $where = array();
+            foreach ($data as $k => $v) {
+                // 删除原纪录条件
+                if ($ifdel) {
+                    $where[] = '(cron_type = "' . $data['cron_type'] . '" and cron_value = "' . $data['cron_value'] . '")';
+                }
+            }
+            // 删除原纪录
+            if ($ifdel) {
+                $cron_model->delCron(implode(',', $where));
+            }
+            $cron_model->addCronAll($data);
+        } else { // 单条插入
+            // 删除原纪录
+            if ($ifdel) {
+                $cron_model->delCron(array('cron_type' => $data['cron_type'], 'cron_value' => $data['cron_value']));
+            }
+            $cron_model->addCron($data);
+        }
+    }
+
+    /**
+     * 当前选中的栏目
+     */
+    protected function setAdminCurItem($curitem = '') {
+        View::assign('admin_item', $this->getAdminItemList());
+        View::assign('curitem', $curitem);
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        return array();
+    }
+
+    /*
+     * 侧边栏列表
+     */
+
+    function menuList() {
+        return array(
+            'dashboard' => array(
+                'name' => 'dashboard',
+                'text' => lang('ds_dashboard'),
+                'show' => TRUE,
+                'children' => array(
+                    'welcome' => array(
+                        'ico'=>"&#xe70b;",
+                        'text' => lang('ds_welcome'),
+                        'args' => 'welcome,Dashboard,dashboard',
+                    ),
+                    /*
+                    'aboutus' => array(
+                        'text' => lang('ds_aboutus'),
+                        'args' => 'aboutus,dashboard,dashboard',
+                    ),
+                     */
+                    'config' => array(
+                        'ico'=>'&#xe6e0;',
+                        'text' => lang('ds_base'),
+                        'args' => 'base,Config,dashboard',
+                    ),
+                    'member' => array(
+                        'ico'=>'&#xe667;',
+                        'text' => lang('ds_member_manage'),
+                        'args' => 'member,Member,dashboard',
+                    ),
+                ),
+            ),
+            'setting' => array(
+                'name' => 'setting',
+                'text' => lang('ds_setting'),
+                'show' => TRUE,
+                'children' => array(
+                    'config' => array(
+                        'ico'=>'&#xe6e0;',
+                        'text' => lang('ds_base'),
+                        'args' => 'base,Config,setting',
+                    ),
+                    'account' => array(
+                        'ico'=>'&#xe678;',
+                        'text' => lang('ds_account'),
+                        'args' => 'qq,Account,setting',
+                    ),
+                    'upload_set' => array(
+                        'ico'=>'&#xe72a;',
+                        'text' => lang('ds_upload_set'),
+                        'args' => 'default_thumb,Upload,setting',
+                    ),
+                    'seo' => array(
+                        'ico'=>'&#xe6e0;',
+                        'text' => lang('ds_seo_set'),
+                        'args' => 'index,Seo,setting',
+                    ),
+                    'message' => array(
+                        'ico'=>'&#xe71b;',
+                        'text' => lang('ds_message'),
+                        'args' => 'email,Message,setting',
+                    ),
+                    'payment' => array(
+                        'ico'=>'&#xe74d;',
+                        'text' => lang('ds_payment'),
+                        'args' => 'index,Payment,setting',
+                    ),
+                    'admin' => array(
+                        'ico'=>'&#xe67b;',
+                        'text' => lang('ds_admin'),
+                        'args' => 'admin,Admin,setting',
+                    ),
+                    'express' => array(
+                        'ico'=>'&#xe69e;',
+                        'text' => lang('ds_express'),
+                        'args' => 'index,Express,setting',
+                    ),
+                    'Region' => array(
+                        'ico'=>'&#xe720;',
+                        'text' => lang('ds_region'),
+                        'args' => 'index,Region,setting',
+                    ),
+                    'db' => array(
+                        'ico'=>'&#xe6f5;',
+                        'text' => lang('ds_db'),
+                        'args' => 'db,Database,setting',
+                    ),
+                    'admin_log' => array(
+                        'ico'=>'&#xe71f;',
+                        'text' => lang('ds_adminlog'),
+                        'args' => 'loglist,Adminlog,setting',
+                    ),
+                ),
+            ),
+            'member' => array(
+                'name' => 'member',
+                'text' => lang('ds_member'),
+                'show' => TRUE,
+                'children' => array(
+                    'member' => array(
+                        'ico'=>'&#xe667;',
+                        'text' => lang('ds_member_manage'),
+                        'args' => 'member,Member,member',
+                    ),
+                    'member_auth' => array(
+                        'ico'=>'&#xe6ea;',
+                        'text' => lang('member_auth'),
+                        'args' => 'index,MemberAuth,member',
+                    ),
+                    'membergrade' => array(
+                        'ico'=>'&#xe6a3;',
+                        'text' => lang('ds_membergrade'),
+                        'args' => 'index,Membergrade,member',
+                    ),
+                    'exppoints' => array(
+                        'ico'=>'&#xe727;',
+                        'text' => lang('ds_exppoints'),
+                        'args' => 'index,Exppoints,member',
+                    ),
+                    'notice' => array(
+                        'ico'=>'&#xe71b;',
+                        'text' => lang('ds_notice'),
+                        'args' => 'index,Notice,member',
+                    ),
+                    'points' => array(
+                        'ico'=>'&#xe6f5;',
+                        'text' => lang('ds_points'),
+                        'args' => 'index,Points,member',
+                    ),
+                    'predeposit' => array(
+                        'ico'=>'&#xe6e2;',
+                        'text' => lang('ds_predeposit'),
+                        'args' => 'pdrecharge_list,Predeposit,member',
+                    ),
+                    'snsmalbum' => array(
+                        'ico'=>'&#xe72a;',
+                        'text' => lang('ds_snsmalbum'),
+                        'args' => 'index,Snsmalbum,member',
+                    ),
+                    'snsmember' => array(
+                        'ico'=>'&#xe73e;',
+                        'text' => lang('ds_snsmember'),
+                        'args' => 'index,Snsmember,member',
+                    ),
+                    'instant_message' => array(
+                        'ico' => '&#xe71f;',
+                        'text' => lang('instant_message'),
+                        'args' => 'index,InstantMessage,member',
+                    ),
+                ),
+            ),
+            'goods' => array(
+                'name' => 'goods',
+                'text' => lang('ds_goods'),
+                'show' => TRUE,
+                'children' => array(
+                    'goodsclass' => array(
+                        'ico'=>'&#xe652;',
+                        'text' => lang('ds_goodsclass'),
+                        'args' => 'goods_class,Goodsclass,goods',
+                    ),
+                    'Brand' => array(
+                        'ico'=>'&#xe6b0;',
+                        'text' => lang('ds_brand_manage'),
+                        'args' => 'index,Brand,goods',
+                    ),
+                    'Goods' => array(
+                        'ico'=>'&#xe732;',
+                        'text' => lang('ds_goods_manage'),
+                        'args' => 'index,Goods,goods',
+                    ),
+                    'Type' => array(
+                        'ico'=>'&#xe728;',
+                        'text' => lang('ds_type'),
+                        'args' => 'index,Type,goods',
+                    ),
+                    'Spec' => array(
+                        'ico'=>'&#xe71d;',
+                        'text' => lang('ds_spec'),
+                        'args' => 'index,Spec,goods',
+                    ),
+                    'album' => array(
+                        'ico'=>'&#xe72a;',
+                        'text' => lang('ds_album'),
+                        'args' => 'index,Goodsalbum,goods',
+                    ),
+                    'video' => array(
+                        'ico'=>'&#xe6fa;',
+                        'text' => lang('ds_video'),
+                        'args' => 'index,Goodsvideo,goods',
+                    ),
+                    'Arrivalnotice' => array(
+                        'ico'=>'&#xe71b;',
+                        'text' => lang('ds_arrivalnotice'),
+                        'args' => 'index,Arrivalnotice,goods',
+                    ),
+                ),
+            ),
+            'store' => array(
+                'name' => 'store',
+                'text' => lang('ds_store'),
+                'show' => TRUE,
+                'children' => array(
+                    'Store' => array(
+                        'ico'=>'&#xe6ec;',
+                        'text' => lang('ds_store_manage'),
+                        'args' => 'store,Store,store',
+                    ),
+                    'Storemoney' => array(
+                        'ico'=>'&#xe6e2;',
+                        'text' => lang('ds_store_money'),
+                        'args' => 'index,Storemoney,store',
+                    ),
+                    'Storedeposit' => array(
+                        'ico'=>'&#xe72b;',
+                        'text' => lang('ds_store_deposit'),
+                        'args' => 'index,Storedeposit,store',
+                    ),
+                    'Storegrade' => array(
+                        'ico'=>'&#xe6a3;',
+                        'text' => lang('ds_storegrade'),
+                        'args' => 'index,Storegrade,store',
+                    ),
+                    'Storeclass' => array(
+                        'ico'=>'&#xe652;',
+                        'text' => lang('ds_storeclass'),
+                        'args' => 'store_class,Storeclass,store',
+                    ),
+//                    'Chain' => array(
+//                        'ico'=>'&#xe69e;',
+//                        'text' => lang('ds_chain'),
+//                        'args' => 'index,Chain,store',
+//                    ),
+                    'Storesnstrace' => array(
+                        'ico'=>'&#xe6ec;',
+                        'text' => lang('ds_storesnstrace'),
+                        'args' => 'index,Storesnstrace,store',
+                    ),
+                    'Storehelp' => array(
+                        'ico'=>'&#xe6b4;',
+                        'text' => lang('ds_Storehelp'),
+                        'args' => 'index,Storehelp,store',
+                    ),
+                    'Storejoin' => array(
+                        'ico'=>'&#xe6ff;',
+                        'text' => lang('ds_storejoin'),
+                        'args' => 'index,Storejoin,store',
+                    ),
+                    'Ownshop' => array(
+                        'ico'=>'&#xe6ec;',
+                        'text' => lang('ds_ownshop'),
+                        'args' => 'index,Ownshop,store',
+                    ),
+                ),
+            ),
+            'trade' => array(
+                'name' => 'trade',
+                'text' => lang('ds_trade'),
+                'show' => TRUE,
+                'children' => array(
+                    'order' => array(
+                        'ico'=>'&#xe69c;',
+                        'text' => lang('ds_order'),
+                        'args' => 'index,Order,trade',
+                    ),
+                    'vrorder' => array(
+                        'ico'=>'&#xe71f;',
+                        'text' => lang('ds_vrorder'),
+                        'args' => 'index,Vrorder,trade',
+                    ),
+                    'refund' => array(
+                        'ico'=>'&#xe6f3;',
+                        'text' => lang('ds_refund'),
+                        'args' => 'refund_manage,Refund,trade',
+                    ),
+                    'return' => array(
+                        'ico'=>'&#xe6f3;',
+                        'text' => lang('ds_return'),
+                        'args' => 'return_manage,Returnmanage,trade',
+                    ),
+                    'vrrefund' => array(
+                        'ico'=>'&#xe6f3;',
+                        'text' => lang('ds_vrrefund'),
+                        'args' => 'refund_manage,Vrrefund,trade',
+                    ),
+                    'Bill' => array(
+                        'ico'=>'&#xe69c;',
+                        'text' => lang('ds_bill_manage'),
+                        'args' => 'show_statis,Bill,trade',
+                    ),
+                    'consulting' => array(
+                        'ico'=>'&#xe71c;',
+                        'text' => lang('ds_consulting'),
+                        'args' => 'Consulting,Consulting,trade',
+                    ),
+                    'inform' => array(
+                        'ico'=>'&#xe70c;',
+                        'text' => lang('ds_inform'),
+                        'args' => 'inform_list,Inform,trade',
+                    ),
+                    'evaluate' => array(
+                        'ico'=>'&#xe6f2;',
+                        'text' => lang('ds_evaluate'),
+                        'args' => 'evalgoods_list,Evaluate,trade',
+                    ),
+                    'complain' => array(
+                        'ico'=>'&#xe676;',
+                        'text' => lang('ds_complain'),
+                        'args' => 'complain_new_list,Complain,trade',
+                    ),
+                ),
+            ),
+            'website' => array(
+                'name' => 'website',
+                'text' => lang('ds_website'),
+                'show' => TRUE,
+                'children' => array(
+                    'Articleclass' => array(
+                        'ico'=>'&#xe652;',
+                        'text' => lang('ds_articleclass'),
+                        'args' => 'index,Articleclass,website',
+                    ),
+                    'Article' => array(
+                        'ico'=>'&#xe71d;',
+                        'text' => lang('ds_article'),
+                        'args' => 'index,Article,website',
+                    ),
+                    'Document' => array(
+                        'ico'=>'&#xe74f;',
+                        'text' => lang('ds_document'),
+                        'args' => 'index,Document,website',
+                    ),
+                    'Navigation' => array(
+                        'ico'=>'&#xe67d;',
+                        'text' => lang('ds_navigation'),
+                        'args' => 'index,Navigation,website',
+                    ),
+                    'Adv' => array(
+                        'ico'=>'&#xe707;',
+                        'text' => lang('ds_adv'),
+                        'args' => 'ap_manage,Adv,website',
+                    ),
+                    'EditablePagePc' => array(
+                        'ico'=>'&#xe60c;',
+                        'text' => lang('editable_page_pc'),
+                        'args' => 'page_list,EditablePage,website',
+                    ),
+                    'EditablePageH5' => array(
+                        'ico'=>'&#xe601;',
+                        'text' => lang('editable_page_h5'),
+                        'args' => 'h5_page_list,EditablePage,website',
+                    ),
+                    'Link' => array(
+                        'ico'=>'&#xe67d;',
+                        'text' => lang('ds_friendlink'),
+                        'args' => 'index,Link,website',
+                    ),
+                    'Mallconsult' => array(
+                        'ico'=>'&#xe750;',
+                        'text' => lang('ds_mall_consult'),
+                        'args' => 'index,Mallconsult,website',
+                    ),
+                    'Feedback' => array(
+                        'ico'=>'&#xe672;',
+                        'text' => lang('ds_feedback'),
+                        'args' => 'flist,Feedback,website',
+                    ),
+                ),
+            ),
+            'operation' => array(
+                'name' => 'operation',
+                'text' => lang('ds_operation'),
+                'show' => TRUE,
+                'children' => array(
+                    'Operation' => array(
+                        'ico'=>'&#xe734;',
+                        'text' => lang('ds_operation_set'),
+                        'args' => 'index,Operation,operation',
+                    ),
+                    
+                ),
+            ),
+            'stat' => array(
+                'name' => 'stat',
+                'text' => lang('ds_stat'),
+                'show' => TRUE,
+                'children' => array(
+                    'stat_general' => array(
+                        'ico'=>'&#xe734;',
+                        'text' => lang('ds_statgeneral'),
+                        'args' => 'general,Statgeneral,stat',
+                    ),
+                    'stat_industry' => array(
+                         'ico'=>'&#xe745;',
+                        'text' => lang('ds_statindustry'),
+                        'args' => 'scale,Statindustry,stat',
+                    ),
+                    'stat_member' => array(
+                        'ico'=>'&#xe73f;',
+                        'text' => lang('ds_statmember'),
+                        'args' => 'newmember,Statmember,stat',
+                    ),
+                    'stat_store' => array(
+                        'ico'=>'&#xe6ec;',
+                        'text' => lang('ds_statstore'),
+                        'args' => 'newstore,Statstore,stat',
+                    ),
+                    'stat_trade' => array(
+                         'ico'=>'&#xe745;',
+                        'text' => lang('ds_stattrade'),
+                        'args' => 'income,Stattrade,stat',
+                    ),
+                    'stat_goods' => array(
+                        'ico'=>'&#xe732;',
+                        'text' => lang('ds_statgoods'),
+                        'args' => 'pricerange,Statgoods,stat',
+                    ),
+                    'stat_marketing' => array(
+                         'ico'=>'&#xe745;',
+                        'text' => lang('ds_statmarketing'),
+                        'args' => 'promotion,Statmarketing,stat',
+                    ),
+                    'stat_stataftersale' => array(
+                         'ico'=>'&#xe745;',
+                        'text' => lang('ds_stataftersale'),
+                        'args' => 'refund,Stataftersale,stat',
+                    ),
+                ),
+            ),
+            'mobile' => array(
+                'name' => 'mobile',
+                'text' => lang('mobile'),
+                'show' => TRUE,
+                'children' => array(
+                    'app_appadv' => array(
+                        'text' => lang('appadv'),
+                        'args' => 'index,Appadv,mobile',
+                    ),
+                ),
+            ),
+            'wechat' => array(
+                'name' => 'wechat',
+                'text' => lang('wechat'),
+                'show' => TRUE,
+                'children' => array(
+                    'wechat_setting' => array(
+                        'ico'=>'&#xe6e0;',
+                        'text' => lang('wechat_setting'),
+                        'args' => 'setting,Wechat,wechat',
+                    ),
+                    'wechat_material' => array(
+                        'ico'=>'&#xe679;',
+                        'text' => lang('wechat_material'),
+                        'args' => 'material,Wechat,wechat',
+                    ),
+                    'wechat_menu' => array(
+                        'ico'=>'&#xe679;',
+                        'text' => lang('wechat_menu'),
+                        'args' => 'menu,Wechat,wechat',
+                    ),
+                    'wechat_keywords' => array(
+                        'ico'=>'&#xe672;',
+                        'text' => lang('wechat_keywords'),
+                        'args' => 'k_text,Wechat,wechat',
+                    ),
+                    'wechat_member' => array(
+                        'ico'=>'&#xe729;',
+                        'text' => lang('wechat_member'),
+                        'args' => 'member,Wechat,wechat',
+                    ),
+                    'wechat_push' => array(
+                        'ico'=>'&#xe71b;',
+                        'text' => lang('wechat_push'),
+                        'args' => 'SendList,Wechat,wechat',
+                    ),
+                ),
+            ),
+            'flea' => array(
+                'name' => 'flea',
+                'text' => lang('flea'),
+                'show' => FALSE,
+                'children' => array(
+                    'flea_mes' => array(
+                        'text' => lang('flea_mes'),
+                        'args' => 'flea,Flea,flea',
+                    ),
+                    'flea_index' => array(
+                        'ico'=>'&#xe6e0;',
+                        'text' => lang('flea_seo'),
+                        'args' => 'index,Fleaseo,flea',
+                    ),
+                     'flea_class' => array(
+                         'ico'=>'&#xe652;',
+                         'text' => lang('flea_class'),
+                         'args' => 'flea_class,Fleaclass,flea',
+                     ),
+                    'flea_class_index' => array(
+                        'ico'=>'&#xe652;',
+                        'text' => lang('flea_class_index'),
+                        'args' => 'flea_class_index,Fleaclassindex,flea',
+                    ),
+                    'flea_region' => array(
+                        'ico'=>'&#xe720;',
+                        'text' => lang('flea_region'),
+                        'args' => 'flea_region,Flearegion,flea',
+                    ),
+                    'flea_adv_manage' => array(
+                        'ico'=>'&#xe72a;',
+                        'text' => lang('flea_adv_manage'),
+                        'args' => 'adv_manage,Fleaseo,flea',
+                    ),
+                ),
+            ),
+            'live' => array(
+                'name' => 'live',
+                'text' => lang('ds_live'),
+                'show' => TRUE,
+                'children' => array(
+                    'live_setting' => array(
+                        'ico' => '&#xe71f;',
+                        'text' => lang('live_setting'),
+                        'args' => 'index,LiveSetting,live',
+                    ),
+                    'live_apply' => array(
+                        'ico' => '&#xe71f;',
+                        'text' => lang('live_apply'),
+                        'args' => 'index,LiveApply,live',
+                    ),
+                    
+                    'live_goods' => array(
+                        'ico' => '&#xe71f;',
+                        'text' => lang('live_goods'),
+                        'args' => 'index,LiveGoods,live',
+                    ),
+                ),
+            ),
+        );
+    }
+
+    /*
+     * 权限选择列表
+     */
+
+    function limitList() {
+        $_limit = array(
+            array('name' => lang('ds_setting'), 'child' => array(
+                    array('name' => lang('ds_base'), 'action' => null, 'controller' => 'Config'),
+                    array('name' => lang('ds_account'), 'action' => null, 'controller' => 'Account'),
+                    array('name' => lang('ds_upload_set'), 'action' => null, 'controller' => 'Upload'),
+                    array('name' => lang('ds_seo_set'), 'action' => null, 'controller' => 'Seo'),
+                    array('name' => lang('ds_payment'), 'action' => null, 'controller' => 'Payment'),
+                    array('name' => lang('ds_message'), 'action' => null, 'controller' => 'Message'),
+                    array('name' => lang('ds_admin'), 'action' => null, 'controller' => 'Admin'),
+                    array('name' => lang('ds_express'), 'action' => null, 'controller' => 'Express'),
+                    array('name' => lang('ds_region'), 'action' => null, 'controller' => 'Region'),
+                    array('name' => lang('ds_db'), 'action' => null, 'controller' => 'Database'),
+                    array('name' => lang('ds_adminlog'), 'action' => null, 'controller' => 'Adminlog'),
+                )),
+            array('name' => lang('ds_goods'), 'child' => array(
+                    array('name' => lang('ds_goods_manage'), 'action' => null, 'controller' => 'Goods'),
+                    array('name' => lang('ds_goodsclass'), 'action' => null, 'controller' => 'Goodsclass'),
+                    array('name' => lang('ds_brand_manage'), 'action' => null, 'controller' => 'Brand'),
+                    array('name' => lang('ds_type'), 'action' => null, 'controller' => 'Type'),
+                    array('name' => lang('ds_spec'), 'action' => null, 'controller' => 'Spec'),
+                    array('name' => lang('ds_album'), 'action' => null, 'controller' => 'Goodsalbum'),
+                    array('name' => lang('ds_video'), 'action' => null, 'controller' => 'Goodsvideo'),
+                    array('name' => lang('ds_arrivalnotice'), 'action' => null, 'controller' => 'Arrivalnotice'),
+                )),
+            array('name' => lang('ds_store'), 'child' => array(
+                    array('name' => lang('ds_store_manage'), 'action' => null, 'controller' => 'Store'),
+                    array('name' => lang('ds_store_money'), 'action' => null, 'controller' => 'Storemoney'),
+                    array('name' => lang('ds_store_deposit'), 'action' => null, 'controller' => 'Storedeposit'),
+                    array('name' => lang('ds_storegrade'), 'action' => null, 'controller' => 'Storegrade'),
+                    array('name' => lang('ds_storeclass'), 'action' => null, 'controller' => 'Storeclass'),
+//                    array('name' => lang('ds_chain'), 'action' => null, 'controller' => 'Chain'),
+                    array('name' => lang('ds_storesnstrace'), 'action' => null, 'controller' => 'Storesnstrace'),
+                    array('name' => lang('ds_Storehelp'), 'action' => null, 'controller' => 'Storehelp'),
+                    array('name' => lang('ds_storejoin'), 'action' => null, 'controller' => 'Storejoin'),
+                    array('name' => lang('ds_ownshop'), 'action' => null, 'controller' => 'Ownshop'),
+                )),
+            array('name' => lang('ds_member'), 'child' => array(
+                    array('name' => lang('ds_member_manage'), 'action' => null, 'controller' => 'Member'),
+                    array('name' => lang('member_auth'), 'action' => null, 'controller' => 'MemberAuth'),
+                    array('name' => lang('ds_membergrade'), 'action' => null, 'controller' => 'Membergrade'),
+                    array('name' => lang('ds_exppoints'), 'action' => null, 'controller' => 'Exppoints'),
+                    array('name' => lang('ds_notice'), 'action' => null, 'controller' => 'Notice'),
+                    array('name' => lang('ds_points'), 'action' => null, 'controller' => 'Points'),
+                    array('name' => lang('ds_snsmalbum'), 'action' => null, 'controller' => 'Snsmalbum'),
+                    array('name' => lang('ds_snsmember'), 'action' => null, 'controller' => 'Snsmember'),
+                    array('name' => lang('ds_predeposit'), 'action' => null, 'controller' => 'Predeposit'),
+                    array('name' => lang('instant_message'), 'action' => null, 'controller' => 'InstantMessage'),
+                )),
+            array('name' => lang('ds_trade'), 'child' => array(
+                    array('name' => lang('ds_order'), 'action' => null, 'controller' => 'Order'),
+                    array('name' => lang('ds_vrorder'), 'action' => null, 'controller' => 'Vrorder'),
+                    array('name' => lang('ds_refund'), 'action' => null, 'controller' => 'Refund'),
+                    array('name' => lang('ds_return'), 'action' => null, 'controller' => 'Returnmanage'),
+                    array('name' => lang('ds_vrrefund'), 'action' => null, 'controller' => 'Vrrefund'),
+                    array('name' => lang('ds_bill_manage'), 'action' => null, 'controller' => 'Bill'),
+                    array('name' => lang('ds_consulting'), 'action' => null, 'controller' => 'Consulting'),
+                    array('name' => lang('ds_inform'), 'action' => null, 'controller' => 'Inform'),
+                    array('name' => lang('ds_evaluate'), 'action' => null, 'controller' => 'Evaluate'),
+                    array('name' => lang('ds_complain'), 'action' => null, 'controller' => 'Complain'),
+                )),
+            array('name' => lang('ds_website'), 'child' => array(
+                    array('name' => lang('ds_articleclass'), 'action' => null, 'controller' => 'Articleclass'),
+                    array('name' => lang('ds_article'), 'action' => null, 'controller' => 'Article'),
+                    array('name' => lang('ds_document'), 'action' => null, 'controller' => 'Document'),
+                    array('name' => lang('ds_navigation'), 'action' => null, 'controller' => 'Navigation'),
+                    array('name' => lang('ds_adv'), 'action' => null, 'controller' => 'Adv'),
+                    array('name' => lang('editable_page_pc'), 'action' => 'page_list', 'controller' => 'EditablePage'),
+                    array('name' => lang('editable_page_h5'), 'action' => 'h5_page_list', 'controller' => 'EditablePage'),
+                    array('name' => lang('ds_friendlink'), 'action' => null, 'controller' => 'Link'),
+                    array('name' => lang('ds_mall_consult'), 'action' => null, 'controller' => 'Mallconsult'),
+                    array('name' => lang('ds_feedback'), 'action' => null, 'controller' => 'Feedback'),
+            )),
+            array('name' => lang('ds_operation'), 'child' => array(
+                    array('name' => lang('ds_operation_set'), 'action' => null, 'controller' => 'Operation|Promotionwholesale|Promotionxianshi|Promotionmansong|Promotionbundling|Promotionbooth|Groupbuy|Vrgroupbuy|Voucher|Promotionmgdiscount|Promotionpintuan|Promotionbargain|Activity|EditablePage|Inviter|Bonus|Marketmanage|Pointprod|Pointorder|Rechargecard|Flea|Fleaseo|Fleaclass|Fleaclassindex|Flearegion|Fleaseo|Promotionpresell'),
+                )),
+            array('name' => lang('ds_stat'), 'child' => array(
+                    array('name' => lang('ds_statgeneral'), 'action' => null, 'controller' => 'Statgeneral'),
+                    array('name' => lang('ds_statindustry'), 'action' => null, 'controller' => 'Statindustry'),
+                    array('name' => lang('ds_statmember'), 'action' => null, 'controller' => 'Statmember'),
+                    array('name' => lang('ds_statstore'), 'action' => null, 'controller' => 'Statstore'),
+                    array('name' => lang('ds_stattrade'), 'action' => null, 'controller' => 'Stattrade'),
+                    array('name' => lang('ds_statgoods'), 'action' => null, 'controller' => 'Statgoods'),
+                    array('name' => lang('ds_statmarketing'), 'action' => null, 'controller' => 'Statmarketing'),
+                    array('name' => lang('ds_stataftersale'), 'action' => null, 'controller' => 'Stataftersale'),
+                )),
+            array('name' => lang('mobile'), 'child' => array(
+                    array('name' => lang('appadv'), 'action' => null, 'controller' => 'Appadv'),
+                )),
+            array('name' => lang('wechat'), 'child' => array(
+                    array('name' => lang('wechat_setting'), 'action' => 'setting', 'controller' => 'Wechat'),
+                    array('name' => lang('wechat_template_message'), 'action' => 'template_message', 'controller' => 'Wechat'),
+                    array('name' => lang('wechat_menu'), 'action' => 'menu', 'controller' => 'Wechat'),
+                    array('name' => lang('wechat_keywords'), 'action' => 'k_text', 'controller' => 'Wechat'),
+                    array('name' => lang('wechat_member'), 'action' => 'member', 'controller' => 'Wechat'),
+                    array('name' => lang('wechat_push'), 'action' => 'SendList', 'controller' => 'Wechat'),
+                )),
+            array('name' => lang('ds_live'), 'child' => array(
+                    array('name' => lang('live_setting'), 'action' => null, 'controller' => 'LiveSetting'),
+                    array('name' => lang('live_apply'), 'action' => null, 'controller' => 'LiveApply'),
+                    array('name' => lang('live_goods'), 'action' => null, 'controller' => 'LiveGoods'),
+                )),
+        );
+
+        return $_limit;
+    }
+
+}
+
+?>

+ 194 - 0
app/admin/controller/Adminlog.php

@@ -0,0 +1,194 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Adminlog extends AdminControl
+{
+    const EXPORT_SIZE = 5000;
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/adminlog.lang.php');
+    }
+
+    /**
+     * 日志列表
+     *
+     */
+    public function loglist()
+    {
+        $condition = array();
+        $time1='';
+        $time2='';
+        if (!empty(input('param.admin_name'))) {
+            $condition[]=array('admin_name','=',input('param.admin_name'));
+        }
+        if (!empty(input('param.time_from'))) {
+            $time1 = strtotime(input('param.time_from'));
+        }
+        if (!empty(input('param.time_to'))) {
+            $time2 = strtotime(input('param.time_to'));
+            if ($time2 !== false)
+                $time2 = $time2 + 86400;
+        }
+        if ($time1 && $time2) {
+            $condition[] = array('adminlog_time','between', array($time1, $time2));
+        }
+        elseif ($time1) {
+            $condition[]=array('adminlog_time','>=', $time1);
+        }
+        elseif ($time2) {
+            $condition[]=array('adminlog_time','<=', $time2);
+        }
+        $adminlog_model= model('adminlog');
+        $order='adminlog_id desc';
+        $adminlog_list = $adminlog_model->getAdminlogList($condition,10,$order);
+        View::assign('adminlog_list', $adminlog_list);
+        View::assign('show_page', $adminlog_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('loglist');
+        return View::fetch();
+    }
+
+    /**
+     * 删除日志
+     *
+     */
+    public function list_del()
+    {
+        $adminlog_id = input('param.adminlog_id');
+        $adminlog_id_array = ds_delete_param($adminlog_id);
+        if ($adminlog_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('adminlog_id','in',$adminlog_id_array);
+        $adminlog_model=model('adminlog');
+        if (!$adminlog_model->delAdminlog($condition)) {
+            $this->log(lang('ds_del').lang('admin_log'), 0);
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+        else {
+            $this->log(lang('ds_del').lang('admin_log'), 1);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        }
+    }
+
+    /**
+     * 导出第一步
+     */
+    public function export_step1()
+    {
+        $time1='';
+        $time2='';
+        $condition = array();
+        if (!empty(input('param.admin_name'))) {
+            $condition[]=array('admin_name','=',input('param.admin_name'));
+        }
+        if (!empty(input('param.time_from'))) {
+            $time1 = strtotime(input('param.time_from'));
+        }
+        if (!empty(input('param.time_to'))) {
+            $time2 = strtotime(input('param.time_to'));
+            if ($time2 !== false)
+                $time2 = $time2 + 86400;
+        }
+        if ($time1 && $time2) {
+            $condition[] = array('createtime','between', array($time1, $time2));
+        }
+        elseif ($time1) {
+            $condition[]=array('createtime','>=', $time1);
+        }
+        elseif ($time2) {
+            $condition[]=array('createtime','<=', $time2);
+        }
+        if (!is_numeric(input('param.page'))) {
+            $adminlog_model=model('adminlog');
+            $count = $adminlog_model->getAdminlogCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) {    //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            }
+            else {    //如果数量小,直接下载
+                $data = Db::name('adminlog')->where($condition)->order('adminlog_id desc')->limit(self::EXPORT_SIZE)->select()->toArray();
+                $this->createExcel($data);
+            }
+        }
+        else {    //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = Db::name('adminlog')->where($condition)->order('adminlog_id desc')->limit($limit1,$limit2)->select()->toArray();
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array())
+    {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array(
+                                 'id' => 's_title', 'Font' => array('FontName' => lang('ds_song_typeface'), 'Size' => '12', 'Bold' => '1')
+                             ));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('admin_log_man'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('admin_log_do'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('admin_log_dotime'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => 'IP');
+        foreach ((array)$data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['admin_name']);
+            $tmp[] = array('data' => $v['adminlog_content']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['adminlog_time']));
+            $tmp[] = array('data' => $v['adminlog_ip']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('admin_log'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('admin_log'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'loglist',
+                'text' => lang('admin_log'),
+                'url' => (string)url('Adminlog/loglist')
+            )
+            );
+        return $menu_array;
+
+    }
+}

+ 407 - 0
app/admin/controller/Adv.php

@@ -0,0 +1,407 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Adv extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/adv.lang.php');
+    }
+
+    /**
+     *
+     * 管理广告位
+     */
+    public function ap_manage() {
+        $adv_model = model('adv');
+        /**
+         * 多选删除广告位
+         */
+        if (!request()->isPost()) {
+            /**
+             * 显示广告位管理界面
+             */
+            $condition = array();
+            $orderby = '';
+            $search_name = trim(input('get.search_name'));
+            if ($search_name != '') {
+                $condition[]=array('ap_name','like', "%" . $search_name . "%");
+            }
+            $ap_list = $adv_model->getAdvpositionList($condition, '10', $orderby);
+            $adv_list = $adv_model->getAdvList();
+            View::assign('ap_list', $ap_list);
+            View::assign('adv_list', $adv_list);
+            View::assign('showpage', $adv_model->page_info->render());
+            
+            View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+            
+            $this->setAdminCurItem('ap_manage');
+            return View::fetch('ap_manage');
+        }
+    }
+
+    /**
+     *
+     * 修改广告位
+     */
+    public function ap_edit() {
+        $ap_id = intval(input('param.ap_id'));
+        $adv_model = model('adv');
+        if (!request()->isPost()) {
+            $condition = array();
+            $condition[] = array('ap_id','=',$ap_id);
+            $ap = $adv_model->getOneAdvposition($condition);
+            View::assign('ref_url', get_referer());
+            View::assign('ap', $ap);
+            return View::fetch('ap_form');
+        } else {
+            $param['ap_name'] = trim(input('post.ap_name'));
+            $param['ap_intro'] = trim(input('post.ap_intro'));
+            $param['ap_width'] = intval(trim(input('post.ap_width')));
+            $param['ap_height'] = intval(trim(input('post.ap_height')));
+            if (input('post.ap_isuse') != '') {
+                $param['ap_isuse'] = intval(input('post.ap_isuse'));
+            }
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('ap_edit')->check($param)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $adv_model->editAdvposition($ap_id,$param);
+
+            if ($result>=0) {
+                $this->log(lang('ap_change_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('ap_change_succ'));
+            } else {
+                $this->error(lang('ap_change_fail'));
+            }
+        }
+    }
+
+    /**
+     *
+     * 新增广告位
+     */
+    public function ap_add() {
+        if (!request()->isPost()) {
+            $ap['ap_isuse'] = 1;
+            View::assign('ap', $ap);
+            return View::fetch('ap_form');
+        } else {
+            $adv_model = model('adv');
+
+            $insert_array['ap_name'] = trim(input('post.ap_name'));
+            $insert_array['ap_intro'] = trim(input('post.ap_intro'));
+            $insert_array['ap_isuse'] = intval(input('post.ap_isuse'));
+            $insert_array['ap_width'] = intval(input('post.ap_width'));
+            $insert_array['ap_height'] = intval(input('post.ap_height'));
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('ap_add')->check($insert_array)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $adv_model->addAdvposition($insert_array);
+
+            if ($result) {
+                $this->log(lang('ap_add_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('ap_add_succ'));
+           } else {
+                $this->error(lang('ap_add_fail'));
+            }
+        }
+    }
+
+    /**
+     *
+     * 删除广告位
+     */
+    public function ap_del() {
+        $adv_model = model('adv');
+        /**
+         * 删除一个广告
+         */
+        $ap_id = intval(input('param.ap_id'));
+        $result = $adv_model->delAdvposition($ap_id);
+
+        if (!$result) {
+            ds_json_encode('10001', lang('ap_del_fail'));
+        } else {
+            $this->log(lang('ap_del_succ') . '[' . $ap_id . ']', null);
+            ds_json_encode('10000', lang('ap_del_succ'));
+        }
+    }
+
+    /**
+     *
+     * 广告管理
+     */
+    public function adv() {
+        $adv_model = model('adv');
+
+        $ap_id = intval(input('param.ap_id'));
+        if (!request()->isPost()) {
+            $condition = array();
+            if ($ap_id) {
+                 $condition[] = array('ap_id','=',$ap_id);
+            }
+            $adv_info = $adv_model->getAdvList($condition, 20, '', '');
+            View::assign('adv_info', $adv_info);
+            $ap_list = $adv_model->getAdvpositionList();
+            View::assign('ap_list', $ap_list);
+            if ($ap_id) {
+                $ap_condition=array();
+                $ap_condition['ap_id'] = $ap_id;
+                $ap = $adv_model->getOneAdvposition($ap_condition);
+                View::assign('ap_name', $ap['ap_name']);
+            } else {
+                View::assign('ap_name', '');
+            }
+
+            View::assign('show_page', $adv_model->page_info->render());
+            
+            View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+            $this->setAdminCurItem('adv');
+            return View::fetch('adv_index');
+        }
+    }
+
+    /**
+     * 管理员添加广告
+     */
+    public function adv_add() {
+        $adv_model = model('adv');
+        if (!request()->isPost()) {
+
+            $ap_list = $adv_model->getAdvpositionList();
+            View::assign('ap_list', $ap_list);
+            $adv = array(
+                'ap_id' => 0,
+                'adv_enabled' => '1',
+                'adv_startdate' => TIMESTAMP,
+                'adv_enddate' => TIMESTAMP + 24 * 3600 * 365,
+            );
+            View::assign('adv', $adv);
+            return View::fetch('adv_form');
+        } else {
+            $insert_array['ap_id'] = intval(input('post.ap_id'));
+            $insert_array['adv_title'] = trim(input('post.adv_name'));
+            $insert_array['adv_link'] = input('post.adv_link');
+            $insert_array['adv_bgcolor'] = input('post.adv_bgcolor');
+            $insert_array['adv_sort'] = input('post.adv_sort');
+            $insert_array['adv_enabled'] = input('post.adv_enabled');
+            $insert_array['adv_startdate'] = $this->getunixtime(input('post.adv_startdate'));
+            $insert_array['adv_enddate'] = $this->getunixtime(input('post.adv_enddate'));
+
+            //上传文件保存路径
+            if (!empty($_FILES['adv_code']['name'])) {
+                $res=ds_upload_pic(ATTACH_ADV,'adv_code');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $insert_array['adv_code'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+
+            }
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('adv_add')->check($insert_array)) {
+                $this->error($adv_validate->getError());
+            }
+
+            //广告信息入库
+            $result = $adv_model->addAdv($insert_array);
+
+            if ($result) {
+                $this->log(lang('adv_add_succ') . '[' . input('post.adv_name') . ']', null);
+                dsLayerOpenSuccess(lang('adv_add_succ'));
+//                $this->success(lang('adv_add_succ'), (string)url('Adv/adv', ['ap_id' => input('post.ap_id')]));
+            } else {
+                $this->error(lang('adv_add_fail'));
+            }
+        }
+    }
+
+    /**
+     *
+     * 修改广告
+     */
+    public function adv_edit() {
+        $adv_id = intval(input('param.adv_id'));
+        $adv_model = model('adv');
+        //获取指定广告
+        $condition = array();
+        $condition[] = array('adv_id','=',$adv_id);
+        $adv = $adv_model->getOneAdv($condition);
+        if (!request()->isPost()) {
+            //获取广告列表
+            $ap_list = $adv_model->getAdvpositionList();
+            View::assign('ap_list', $ap_list);
+            View::assign('adv', $adv);
+            View::assign('ref_url', get_referer());
+            return View::fetch('adv_form');
+        } else {
+            $param['ap_id'] = intval(input('post.ap_id'));
+            $param['adv_title'] = trim(input('post.adv_name'));
+            $param['adv_link'] = input('post.adv_link');
+            $param['adv_bgcolor'] = input('post.adv_bgcolor');
+            $param['adv_sort'] = input('post.adv_sort');
+            $param['adv_enabled'] = input('post.adv_enabled');
+            $param['adv_startdate'] = $this->getunixtime(trim(input('post.adv_startdate')));
+            $param['adv_enddate'] = $this->getunixtime(trim(input('post.adv_enddate')));
+
+
+            if (!empty($_FILES['adv_code']['name'])) {
+		//上传文件保存路径
+                $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ADV;
+                $res=ds_upload_pic(ATTACH_ADV,'adv_code');
+                if($res['code']){
+					//还需删除原来图片
+                    if (!empty($adv['adv_code'])) {
+                        @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
+                    }
+                    $file_name=$res['data']['file_name'];
+                    $param['adv_code'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+                
+
+            }
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('adv_edit')->check($param)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $adv_model->editAdv($adv_id,$param);
+
+            if ($result>=0) {
+                $this->log(lang('adv_change_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('adv_change_succ'));
+//               $this->success(lang('adv_change_succ'), input('post.ref_url'));
+            } else {
+                $this->error(lang('adv_change_fail'));
+            }
+        }
+    }
+
+    /**
+     *
+     * 删除广告
+     */
+    public function adv_del() {
+        $adv_model = model('adv');
+        /**
+         * 删除一个广告
+         */
+        $adv_id = intval(input('param.adv_id'));
+        $result = $adv_model->delAdv($adv_id);
+
+        if (!$result) {
+            ds_json_encode('10001', lang('adv_del_fail'));
+        } else {
+            $this->log(lang('adv_del_succ') . '[' . $adv_id . ']', null);
+            ds_json_encode('10000', lang('adv_del_succ'));
+        }
+    }
+
+    /**
+     *
+     * 获取UNIX时间戳
+     */
+    public function getunixtime($time) {
+        $array = explode("-", $time);
+        $unix_time = mktime(0, 0, 0, $array[1], $array[2], $array[0]);
+        return $unix_time;
+    }
+
+    public function ajax() {
+        $adv_model = model('adv');
+        switch (input('get.branch')) {
+            case 'ap_branch':
+                $column = trim(input('param.column'));
+                $value = trim(input('param.value'));
+                $ap_id = intval(input('param.id'));
+                $param[$column] = trim($value);
+                $result = $adv_model->editAdvposition($ap_id,$param);
+                break;
+            //ADV数据表更新
+            case 'adv_branch':
+                $column = trim(input('param.column'));
+                $value = trim(input('param.value'));
+                $adv_id = intval(input('param.id'));
+                $param[$column] = trim($value);
+                $result = $adv_model->editAdv($adv_id,$param);
+                break;
+        }
+        if($result>=0){
+            echo 'true';
+        }else{
+            echo false;
+        }
+    }
+
+    function adv_template() {
+        $pages = $this->_get_editable_pages();
+        View::assign('pages', $pages);
+        $this->setAdminCurItem('adv_template');
+        return View::fetch();
+    }
+
+    /**
+     *    获取可以编辑的页面列表
+     */
+    function _get_editable_pages() {
+        return array(
+            lang('homepage') => (string)url('home/Index/index',['edit_ad'=>1]),
+            lang('flea') => (string)url('home/Flea/index',['edit_ad'=>1]),
+        );
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'ap_manage',
+                'text' => lang('ap_manage'),
+                'url' => (string)url('Adv/ap_manage')
+            ),
+        );
+        $menu_array[] = array(
+            'name' => 'adv',
+            'text' => lang('adv_manage'),
+            'url' => (string)url('Adv/adv')
+        );
+        $menu_array[] = array(
+            'name' => 'adv_add',
+            'text' => lang('adv_add'),
+            'url' => "javascript:dsLayerOpen('".(string)url('Adv/adv_add', ['ap_id' => input('param.ap_id')])."','".lang('adv_add')."')"
+        );
+
+
+        return $menu_array;
+    }
+
+}
+
+?>

+ 380 - 0
app/admin/controller/Appadv.php

@@ -0,0 +1,380 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Appadv extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/adv.lang.php');
+    }
+    
+    function index()
+    {
+        /**
+         * 显示广告位管理界面
+         */
+        $condition = array();
+        $search_name = trim(input('get.search_name'));
+        if ($search_name != '') {
+            $condition[] = array('ap_name','=',$search_name);
+        }
+        $appadv_model = model('appadv');
+        $ap_list= $appadv_model->getAppadvpositionList($condition,'10');
+        $adv_list = $appadv_model->getAppadvList();
+        
+        View::assign('ap_list',$ap_list);
+        View::assign('adv_list',$adv_list);
+        View::assign('showpage', $appadv_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     *
+     * 新增广告位
+     */
+    public function ap_add() {
+        if (!request()->isPost()) {
+            $ap['ap_isuse']=1;
+            View::assign('ap',$ap);
+            return View::fetch('ap_form');
+        } else {
+            $appadv_model = model('appadv');
+            $insert_array['ap_name'] = trim(input('post.ap_name'));
+            $insert_array['ap_intro'] = trim(input('post.ap_intro'));
+            $insert_array['ap_isuse'] = intval(input('post.ap_isuse'));
+            $insert_array['ap_width'] = intval(input('post.ap_width'));
+            $insert_array['ap_height'] = intval(input('post.ap_height'));
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('app_ap_add')->check($insert_array)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $appadv_model->addAppadvposition($insert_array);
+
+            if ($result) {
+                $this->log(lang('ap_add_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('ap_add_succ'),(string)url('Appadv/index'));
+            } else {
+                $this->error(lang('ap_add_fail'));
+            }
+        }
+    }
+
+
+    /**
+     *
+     * 删除广告位
+     */
+    public function ap_del() {
+        $appadv_model = model('appadv');
+        /**
+         * 删除一个广告位
+         */
+        $ap_id = intval(input('param.ap_id'));
+        $result = $appadv_model->delAppadvposition($ap_id);
+        if (!$result) {
+            ds_json_encode(10001, lang('ap_del_fail'));
+        } else {
+            $this->log(lang('ap_del_succ') . '[' . $ap_id . ']', null);
+            ds_json_encode(10000, lang('ap_del_succ'));
+        }
+    }
+
+    /**
+     *
+     * 删除广告
+     */
+    public function adv_del() {
+        $appadv_model = model('appadv');
+        /**
+         * 删除一个广告
+         */
+        $adv_id = intval(input('param.adv_id'));
+        $result = $appadv_model->delAppadv($adv_id);
+
+        if (!$result) {
+            ds_json_encode(10001, lang('adv_del_fail'));
+        } else {
+            $this->log(lang('adv_del_succ') . '[' . $adv_id . ']', null);
+            ds_json_encode(10000, lang('adv_del_succ'));
+        }
+    }
+
+    /**
+     *
+     * 修改广告
+     */
+    public function adv_edit() {
+        $adv_id = intval(input('param.adv_id'));
+        $appadv_model = model('appadv');
+        //获取指定广告
+        $condition = array();
+        $condition[] = array('adv_id','=',$adv_id);
+        $adv = $appadv_model->getOneAppadv($condition);
+        if (!request()->isPost()) {
+            //获取广告列表
+            $ap_list = $appadv_model->getAppadvpositionList();
+            View::assign('ap_list', $ap_list);
+            View::assign('adv', $adv);
+            View::assign('ref_url', get_referer());
+            return View::fetch('adv_form');
+        } else {
+            $param['ap_id'] = intval(input('post.ap_id'));
+            $param['adv_title'] = trim(input('post.adv_name'));
+            $param['adv_type'] = input('post.adv_type');
+            $param['adv_typedate'] = input('post.adv_typedate');
+            $param['adv_sort'] = input('post.adv_sort');
+            $param['adv_enabled'] = input('post.adv_enabled');
+            $param['adv_startdate'] = $this->getunixtime(trim(input('post.adv_startdate')));
+            $param['adv_enddate'] = $this->getunixtime(trim(input('post.adv_enddate')));
+
+
+            if (!empty($_FILES['adv_code']['name'])) {
+                //上传文件保存路径
+                $upload_file = BASE_UPLOAD_PATH . '/' . ATTACH_APPADV;
+                $res=ds_upload_pic(ATTACH_APPADV,'adv_code');
+                if($res['code']){
+                    //还需删除原来图片
+                    if (!empty($adv['adv_code'])) {
+                        @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
+                    }
+                    $file_name=$res['data']['file_name'];
+                    $param['adv_code'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+                
+            }
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('app_adv_edit')->check($param)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $appadv_model->editAppadv($adv_id,$param);
+
+            if ($result>=0) {
+                $this->log(lang('adv_change_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('adv_change_succ'),input('post.ref_url'));
+            } else {
+                $this->error(lang('adv_change_fail'));
+            }
+        }
+    }
+    
+    public function ajax() {
+        $appadv_model = model('appadv');
+        switch (input('get.branch')) {
+            case 'ap_branch':
+                $column = input('param.column');
+                $value = input('param.value');
+                $ap_id = intval(input('param.id'));
+                $param[$column] = trim($value);
+                $result = $appadv_model->editAppadvposition($ap_id,$param);
+                break;
+            //ADV数据表更新
+            case 'adv_branch':
+                $column = input('param.column');
+                $value = input('param.value');
+                $adv_id = intval(input('param.id'));
+                $param[$column] = trim($value);
+                $result = $appadv_model->editAppAdv($adv_id,$param);
+                break;
+        }
+        if($result>=0){
+            echo 'true';
+        }else{
+            echo false;
+        }
+    }
+    
+    
+    /**
+     *
+     * 广告管理
+     */
+    public function adv() {
+        $appadv_model = model('appadv');
+        $ap_id = intval(input('param.ap_id'));
+        if (!request()->isPost()) {
+            $condition = array();
+            if ($ap_id) {
+                $condition[] = array('ap_id','=',$ap_id);
+            }
+            $adv_info = $appadv_model->getAppadvList($condition, 20, '', '');
+            View::assign('adv_info', $adv_info);
+            $ap_list = $appadv_model->getAppadvpositionList();
+            View::assign('ap_list', $ap_list);
+            if ($ap_id) {
+                $ap_condition=array();
+                $ap_condition[] = array('ap_id','=',$ap_id);
+                $ap = $appadv_model->getOneAppadvposition($ap_condition); 
+                View::assign('ap_name', $ap['ap_name']);
+            } else {
+                View::assign('ap_name', '');
+            }
+
+            View::assign('show_page', $appadv_model->page_info->render());
+            
+            View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+            
+            $this->setAdminCurItem('adv');
+            return View::fetch('adv_index');
+        }
+    }
+
+    /**
+     * 管理员添加广告
+     */
+    public function appadv_add() {
+        $appadv_model = model('appadv');
+        if (!request()->isPost()) {
+
+            $ap_list = $appadv_model->getAppadvpositionList();
+            View::assign('ap_list', $ap_list);
+            $adv = array(
+                'ap_id' => 0,
+                'adv_enabled' => '1',
+                'adv_startdate' => TIMESTAMP,
+                'adv_enddate' => TIMESTAMP + 24 * 3600 * 365,
+                'adv_type'=>''
+            );
+            View::assign('adv', $adv);
+            return View::fetch('adv_form');
+        } else {
+            $insert_array['ap_id'] = intval(input('post.ap_id'));
+            $insert_array['adv_title'] = trim(input('post.adv_name'));
+            $insert_array['adv_type'] = input('post.adv_type');
+            $insert_array['adv_typedate'] = input('post.adv_typedate');
+            $insert_array['adv_sort'] = input('post.adv_sort');
+            $insert_array['adv_enabled'] = input('post.adv_enabled');
+            $insert_array['adv_startdate'] = $this->getunixtime(input('post.adv_startdate'));
+            $insert_array['adv_enddate'] = $this->getunixtime(input('post.adv_enddate'));
+
+            //上传文件保存路径
+            $upload_file = BASE_UPLOAD_PATH . '/' . ATTACH_APPADV;
+            if (!empty($_FILES['adv_code']['name'])) {
+                $res=ds_upload_pic(ATTACH_APPADV,'adv_code');
+                if($res['code']){
+                    //还需删除原来图片
+                    if (!empty($adv['adv_code'])) {
+                        @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
+                    }
+                    $file_name=$res['data']['file_name'];
+                    $insert_array['adv_code'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('app_adv_add')->check($insert_array)) {
+                $this->error($adv_validate->getError());
+            }
+
+            //广告信息入库
+            $result = $appadv_model->addAppadv($insert_array);
+            //更新相应广告位所拥有的广告数量
+            $ap_condition=array();
+            $ap_condition['ap_id']=intval(input('post.ap_id'));
+            $appadv_model->getOneAppadvposition($ap_condition);
+            if ($result) {
+                $this->log(lang('adv_add_succ') . '[' . input('post.adv_name') . ']', null);
+                dsLayerOpenSuccess(lang('adv_add_succ'),(string)url('Appadv/adv', ['ap_id' => input('post.ap_id')]));
+            } else {
+                $this->error(lang('adv_add_fail'));
+            }
+        }
+    }
+
+    /**
+     *
+     * 修改广告位
+     */
+    public function ap_edit() {
+        $ap_id = intval(input('param.ap_id'));
+
+        $appadv_model = model('appadv');
+        if (!request()->isPost()) {
+            $condition = array();
+            $condition[] = array('ap_id','=',$ap_id);
+            $ap = $appadv_model->getOneAppadvposition($condition);
+            View::assign('ref_url', get_referer());
+            View::assign('ap', $ap);
+            return View::fetch('ap_form');
+        } else {
+            $param['ap_name'] = trim(input('post.ap_name'));
+            $param['ap_intro'] = trim(input('post.ap_intro'));
+            $param['ap_width'] = intval(trim(input('post.ap_width')));
+            $param['ap_height'] = intval(trim(input('post.ap_height')));
+            if (input('post.ap_isuse') != '') {
+                $param['ap_isuse'] = intval(input('post.ap_isuse'));
+            }
+            $adv_validate = ds_validate('adv');
+            if (!$adv_validate->scene('app_ap_edit')->check($param)) {
+                $this->error($adv_validate->getError());
+            }
+
+            $result = $appadv_model->editAppadvposition($ap_id,$param);
+
+            if ($result>=0) {
+                $this->log(lang('ap_change_succ') . '[' . input('post.ap_name') . ']', null);
+                dsLayerOpenSuccess(lang('ap_change_succ'),input('post.ref_url'));
+            } else {
+                $this->error(lang('ap_change_fail'));
+            }
+        }
+    }
+    /**
+     *
+     * 获取UNIX时间戳
+     */
+    public function getunixtime($time) {
+        $array = explode("-", $time);
+        $unix_time = mktime(0, 0, 0, $array[1], $array[2], $array[0]);
+        return $unix_time;
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ap_manage'),
+                'url' => (string)url('Appadv/index')
+            ),
+        );
+        $menu_array[] = array(
+            'name' => 'adv',
+            'text' => lang('adv_manage'),
+            'url' => (string)url('Appadv/adv')
+        );
+        $menu_array[] = array(
+            'name' => 'adv_add',
+            'text' => lang('adv_add'),
+            'url' => "javascript:dsLayerOpen('".(string)url('Appadv/appadv_add', ['ap_id' => input('param.ap_id')])."','".lang('adv_add')."')"
+        );
+        return $menu_array;
+    }
+    
+}

+ 71 - 0
app/admin/controller/Arrivalnotice.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Arrivalnotice extends AdminControl
+{
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/arrivalnotice.lang.php');
+    }
+
+    /**
+     * 到货通知列表
+     * @return mixed
+     */
+    public function index() {
+        $arrivalnotice_model = model('arrivalnotice');
+        $condition = array();
+        if (!empty(input('param.search_goods'))) {
+            $condition[]=array('goods_name','like', '%' . input('param.search_goods') . '%');
+        }
+        if (!empty(input('param.search_state'))) {
+            $condition[]=array('arrivalnotice_state','=',input('param.search_state'));
+        }
+        $arrivalnotice_list = $arrivalnotice_model->getArrivalNoticeList($condition,'','','',5);
+        foreach ($arrivalnotice_list as $key => $value){
+            $arrivalnotice_list[$key]['member_name'] = model('member')->getMemberInfo(['member_id'=>$value['member_id']],'member_name')['member_name'];
+        }
+
+        View::assign('arrivalnotice_list', $arrivalnotice_list);
+        View::assign('show_page', $arrivalnotice_model->page_info->render());
+        $this->setAdminCurItem('index');
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        return View::fetch();
+    }
+
+    /**
+     * 到货通知删除
+     */
+    public function arrivalnotice_del(){
+        $arrivalnotice_id = input('param.arrivalnotice_id');
+        $arrivalnotice_id_array = ds_delete_param($arrivalnotice_id);
+        if ($arrivalnotice_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('arrivalnotice_id','in',$arrivalnotice_id_array);
+        $arrivalnotice_model = model('arrivalnotice');
+        //批量删除
+        $result = $arrivalnotice_model->delArrivalNotice($condition);
+        if ($result){
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        }else{
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+}

+ 354 - 0
app/admin/controller/Article.php

@@ -0,0 +1,354 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Article extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/article.lang.php');
+    }
+
+    public function index() {
+
+        /**
+         * 检索条件
+         */
+        $condition = array();
+        $search_ac_id = intval(input('param.search_ac_id'));
+        if ($search_ac_id) {
+            $condition[]=array('ac_id','=',$search_ac_id);
+        }
+        $search_title = trim(input('param.search_title'));
+        if ($search_title) {
+            $condition[]=array('article_title','like', "%" . $search_title . "%");
+        }
+        $article_model = model('article');
+        $article_list = $article_model->getArticleList($condition, 10);
+
+        $articleclass_model = model('articleclass');
+        /**
+         * 整理列表内容
+         */
+        if (is_array($article_list)) {
+            /**
+             * 取文章分类
+             */
+            $class_list = $articleclass_model->getArticleclassList(array());
+            $tmp_class_name = array();
+            if (is_array($class_list)) {
+                foreach ($class_list as $k => $v) {
+                    $tmp_class_name[$v['ac_id']] = $v['ac_name'];
+                }
+            }
+            foreach ($article_list as $k => $v) {
+                /**
+                 * 发布时间
+                 */
+                $article_list[$k]['article_time'] = date('Y-m-d H:i:s', $v['article_time']);
+                /**
+                 * 所属分类
+                 */
+                if (@array_key_exists($v['ac_id'], $tmp_class_name)) {
+                    $article_list[$k]['ac_name'] = $tmp_class_name[$v['ac_id']];
+                }
+            }
+        }
+
+        /**
+         * 分类列表
+         */
+        $parent_list = $articleclass_model->getTreeClassList(2);
+        if (is_array($parent_list)) {
+            $unset_sign = false;
+            foreach ($parent_list as $k => $v) {
+                $parent_list[$k]['ac_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['ac_name'];
+            }
+        }
+
+        View::assign('article_list', $article_list);
+        View::assign('show_page', $article_model->page_info->render());
+        View::assign('search_title', $search_title);
+        View::assign('search_ac_id', $search_ac_id);
+        View::assign('parent_list', $parent_list);
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function add() {
+        if (!(request()->isPost())) {
+            $article = [
+                'article_id' => 0,
+                'article_title' => '',
+                'ac_id' => input('param.ac_id'),
+                'article_url' => '',
+                'article_show' => 0,
+                'article_sort' => 0,
+                'article_content' => '',
+            ];
+            $articleclass_model = model('articleclass');
+            $cate_list = $articleclass_model->getTreeClassList(2);
+            View::assign('ac_list', $cate_list);
+            View::assign('article', $article);
+            //游离图片
+            $article_pic_list = model('upload')->getUploadList(array('upload_type' => '1', 'item_id' => 0));
+            View::assign('file_upload', $article_pic_list);
+            $this->setAdminCurItem('add');
+            return View::fetch('form');
+        } else {
+            $data = array(
+                'article_title' => input('post.article_title'),
+                'ac_id' => input('post.ac_id'),
+                'article_url' => input('post.article_url'),
+                'article_sort' => input('post.article_sort'),
+                'article_content' => input('post.article_content'),
+                'article_time' => TIMESTAMP,
+            );
+            $data['article_show'] = intval(input('post.article_show'));
+
+            $article_validate = ds_validate('article');
+            if (!$article_validate->scene('add')->check($data)) {
+                $this->error($article_validate->getError());
+            }
+
+            $article_id = model('article')->addArticle($data);
+            if ($article_id) {
+                //更新图片信息ID
+                $upload_model = model('upload');
+                $file_id_array = input('post.file_id/a');
+                if (is_array($file_id_array)) {
+                    foreach ($file_id_array as $k => $v) {
+                        $update_array = array();
+                        $update_array['item_id'] = $article_id;
+                        $upload_model->editUpload($update_array,array(array('upload_id','=',intval($v))));
+                        unset($update_array);
+                    }
+                }
+                //上传文章封面
+                if (!empty($_FILES['_pic']['name'])) {
+                    $res=ds_upload_pic(ATTACH_ARTICLE,'_pic');
+                    if($res['code']){
+                        $article_pic=$res['data']['file_name'];
+                        model('article')->editArticle(array('article_pic' => $article_pic), $article_id);
+                    }else{
+                        $this->error($res['msg'], (string) url('Article/edit', ['article_id' => $article_id]));
+                    }
+                }
+                $this->success(lang('ds_common_save_succ'), 'Article/index');
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    public function edit() {
+        $art_id = intval(input('param.article_id'));
+        if ($art_id<=0) {
+            $this->error(lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('article_id','=',$art_id);
+        $article = model('article')->getOneArticle($condition);
+        if(!$article){
+            $this->error(lang('ds_no_record'));
+        }
+        if (!request()->isPost()) {
+            View::assign('article', $article);
+            $articleclass_model = model('articleclass');
+            $cate_list=$articleclass_model->getTreeClassList(2);
+            View::assign('ac_list', $cate_list);
+            //附属图片
+            $article_pic_list=model('upload')->getUploadList(array('upload_type'=>'1','item_id'=>$art_id));
+            View::assign('file_upload', $article_pic_list);
+            $this->setAdminCurItem('edit');
+            return View::fetch('form');
+        } else {
+            $data = array(
+                'article_title' => input('post.article_title'),
+                'ac_id' => input('post.ac_id'),
+                'article_url' => input('post.article_url'),
+                'article_sort' => input('post.article_sort'),
+                'article_content' => input('post.article_content'),
+                'article_time' => TIMESTAMP,
+            );
+            $data['article_show'] = intval(input('post.article_show'));
+            $article_validate = ds_validate('article');
+            if (!$article_validate->scene('edit')->check($data)) {
+                $this->error($article_validate->getError());
+            }
+
+            //上传文章封面
+            if (!empty($_FILES['_pic']['name'])) {
+                $res=ds_upload_pic(ATTACH_ARTICLE,'_pic');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    //删除原图
+                    if($article['article_pic']){
+                        @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $article['article_pic']);
+                    }
+                    $data['article_pic'] = $file_name;
+                }else{
+                    $this->error($res['msg'], (string)url('Article/edit', ['article_id' => $art_id]));
+                }
+            }
+            //验证数据  END
+            $result = model('article')->editArticle($data, $art_id);
+            if ($result) {
+                $this->success(lang('ds_common_save_succ'), 'Article/index');
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    public function drop() {
+        $article_id = input('param.article_id');
+        if (empty($article_id)) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('article_id','=',$article_id);
+        $article = model('article')->getOneArticle($condition);
+        if(!$article){
+            ds_json_encode(10001, lang('ds_no_record'));
+        }
+        //删除图片
+        if($article['article_pic']){
+            @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $article['article_pic']);
+        }
+        $article_pic_list=model('upload')->getUploadList(array('upload_type'=>'1','item_id'=>$article_id));
+        foreach($article_pic_list as $article_pic){
+            @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $article_pic['file_name']);
+        }
+        $result = model('article')->delArticle($article_id);
+        if ($result) {
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('error'));
+        }
+    }
+
+    /**
+     * 文章图片上传
+     */
+    public function article_pic_upload() {
+        $file_name = '';
+        $file_object = request()->file('fileupload');
+        if ($file_object) {
+                $res=ds_upload_pic(ATTACH_ARTICLE,'fileupload');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                }else{
+                    echo $res['msg'];
+                    exit;
+                }
+        } else {
+            echo 'error';
+            exit;
+        }
+
+        /**
+         * 模型实例化
+         */
+        $upload_model = model('upload');
+        /**
+         * 图片数据入库
+         */
+        $insert_array = array();
+        $insert_array['file_name'] = $file_name;
+        $insert_array['upload_type'] = '1';
+        $insert_array['file_size'] = $_FILES['fileupload']['size'];
+        $insert_array['item_id'] = intval(input('param.item_id'));
+        $insert_array['upload_time'] = TIMESTAMP;
+        $result = $upload_model->addUpload($insert_array);
+        if ($result) {
+            $data = array();
+            $data['file_id'] = $result;
+            $data['file_name'] = $file_name;
+            $data['file_path'] = ds_get_pic(ATTACH_ARTICLE , $file_name);
+            /**
+             * 整理为json格式
+             */
+            $output = json_encode($data);
+            echo $output;
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        switch (input('param.branch')) {
+            /**
+             * 删除文章图片
+             */
+            case 'del_file_upload':
+                if (intval(input('param.file_id')) > 0) {
+                    $upload_model = model('upload');
+                    /**
+                     * 删除图片
+                     */
+                    $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
+                    @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $file_array['file_name']);
+                    /**
+                     * 删除信息
+                     */
+                    $condition = array();
+                    $condition[] = array('upload_id','=',intval(input('param.file_id')));
+                    $upload_model->delUpload($condition);
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Article/index')
+            ),
+        );
+
+        if (request()->action() == 'add' || request()->action() == 'index') {
+            $menu_array[] = array(
+                'name' => 'add',
+                'text' => lang('ds_new'),
+                'url' => (string)url('Article/add')
+            );
+        }
+        if (request()->action() == 'edit') {
+            $menu_array[] = array(
+                'name' => 'edit',
+                'text' => lang('ds_edit'),
+                'url' => 'javascript:void(0)'
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 256 - 0
app/admin/controller/Articleclass.php

@@ -0,0 +1,256 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Articleclass extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/articleclass.lang.php');
+    }
+
+    /**
+     * 文章管理
+     */
+    public function index() {
+        $articleclass_model = model('articleclass');
+        /**
+         * 父ID
+         */
+        $parent_id = input('param.ac_parent_id') ? intval(input('param.ac_parent_id')) : 0;
+        /**
+         * 列表
+         */
+        $tmp_list = $articleclass_model->getTreeClassList(2);
+        $class_list = array();
+        if (is_array($tmp_list)) {
+            foreach ($tmp_list as $k => $v) {
+                if ($v['ac_parent_id'] == $parent_id) {
+                    /**
+                     * 判断是否有子类
+                     */
+                    $v['have_child'] = 0;
+                    if (isset($tmp_list[$k + 1]['deep']) && $tmp_list[$k + 1]['deep'] > $v['deep']) {
+                        $v['have_child'] = 1;
+                    }
+                    $class_list[] = $v;
+                }
+            }
+        }
+        if (input('param.ajax') == '1') {
+            /**
+             * 转码
+             */
+            $output = json_encode($class_list);
+            print_r($output);
+            exit;
+        } else {
+            View::assign('class_list', $class_list);
+            $this->setAdminCurItem('index');
+            return View::fetch('article_class_index');
+        }
+    }
+
+    /**
+     * 文章分类 新增
+     */
+    public function article_class_add() {
+        $articleclass_model = model('articleclass');
+        if (request()->isPost()) {
+            /**
+             * 验证
+             */
+            $data = [
+                'ac_name' => input('param.ac_name'),
+                'ac_sort' => input('param.ac_sort')
+            ];
+            $article_validate = ds_validate('article');
+            if (!$article_validate->scene('article_class_add')->check($data)) {
+                $this->error($article_validate->getError());
+            } else {
+
+                $insert_array = array();
+                $insert_array['ac_name'] = trim(input('param.ac_name'));
+                $insert_array['ac_parent_id'] = intval(input('param.ac_parent_id'));
+                $insert_array['ac_sort'] = trim(input('param.ac_sort'));
+
+                $result = $articleclass_model->addArticleclass($insert_array);
+                if ($result) {
+                    $this->log(lang('ds_add') . lang('article_class_index_class') . '[' . input('ac_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('article_class_add_succ'));
+                } else {
+                    $this->error(lang('article_class_add_fail'));
+                }
+            }
+        } else {
+            /**
+             * 父类列表,只取到第三级
+             */
+            $parent_list = $articleclass_model->getTreeClassList(1);
+            if (is_array($parent_list)) {
+                foreach ($parent_list as $k => $v) {
+                    $parent_list[$k]['ac_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['ac_name'];
+                }
+            }
+            View::assign('ac_parent_id', intval(input('param.ac_parent_id')));
+            View::assign('parent_list', $parent_list);
+            return View::fetch('article_class_edit');
+        }
+    }
+
+    /**
+     * 文章分类编辑
+     */
+    public function article_class_edit() {
+        $articleclass_model = model('articleclass');
+        
+        $ac_id = intval(input('param.ac_id'));
+        
+        if (request()->isPost()) {
+            /**
+             * 验证
+             */
+            $data = [
+                'ac_name' => input('param.ac_name'),
+                'ac_sort' => input('param.ac_sort')
+            ];
+            $article_validate = ds_validate('article');
+            if (!$article_validate->scene('article_class_edit')->check($data)) {
+                $this->error($article_validate->getError());
+            } else {
+
+                $update_array = array();
+                $update_array['ac_name'] = trim(input('post.ac_name'));
+                $update_array['ac_sort'] = trim(input('post.ac_sort'));
+
+                $result = $articleclass_model->editArticleclass($update_array,$ac_id);
+                if ($result>=0) {
+                    $this->log(lang('ds_edit') . lang('article_class_index_class') . '[' . input('post.ac_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('ds_common_op_succ'));
+                } else {
+                    $this->error(lang('ds_common_op_fail'));
+                }
+            }
+        } else {
+            $class_array = $articleclass_model->getOneArticleclass($ac_id);
+            if (empty($class_array)) {
+                $this->error(lang('param_error'));
+            }
+
+            View::assign('class_array', $class_array);
+            return View::fetch('article_class_edit');
+        }
+    }
+
+    /**
+     * 删除分类
+     */
+    public function article_class_del() {
+        $articleclass_model = model('articleclass');
+        
+        $ac_id = input('param.ac_id');
+        $ac_id_array = ds_delete_param($ac_id);
+        if ($ac_id_array === FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        
+
+            $del_array = $articleclass_model->getChildClass($ac_id_array);
+        if (is_array($del_array)) {
+            foreach ($del_array as $k => $v) {
+                $articleclass_model->delArticleclass($v['ac_id']);
+            }
+        }
+        $this->log(lang('ds_add') . lang('article_class_index_class') . '[ID:' . $ac_id . ']', 1);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        switch (input('param.branch')) {
+            /**
+             * 分类:验证是否有重复的名称
+             */
+            case 'article_class_name':
+                $articleclass_model = model('articleclass');
+                $class_array = $articleclass_model->getOneArticleclass(intval(input('param.id')));
+
+                $condition[]=array('ac_name','=',trim(input('param.value')));
+                $condition[]=array('ac_parent_id','=',$class_array['ac_parent_id']);
+                $condition[]=array('ac_id','<>',intval(input('param.id')));
+                $class_list = $articleclass_model->getArticleclassList($condition);
+                if (empty($class_list)) {
+                    $update_array = array();
+                    $update_array['ac_name'] = trim(input('param.value'));
+                    $articleclass_model->editArticleclass($update_array,input('param.id'));
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+            /**
+             * 分类: 排序 显示 设置
+             */
+            case 'article_class_sort':
+                $articleclass_model = model('articleclass');
+                $update_array = array();
+                $update_array[input('param.column')] = trim(input('param.value'));
+                $result = $articleclass_model->editArticleclass($update_array,intval(input('param.id')));
+                echo 'true';
+                exit;
+                break;
+            /**
+             * 分类:添加、修改操作中 检测类别名称是否有重复
+             */
+            case 'check_class_name':
+                $articleclass_model = model('articleclass');
+                $condition[]=array('ac_name','=',trim(input('param.ac_name')));
+//                $condition[] = array('ac_parent_id','=',intval(input('param.ac_parent_id')));
+                $condition[]=array('ac_id','<>',intval(input('param.ac_id')));
+                $class_list = $articleclass_model->getArticleclassList($condition);
+                if (empty($class_list)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' =>lang('ds_manage'),
+                'url' => (string)url('Articleclass/index')
+            ),
+            array(
+                'name' => 'add',
+                'text' => lang('ds_new'),
+                'url' =>"javascript:dsLayerOpen('".(string)url('Articleclass/article_class_add')."','".lang('article_class_add')."')",
+            )
+        );
+        return $menu_array;
+    }
+
+}

+ 552 - 0
app/admin/controller/Bill.php

@@ -0,0 +1,552 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+use app\common\model\Storemoneylog;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Bill extends AdminControl
+{
+    const EXPORT_SIZE = 1000;
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/bill.lang.php');
+    }
+
+    /**
+     * 所有月份销量账单
+     *
+     */
+    public function index()
+    {
+        //检查是否需要生成上月及更早结算单的程序不再执行,执行量较大,放到任务计划中触发
+        $condition = array();
+        $query_year = input('get.query_year');
+        if (preg_match('/^\d{4}$/', $query_year, $match)) {
+            $condition[]=array('os_month','like',$query_year.'%');
+        }
+        $bill_model = model('bill');
+        $bill_list = $bill_model->getOrderstatisList($condition, '*', 12, 'os_month desc');
+        View::assign('bill_list', $bill_list);
+        View::assign('show_page', $bill_model->page_info->render());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('index');
+        return View::fetch('index');
+    }
+
+    /**
+     * 某月所有店铺销量账单
+     *
+     */
+    public function show_statis()
+    {
+
+        $bill_model = model('bill');
+        $condition = array();
+
+        $bill_state = input('get.bill_state');
+        if (is_numeric($bill_state)) {
+            $condition[] = array('ob_state','=',intval($bill_state));
+        }
+        $query_store = input('get.query_store');
+        if (preg_match('/^\d{1,8}$/', $query_store)) {
+            $condition[] = array('ob_store_id','=',$query_store);
+        } elseif ($query_store != '') {
+            $condition[] = array('ob_store_name','=',$query_store);
+        }
+        $os_month = input('get.os_month');
+        if($os_month){
+            $condition[]=array('ob_startdate','>=',strtotime($os_month.'01 0:0:0'));
+            $condition[]=array('ob_enddate','<',strtotime($os_month.'01 23:59:59 +1 month -1 day'));
+        }
+        $bill_list = $bill_model->getOrderbillList($condition, '*', 30, 'ob_no desc');
+        View::assign('bill_list', $bill_list);
+        View::assign('show_page', $bill_model->page_info->render());
+
+        $this->setAdminCurItem('show_statis');
+        return View::fetch('show_statis');
+    }
+
+    /**
+     * 某店铺某月订单列表
+     *
+     */
+    public function show_bill()
+    {
+        $ob_no = input('param.ob_no');
+        if (!$ob_no) {
+            $this->error(lang('param_error'));
+        }
+        $bill_model = model('bill');
+        $bill_info = $bill_model->getOrderbillInfo(array('ob_no' => $ob_no));
+        if (!$bill_info) {
+            $this->error(lang('param_error'));
+        }
+
+        $order_condition = array();
+        $order_condition[] = array('ob_no','=',$ob_no);
+        $order_condition[] = array('order_state','=',ORDER_STATE_SUCCESS);
+        $order_condition[] = array('store_id','=',$bill_info['ob_store_id']);
+
+        $query_start_date = input('get.query_start_date');
+        $query_end_date = input('get.query_end_date');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
+        $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
+        $end_unixtime = $if_end_date ? strtotime($query_end_date) : null;
+
+        $end_unixtime = $if_end_date ? $end_unixtime + 86400 - 1 : null;
+        if ($if_start_date || $if_end_date) {
+            if($if_start_date){
+                $order_condition[]=array('finnshed_time','>=', $start_unixtime);
+            }
+            if($if_end_date){
+                $order_condition[]=array('finnshed_time','<=', $end_unixtime);
+            }
+        }
+
+        $query_type = input('param.query_type');
+        if ($query_type == 'cost') {
+
+            //店铺费用
+            $storecost_model = model('storecost');
+            $cost_condition = array();
+            $cost_condition[] = array('storecost_store_id','=',$bill_info['ob_store_id']);
+            $cost_condition[] = array('storecost_time','between',[$bill_info['ob_startdate'],$bill_info['ob_enddate']]);
+            $store_cost_list = $storecost_model->getStorecostList($cost_condition, 20);
+            //取得店铺名字
+            $store_info = model('store')->getStoreInfoByID($bill_info['ob_store_id']);
+            View::assign('cost_list', $store_cost_list);
+            View::assign('store_info', $store_info);
+            View::assign('show_page', $storecost_model->page_info->render());
+            $sub_tpl_name = 'show_cost_list';
+        }elseif ($query_type == 'vrorder') {
+
+            //店铺费用
+            $vrorder_model = model('vrorder');
+            $order_list = $vrorder_model->getVrorderList($order_condition, 20,'(ROUND(order_amount*commis_rate/100,2)) AS commis_amount,(ROUND(refund_amount*commis_rate/100,2)) AS return_commis_amount,order_amount,refund_amount,order_sn,buyer_name,add_time,finnshed_time,order_id');
+            foreach($order_list as $key => $val){
+                if(!$val['order_id']){
+                    $order_list=array();
+                    break;
+                }
+                //分销佣金
+                $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 1))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
+                $order_list[$key]['inviter_amount']= ds_price_format($inviter_info['ob_inviter_totals']);
+            }
+            View::assign('order_list', $order_list);
+            View::assign('show_page', $vrorder_model->page_info->render());
+            $sub_tpl_name = 'show_vrorder_list';
+        } else {
+
+            //订单列表
+            $order_model = model('order');
+            $order_list = $order_model->getOrderList($order_condition, 20);
+
+            //然后取订单商品佣金
+            $order_id_array = array();
+            if (is_array($order_list)) {
+                foreach ($order_list as $order_info) {
+                    $order_id_array[] = $order_info['order_id'];
+                }
+            }
+            $order_goods_condition = array();
+            $order_goods_condition[] = array('order_id','in',$order_id_array);
+            $field = 'SUM(ROUND(goods_pay_price*commis_rate/100,2)) as commis_amount,order_id';
+            $commis_list = $order_model->getOrdergoodsList($order_goods_condition, $field, 0, null, '', 'order_id', 'order_id');
+            foreach($commis_list as $key => $val){
+                $return_commis_amount=0;
+                $refund_info=Db::name('refundreturn')->alias('refundreturn')->join('ordergoods ordergoods', 'refundreturn.order_goods_id = ordergoods.rec_id')->where(array(array('refundreturn.order_id' ,'=', $key), array('refundreturn.refund_state' ,'=', 3), array('refundreturn.order_goods_id','>', 0)))->field('SUM(ROUND(refundreturn.refund_amount*ordergoods.commis_rate/100,2)) AS ob_commis_return_totals')->find();
+                $return_commis_amount=$refund_info['ob_commis_return_totals'];
+                $commis_list[$key]['return_commis_amount']=$return_commis_amount;
+                //分销佣金
+                $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 0))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
+                $commis_list[$key]['inviter_amount']=$inviter_info['ob_inviter_totals'];
+                //平台代金券
+                $mallvoucher_info=Db::name('ordercommon')->where(array('order_id' => $key))->field('mallvoucher_price')->find();
+                $commis_list[$key]['mall_voucher_totals']=number_format($mallvoucher_info['mallvoucher_price'], 2);
+            }
+            View::assign('commis_list', $commis_list);
+            View::assign('order_list', $order_list);
+            View::assign('show_page', $order_model->page_info->render());
+            $sub_tpl_name = 'show_order_list';
+        }
+        View::assign('bill_info', $bill_info);
+        return View::fetch($sub_tpl_name);
+    }
+
+    public function bill_check() {
+        $ob_no = input('param.ob_no');
+        if (!$ob_no) {
+            $this->error(lang('param_error'));
+        }
+        $bill_model = model('bill');
+        $condition = array();
+        $condition[] = array('ob_no','=',$ob_no);
+        $condition[] = array('ob_state','=',BILL_STATE_STORE_COFIRM);
+        $bill_info = $bill_model->getOrderbillInfo($condition);
+        if (!$bill_info) {
+            $this->error(lang('bill_is_not_exist'));
+        }
+        if (request()->isPost()) {
+            
+            Db::startTrans();
+            try {
+                if($bill_info['ob_result_totals']!=0){
+                    $storemoneylog_model=model('storemoneylog');
+                    $data=array(
+                        'store_id'=>$bill_info['ob_store_id'],
+                        'storemoneylog_type'=>Storemoneylog::TYPE_BILL,
+                        'storemoneylog_state'=>Storemoneylog::STATE_VALID,
+                        'storemoneylog_add_time'=>TIMESTAMP,
+                        'store_avaliable_money'=>$bill_info['ob_result_totals'],//如果是欠账则从店铺余额里扣除,否则增加
+                        'storemoneylog_desc'=>$ob_no.lang('bill_phase_numbers').lang('bill_state_success'),
+                    );
+
+                    $storemoneylog_model->changeStoremoney($data);
+                }
+                $update = $bill_model->editOrderbill(array('ob_state' => BILL_STATE_SUCCESS,'ob_admin_content'=>input('post.ob_admin_content')), $condition);
+                if (!$update) {
+                    throw new \think\Exception(lang('bill_audit_fail'), 10006);
+                }
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->log(lang('bill_audit_bill') . $ob_no, 0);
+                $this->error($e->getMessage());
+            }
+            Db::commit();
+            $this->log(lang('bill_audit_bill') . $ob_no, 1);
+            $this->success(lang('bill_audit_succ'),(string)url('Bill/show_bill',['ob_no'=>$ob_no]));
+        } else {
+            return View::fetch('bill_check');
+        }
+    }
+
+    /**
+     * 账单付款
+     *
+     */
+    public function bill_pay()
+    {
+        $ob_no = input('param.ob_no');
+        if (!preg_match('/^20\d{5,12}$/', $ob_no)) {
+            $this->error(lang('param_error'));
+        }
+        $bill_model = model('bill');
+        $condition = array();
+        $condition[] = array('ob_no','=',$ob_no);
+        $condition[] = array('ob_state','=',BILL_STATE_SYSTEM_CHECK);
+        $bill_info = $bill_model->getOrderbillInfo($condition);
+        if (!$bill_info) {
+            $this->error(lang('param_error'));
+        }
+        if (request()->isPost()) {
+            if (!preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.pay_date'))) {
+                $this->error(lang('param_error'));
+            }
+            $input = array();
+            $input['ob_pay_content'] = input('pay_content');
+            $input['ob_paydate'] = strtotime(input('param.pay_date'));
+            $input['ob_state'] = BILL_STATE_SUCCESS;
+            $update = $bill_model->editOrderbill($input, $condition);
+            if ($update) {
+                $storecost_model = model('storecost');
+                $cost_condition = array();
+                $cost_condition[] = array('storecost_store_id','=',$bill_info['ob_store_id']);
+                $cost_condition[] = array('storecost_state','=',0);
+                $cost_condition[] = array('storecost_time','between', "{$bill_info['ob_startdate']},{$bill_info['ob_enddate']}");
+                $storecost_model->editStorecost(array('storecost_state' => 1), $cost_condition);
+
+                // 发送店铺消息
+                $param = array();
+                $param['code'] = 'store_bill_gathering';
+                $param['store_id'] = $bill_info['ob_store_id'];
+                $param['ali_param'] = array(
+                    'bill_no' => $bill_info['ob_no']
+                );
+                $param['ten_param'] = array(
+                    $bill_info['ob_no']
+                );
+                $param['param'] = $param['ali_param'];
+                //微信模板消息
+                $param['weixin_param'] = array(
+                    'url' => config('ds_config.h5_site_url').'/seller/billlist',
+                    'data'=>array(
+                        "keyword1" => array(
+                            "value" => date('Y-m-d', $bill_info['ob_startdate']).'~'.date('Y-m-d', $bill_info['ob_enddate']),
+                            "color" => "#333"
+                        ),
+                        "keyword2" => array(
+                            "value" => date('Y-m-d', $bill_info['ob_createdate']),
+                            "color" => "#333"
+                        ),
+                        "keyword3" => array(
+                            "value" => $bill_info['ob_result_totals'],
+                            "color" => "#333"
+                        )
+                    ),
+                );
+                model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize($param)));
+
+                $this->log(lang('bill_payment_audit_fail') . $ob_no, 1);
+                $this->success(lang('ds_common_save_succ'), 'bill/show_statis?os_month=' . $bill_info['os_month']);
+            } else {
+                $this->log(lang('bill_payment_audit_fail') . $ob_no, 1);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $this->setAdminCurItem('bill_pay');
+            return View::fetch('bill_pay');
+        }
+    }
+
+    /**
+     * 打印结算单
+     *
+     */
+    public function bill_print()
+    {
+        $ob_no = input('param.ob_no');
+        if (!$ob_no) {
+            $this->error(lang('param_error'));
+        }
+        $bill_model = model('bill');
+        $condition = array();
+        $condition[] = array('ob_no','=',$ob_no);
+        $condition[] = array('ob_state','=',BILL_STATE_SUCCESS);
+        $bill_info = $bill_model->getOrderbillInfo($condition);
+        if (!$bill_info) {
+            $this->error(lang('param_error'));
+        }
+
+        View::assign('bill_info', $bill_info);
+
+        return View::fetch('bill_print');
+    }
+
+    /**
+     * 导出 结算管理
+     *
+     */
+    public function export_js_step1() {
+        $bill_model = model('bill');
+        $condition = array();
+        $query_year = input('get.query_year');
+        if (preg_match('/^\d{4}$/', $query_year, $match)) {
+            $condition[]=array('os_month','like',$query_year.'%');
+        }
+        if (!is_numeric(input('param.page'))) {
+            $count = $bill_model->getOrderstatisCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $bill_model->getOrderstatisList($condition, '*', '', '', self::EXPORT_SIZE);
+                $this->createJsExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $bill_model->getOrderstatisList($condition, '*', $limit2);
+            $this->createJsExcel($data);
+        }
+    }
+
+    /**
+     * 结算管理 生成excel
+     *
+     * @param array $data
+     */
+    private function createJsExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_order_number_bill'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_order_price_from'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_order_total_transport'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_commis_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_order_returntotals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_commis_returntotals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_store_costtotals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_ob_inviter_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_result_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_js_os_createdate'));
+        //data
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => substr($v['os_month'],0,4).'-'.substr($v['os_month'],4));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_order_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_shipping_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_commis_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_order_returntotals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_commis_returntotals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_store_costtotals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_inviter_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['os_result_totals']));
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['os_createdate']));
+
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_js_list'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_js_list'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 商家账单列表 管理
+     *
+     */
+    public function export_zd_step1() {
+
+        $bill_model = model('bill');
+        $condition = array();
+
+        $bill_state = input('get.bill_state');
+        if (is_numeric($bill_state)) {
+            $condition[] = array('ob_state','=',intval($bill_state));
+        }
+        $query_store = input('get.query_store');
+        if (preg_match('/^\d{1,8}$/', $query_store)) {
+            $condition[] = array('ob_store_id','=',$query_store);
+        } elseif ($query_store != '') {
+            $condition[] = array('ob_store_name','=',$query_store);
+        }
+        $os_month = input('get.os_month');
+        if($os_month){
+            $condition[]=array('ob_startdate','>=',strtotime($os_month.'01 0:0:0'));
+            $condition[]=array('ob_enddate','<',strtotime($os_month.'01 23:59:59 +1 month -1 day'));
+        }
+        if (!is_numeric(input('param.page'))) {
+            $count = $bill_model->getOrderbillCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $bill_model->getOrderbillList($condition, '*', '', '', self::EXPORT_SIZE);
+                $this->createZdExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $bill_model->getOrderbillList($condition, '*', $limit2);
+            $this->createZdExcel($data);
+        }
+    }
+
+    /**
+     * 商家账单列表 生成excel
+     *
+     * @param array $data
+     */
+    private function createZdExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_no'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_os_startdate'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_os_enddate'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_order_price_from'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_order_total_transport'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_print_commision'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_order_return_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_os_commis_returntotals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_ob_inviter_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_vr_order_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_vr_order_return_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_vr_commis_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_vr_commis_return_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_ob_vr_inviter_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_os_store_costtotals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_os_result_totals'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_out_date'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_zd_bill_state'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_store_name'));
+        //data
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['ob_no']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['ob_startdate']));
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['ob_enddate']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_order_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_shipping_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_commis_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_order_return_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_commis_return_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_inviter_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_vr_order_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_vr_order_return_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_vr_commis_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_vr_commis_return_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_vr_inviter_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_store_cost_totals']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['ob_result_totals']));
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['ob_createdate']));
+            $tmp[] = array('data' => get_bill_state($v['ob_state']));
+            $tmp[] = array('data' => $v['ob_store_name']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_zd_list'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_zd_list'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_bill'),
+                'url' => (string)url('Bill/index')
+            ),
+        );
+            $title = !empty(input('param.os_month')) ? input('param.os_month') . lang('bill_period') : '';
+            $menu_array[] = array(
+                'name' => 'show_statis',
+                'text' => $title . lang('bill_billing_list'),
+                'url' => !empty($title) ? (string)url('Bill/show_statis', ['os_month' => input('param.os_month')]) : (string)url('Bill/show_statis'),
+            );
+        return $menu_array;
+    }
+}
+
+?>

+ 248 - 0
app/admin/controller/Bonus.php

@@ -0,0 +1,248 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 平台红包 控制器
+ */
+class Bonus extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/bonus.lang.php');
+    }
+
+    public function index() {
+        $condition = array();
+        $bonus_name = input('param.bonus_name');
+        if (!empty($bonus_name)) {
+            $condition[]=array('bonus_name','like', '%' . $bonus_name . '%');
+        }
+        //红包是否有效
+        $bonus_state = intval(input('get.bonus_state'));
+        if ($bonus_state) {
+            $condition[]=array('bonus_state','=',$bonus_state);
+        }
+        //红包类型
+        $bonus_type = intval(input('get.bonus_type'));
+        if ($bonus_type) {
+            $condition[]=array('bonus_type','=',$bonus_type);
+        }
+        $bonus_model = model('bonus');
+        $bonus_list = $bonus_model->getBonusList($condition, 10);
+
+        //红包类型
+        View::assign('bonus_type_list', $bonus_model->bonus_type_list());
+        //红包状态
+        View::assign('bonus_state_list', $bonus_model->bonus_state_list());
+
+        View::assign('bonus_list', $bonus_list);
+        View::assign('show_page', $bonus_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 添加吸粉红包
+     */
+    public function add() {
+        $bonus_model = model('bonus');
+        if (!request()->isPost()) {
+            $bonus = array(
+                'bonus_type' => 1,
+                'bonus_begintime' => TIMESTAMP,
+                'bonus_endtime' => TIMESTAMP+3600*24*7,
+            );
+            //红包类型
+            View::assign('bonus_type_list', $bonus_model->bonus_type_list());
+            View::assign('bonus', $bonus);
+            return View::fetch('form');
+        } else {
+            $bonus_totalprice = floatval(input('param.bonus_totalprice'));
+            $bonus_pricetype = intval(input('param.bonus_pricetype'));
+            $bonus_fixedprice = floatval(input('param.bonus_fixedprice'));
+            $bonus_randomprice_start = floatval(input('param.bonus_randomprice_start'));
+            $bonus_randomprice_end = floatval(input('param.bonus_randomprice_end'));
+
+            //计算写入吸粉红包领取记录表
+            $data_bonusreceive = array(); //红包领取记录
+            if ($bonus_pricetype == 1) {
+                //固定金额
+                if ($bonus_fixedprice == 0 || $bonus_fixedprice > $bonus_totalprice) {
+                    $this->error(lang('bonus_fixedprice_error'));
+                }
+                if (($bonus_totalprice*100) % ($bonus_fixedprice*100) != 0) {
+                    $this->error(lang('bonus_fixedprice_error'));
+                }
+                //生成红包领取记录-固定金额
+                for ($i = 0; $i < $bonus_totalprice / $bonus_fixedprice; $i++) {
+                    $data_bonusreceive[] = array(
+                        'bonusreceive_price' => $bonus_fixedprice
+                    );
+                }
+                $bonus_randomprice_start = 0;
+                $bonus_randomprice_end = 0;
+            } else {
+                if ($bonus_randomprice_start == 0 || $bonus_randomprice_start > $bonus_totalprice || $bonus_randomprice_end > $bonus_totalprice || $bonus_randomprice_start >= $bonus_randomprice_end) {
+                    $this->error(lang('bonus_randomprice_error'));
+                }
+                //生成红包领取记录-随机金额
+                $surplus_price = $bonus_totalprice; //剩余未计算金额
+                while (true) {
+                    if ($surplus_price <= $bonus_randomprice_end) {
+                        $bonusreceive_price = $surplus_price;
+                    } else {
+                        $bonusreceive_price = rand($bonus_randomprice_start * 100, $bonus_randomprice_end * 100) / 100;
+                    }
+                    $surplus_price -= $bonusreceive_price;
+                    $data_bonusreceive[] = array(
+                        'bonusreceive_price' => $bonusreceive_price
+                    );
+                    if ($surplus_price == 0) {
+                        break;
+                    }
+                }
+                $bonus_fixedprice = 0;
+            }
+
+            $data_bonus = array(
+                'bonus_type' => input('param.bonus_type'),
+                'bonus_name' => input('param.bonus_name'),
+                'bonus_remark' => input('param.bonus_remark'),
+                'bonus_blessing' => input('param.bonus_blessing'),
+                'bonus_begintime' => strtotime(input('param.bonus_begintime')),
+                'bonus_endtime' => strtotime(input('param.bonus_endtime')),
+                'bonus_state' => 1,
+                'bonus_totalprice' => $bonus_totalprice,
+                'bonus_pricetype' => $bonus_pricetype,
+                'bonus_fixedprice' => $bonus_fixedprice,
+                'bonus_randomprice_start' => $bonus_randomprice_start,
+                'bonus_randomprice_end' => $bonus_randomprice_end,
+            );
+            $bonus_id = $bonus_model->addBonus($data_bonus);
+
+            if ($bonus_id > 0) {
+                foreach ($data_bonusreceive as $key => $bonusreceive) {
+                    $data_bonusreceive[$key]['bonus_id'] = $bonus_id;
+                }
+                Db::name('bonusreceive')->insertAll($data_bonusreceive);
+                $this->log(lang('ds_add') . lang('ds_bonus') . '[ID' . $bonus_id . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑吸粉红包  不可以对金额以及红包类型进行编辑。
+     */
+    public function edit() {
+        $bonus_id = intval(input('param.bonus_id'));
+        if ($bonus_id < 0) {
+            ds_json_encode(10000, lang('param_error'));
+        }
+        $bonus_model = model('bonus');
+        $condition = array();
+        $condition[] = array('bonus_id','=',$bonus_id);
+        if (!request()->isPost()) {
+            $bonus = $bonus_model->getOneBonus($condition);
+            View::assign('bonus', $bonus);
+            //红包类型
+            View::assign('bonus_type_list', $bonus_model->bonus_type_list());
+            return View::fetch('form');
+        } else {
+            $data_bonus = array(
+                'bonus_name' => input('param.bonus_name'),
+                'bonus_remark' => input('param.bonus_remark'),
+                'bonus_blessing' => input('param.bonus_blessing'),
+                'bonus_begintime' => strtotime(input('param.bonus_begintime')),
+                'bonus_endtime' => strtotime(input('param.bonus_endtime')),
+            );
+            $bonus_model->editBonus($condition, $data_bonus);
+            $this->log(lang('ds_edit') . lang('ds_bonus') . '[ID' . $bonus_id . ']', 1);
+            dsLayerOpenSuccess(lang('ds_common_save_succ'));
+        }
+    }
+
+    /**
+     * 设置红包失效    1正在进行  2过期  3失效
+     */
+    public function invalid() {
+        $bonus_id = intval(input('param.bonus_id'));
+        if ($bonus_id < 0) {
+            ds_json_encode(10000, lang('param_error'));
+        }
+        $bonus_model = model('bonus');
+        $condition = array();
+        $condition[] = array('bonus_id','=',$bonus_id);
+        $data['bonus_state'] = 3;
+        $bonus_model->editBonus($condition, $data);
+        $this->log(lang('ds_edit') . lang('ds_bonus') . '[ID' . $bonus_id . ']', 1);
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 领取列表
+     */
+    public function receive() {
+        $bonus_id = intval(input('param.bonus_id'));
+        if ($bonus_id < 0) {
+            $this->error(lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('bonus_id','=',$bonus_id);
+        $bonus_model = model('bonus');
+        $bonusreceive_list = $bonus_model->getBonusreceiveList($condition, 10);
+        View::assign('bonusreceive_list', $bonusreceive_list);
+        View::assign('show_page', $bonus_model->page_info->render());
+        return View::fetch();
+    }
+    
+    //链接信息
+    public function link()
+    {
+        $bonus_id = intval(input('param.bonus_id'));
+        if ($bonus_id < 0) {
+            $this->error(lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('bonus_id','=',$bonus_id);
+        $bonus_model = model('bonus');
+        $bonus = $bonus_model->getOneBonus($condition);
+        View::assign('bonus', $bonus);
+        $bonus_url = config('ds_config.h5_site_url')."/home/bonus_detail?bonus_id=".$bonus['bonus_id'];
+        View::assign('bonus_url', $bonus_url);
+        return View::fetch();
+    }
+    
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Bonus/index')
+            ),
+            array(
+                'name' => 'add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Bonus/add') . "','".lang('ds_add')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 457 - 0
app/admin/controller/Brand.php

@@ -0,0 +1,457 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Brand extends AdminControl {
+
+    const EXPORT_SIZE = 1000;
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/brand.lang.php');
+    }
+
+    /**
+     * 品牌列表
+     */
+    public function index() {
+        $brand_model = model('brand');
+        /**
+         * 检索条件
+         */
+        if (!empty(input('param.search_brand_name'))) {
+            $condition[] = array('brand_name', 'like', "%" . input('param.search_brand_name') . "%");
+        }
+        if (!empty(input('param.search_brand_class'))) {
+            $condition[] = array('brand_class', 'like', "%" . input('param.search_brand_class') . "%");
+        }
+        $condition[] = array('brand_apply', '=', '1');
+        $brand_list = $brand_model->getBrandList($condition, "*", 10);
+        View::assign('showpage', $brand_model->page_info->render());
+        View::assign('brand_list', $brand_list);
+        View::assign('search_brand_name', trim(input('param.search_brand_name')));
+        View::assign('search_brand_class', trim(input('param.search_brand_class')));
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 增加品牌
+     */
+    public function brand_add() {
+
+        $brand_model = model('brand');
+        if (request()->isPost()) {
+            $data = [
+                'brand_name' => input('post.brand_name'), 'brand_initial' => input('post.brand_initial'),
+                'brand_sort' => input('post.brand_sort')
+            ];
+            $brand_validate = ds_validate('brand');
+
+            if (!$brand_validate->scene('brand_add')->check($data)) {
+                $this->error($brand_validate->getError());
+            } else {
+                $insert_array = array();
+                if (!empty($_FILES['_pic']['name'])) {
+                    $res=ds_upload_pic(ATTACH_BRAND,'_pic');
+                    if($res['code']){
+                        $brand_pic=$res['data']['file_name'];
+                    }else{
+                        $this->error($res['msg']);
+                    }
+                }
+                $insert_array['brand_name'] = trim(input('post.brand_name'));
+                $insert_array['brand_initial'] = strtoupper(input('post.brand_initial'));
+                $insert_array['gc_id'] = input('post.class_id');
+                $insert_array['brand_class'] = trim(input('post.brand_class'));
+                if (!empty($brand_pic)) {
+                    $insert_array['brand_pic'] = $brand_pic;
+                }
+                $insert_array['brand_recommend'] = trim(input('post.brand_recommend'));
+                $insert_array['brand_sort'] = intval(input('post.brand_sort'));
+                $insert_array['brand_showtype'] = intval(input('post.brand_showtype')) == 1 ? 1 : 0;
+                $result = $brand_model->addBrand($insert_array);
+                if ($result) {
+                    $this->log(lang('ds_add') . lang('brand_index_brand') . '[' . input('post.brand_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('ds_common_save_succ'));
+                } else {
+                    $this->error(lang('ds_common_save_fail'));
+                }
+            }
+        } else {
+            $brand_array = [
+                'brand_id' => '',
+                'brand_name' => '',
+                'brand_initial' => '',
+                'gc_id' => '',
+                'brand_class' => '',
+                'brand_pic' => '',
+                'brand_showtype' => '0',
+                'brand_recommend' => '1',
+                'brand_sort' => '0',
+            ];
+            View::assign('brand_array', $brand_array);
+
+            // 一级商品分类
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            return View::fetch('form');
+        }
+    }
+
+    /**
+     * 品牌编辑
+     */
+    public function brand_edit() {
+        $brand_model = model('brand');
+
+        if (request()->isPost()) {
+            $data = [
+                'brand_name' => input('post.brand_name'), 'brand_initial' => input('post.brand_initial'),
+                'brand_sort' => input('post.brand_sort')
+            ];
+            $brand_validate = ds_validate('brand');
+            if (!$brand_validate->scene('brand_edit')->check($data)) {
+                $this->error($brand_validate->getError());
+            } else {
+                if (!empty($_FILES['_pic']['name'])) {
+                    $res=ds_upload_pic(ATTACH_BRAND,'_pic');
+                    if($res['code']){
+                        $brand_pic=$res['data']['file_name'];
+                    }else{
+                        $this->error($res['msg']);
+                    }
+                }
+                $brand_info = $brand_model->getBrandInfo(array('brand_id' => intval(input('post.brand_id'))));
+                $condition = array();
+                $condition[] = array('brand_id', '=', intval(input('post.brand_id')));
+                $update_array = array();
+                $update_array['brand_name'] = trim(input('post.brand_name'));
+                $update_array['brand_initial'] = strtoupper(input('post.brand_initial'));
+                $update_array['gc_id'] = input('post.class_id');
+                $update_array['brand_class'] = trim(input('post.brand_class'));
+                if (!empty($brand_pic)) {
+                    $update_array['brand_pic'] = $brand_pic;
+                }
+                $update_array['brand_recommend'] = intval(input('post.brand_recommend'));
+                $update_array['brand_sort'] = intval(input('post.brand_sort'));
+                $update_array['brand_showtype'] = intval(input('post.brand_showtype')) == 1 ? 1 : 0;
+                $result = $brand_model->editBrand($condition, $update_array);
+                if ($result >= 0) {
+                    if (!empty(input('post.brand_pic')) && !empty($brand_info['brand_pic'])) {
+                        @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_BRAND . DIRECTORY_SEPARATOR . $brand_info['brand_pic']);
+                    }
+                    $this->log(lang('ds_edit') . lang('brand_index_brand') . '[' . input('post.brand_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('ds_common_save_succ'));
+                } else {
+                    $this->log(lang('ds_edit') . lang('brand_index_brand') . '[' . input('post.brand_name') . ']', 0);
+                    $this->error(lang('ds_common_save_fail'));
+                }
+            }
+        } else {
+            $brand_info = $brand_model->getBrandInfo(array('brand_id' => intval(input('param.brand_id'))));
+            if (empty($brand_info)) {
+                $this->error(lang('param_error'));
+            }
+            View::assign('brand_array', $brand_info);
+            // 一级商品分类
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            return View::fetch('form');
+        }
+    }
+
+    /**
+     * 删除品牌
+     */
+    public function brand_del() {
+        $brand_id = input('param.brand_id');
+        $brand_id_array = ds_delete_param($brand_id);
+        if ($brand_id_array == FALSE) {
+            $this->log(lang('ds_del') . lang('brand_index_brand') . '[ID:' . $brand_id . ']', 0);
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $brand_mod = model('brand');
+        $condition = array();
+        $condition[] = array('brand_id', 'in', $brand_id_array);
+        $brand_mod->delBrand($condition);
+        $this->log(lang('ds_del') . lang('brand_index_brand') . '[ID:' . $brand_id . ']', 1);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+    /**
+     * 品牌申请
+     */
+    public function brand_apply() {
+        $brand_model = model('brand');
+        /**
+         * 对申请品牌进行操作 通过,拒绝
+         */
+        if (request()->isPost()) {
+            $del_id_array = input('post.del_id/a'); #获取数组
+            if (!empty($del_id_array)) {
+                switch (input('post.type')) {
+                    case 'pass':
+                        //更新品牌 申请状态
+                        $brandid_array = array();
+                        foreach ($del_id_array as $v) {
+                            $brandid_array[] = intval($v);
+                        }
+                        $update_array = array();
+                        $update_array['brand_apply'] = 1;
+                        $condition = array();
+                        $condition[] = array('brand_id', 'in', $brandid_array);
+                        $brand_model->editBrand($condition, $update_array);
+                        $this->log(lang('brand_apply_pass') . '[ID:' . implode(',', $brandid_array) . ']', null);
+                        $this->success(lang('brand_apply_passed'));
+                        break;
+                    case 'refuse':
+                        //删除该品牌
+                        $brandid_array = array();
+                        foreach ($del_id_array as $v) {
+                            $brandid_array[] = intval($v);
+                        }
+                        $condition = array();
+                        $condition[] = array('brand_id', 'in', $brandid_array);
+                        $brand_model->delBrand($condition);
+                        $this->log(lang('ds_del') . lang('brand_index_brand') . '[ID:' . implode(',', $del_id_array) . ']', 1);
+                        $this->success(lang('ds_common_del_succ'));
+                        break;
+                    default:
+                        $this->success(lang('brand_apply_invalid_argument'));
+                }
+            } else {
+                $this->log(lang('ds_del') . lang('brand_index_brand'), 0);
+                $this->error(lang('ds_common_del_fail'));
+            }
+        } else {
+            /**
+             * 检索条件
+             */
+            $condition = array();
+            if (!empty(input('param.search_brand_name'))) {
+                $condition[] = array('brand_name', 'like', '%' . trim(input('param.search_brand_name')) . '%');
+            }
+            if (!empty(input('param.search_brand_class'))) {
+                $condition[] = array('brand_class', 'like', '%' . trim(input('param.search_brand_class')) . '%');
+            }
+            $brand_list = $brand_model->getBrandNoPassedList($condition, '*', 10);
+
+            View::assign('brand_list', $brand_list);
+            View::assign('show_page', $brand_model->page_info->render());
+            View::assign('search_brand_name', trim(input('param.search_brand_name')));
+            View::assign('search_brand_class', trim(input('param.search_brand_class')));
+            View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+            $this->setAdminCurItem('brand_apply');
+            return View::fetch('brand_apply');
+        }
+    }
+
+    /**
+     * 审核 申请品牌操作
+     */
+    public function brand_apply_set() {
+        $brand_model = model('brand');
+
+        if (intval(input('param.brand_id')) > 0) {
+            switch (input('param.state')) {
+                case 'pass':
+                    /**
+                     * 更新品牌 申请状态
+                     */
+                    $update_array = array();
+                    $update_array['brand_apply'] = 1;
+                    $result = $brand_model->editBrand(array('brand_id' => intval(input('param.brand_id'))), $update_array);
+                    if ($result) {
+                        $this->log(lang('brand_apply_pass') . '[ID:' . intval(input('param.brand_id')) . ']', null);
+                        $this->success(lang('brand_apply_pass'));
+                    } else {
+                        $this->log(lang('brand_apply_fail') . '[ID:' . intval(input('param.brand_id')) . ')', 0);
+                        $this->error(lang('brand_apply_fail'));
+                    }
+                    break;
+                case 'refuse':
+                    // 删除
+                    $brand_model->delBrand(array('brand_id' => intval(input('param.brand_id'))));
+                    $this->log(lang('ds_del') . lang('brand_index_brand') . '[ID:' . intval(input('param.brand_id')) . ']', 1);
+                    $this->success(lang('ds_common_del_succ'));
+                    break;
+                default:
+                    $this->error(lang('brand_apply_paramerror'));
+            }
+        } else {
+            $this->log(lang('ds_del') . lang('brand_index_brand') . '[ID:' . intval(input('param.brand_id')) . ']', 0);
+            $this->error(lang('brand_apply_brandparamerror'));
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $brand_model = model('brand');
+        switch (input('param.branch')) {
+            /**
+             * 品牌名称
+             */
+            case 'brand_name':
+                /**
+                 * 判断是否有重复
+                 */
+                $condition[] = array('brand_name', '=', trim(input('param.value')));
+                $condition[] = array('brand_id', '<>', intval(input('param.id')));
+                $result = $brand_model->getBrandList($condition);
+                if (empty($result)) {
+                    $brand_model->editBrand(array('brand_id' => intval(input('param.id'))), array('brand_name' => trim(input('param.value'))));
+                    $this->log(lang('ds_edit') . lang('brand_index_name') . '[' . input('param.value') . ']', 1);
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+            /**
+             * 品牌类别,品牌排序,推荐
+             */
+            case 'brand_class':
+            case 'brand_sort':
+            case 'brand_recommend':
+                $brand_model->editBrand(array('brand_id' => intval(input('param.id'))), array(input('param.column') => trim(input('param.value'))));
+                $detail_log = str_replace(array(
+                    'brand_class', 'brand_sort', 'brand_recommend'
+                        ), array(
+                    lang('brand_index_class'), lang('ds_sort'), lang('ds_recommend')
+                        ), input('param.branch'));
+                $this->log(lang('ds_edit') . lang('brand_index_brand') . $detail_log . '[ID:' . intval(input('param.id')) . ')', 1);
+                echo 'true';
+                exit;
+                break;
+            /**
+             * 验证品牌名称是否有重复
+             */
+            case 'check_brand_name':
+                $condition[] = array('brand_name', '=', trim(input('param.brand_name')));
+                $condition[] = array('brand_id', '<>', intval(input('param.id')));
+                $result = $brand_model->getBrandList($condition);
+                if (empty($result)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    /**
+     * 品牌导出第一步
+     */
+    public function export_step1() {
+        $brand_model = model('brand');
+        $condition = array();
+        if ((input('param.search_brand_name'))) {
+            $condition[] = array('brand_name', 'like', "%{input('param.search_brand_name')}%");
+        }
+        if ((input('param.search_brand_class'))) {
+            $condition[] = array('brand_class', 'like', "%{input('param.search_brand_class')}%");
+        }
+        $condition[] = array('brand_apply', '=', '1');
+
+        if (!is_numeric(input('param.page'))) {
+            $count = $brand_model->getBrandCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) {    //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('export_excel');
+            } else {    //如果数量小,直接下载
+                $data = $brand_model->getBrandList($condition, '*', self::EXPORT_SIZE, 'brand_id desc');
+                $this->createExcel($data);
+            }
+        } else {    //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $brand_model->getBrandList($condition, '*', $limit2, 'brand_id desc');
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array(
+            'id' => 's_title', 'Font' => array('FontName' => lang('ds_song_typeface'), 'Size' => '12', 'Bold' => '1')
+        ));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_brandid'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_brand'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_brand_cate'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_brand_img'));
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['brand_id']);
+            $tmp[] = array('data' => $v['brand_name']);
+            $tmp[] = array('data' => $v['brand_class']);
+            $tmp[] = array('data' => $v['brand_pic']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_brand'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_brand'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string) url('Brand/index'),
+            ),
+            array(
+                'name' => 'brand_add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Brand/brand_add') . "','" . lang('ds_add') . "')"
+            ),
+            array(
+                'name' => 'brand_apply',
+                'text' => lang('brand_index_to_audit'),
+                'url' => (string) url('Brand/brand_apply')
+            )
+        );
+        return $menu_array;
+    }
+
+}

+ 158 - 0
app/admin/controller/Chain.php

@@ -0,0 +1,158 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Chain extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/chain.lang.php');
+    }
+
+    /**
+     * 门店列表
+     */
+    public function index()
+    {
+        $chain_model = model('chain');
+        $where = array();
+        if (input('param.search_name') != '') {
+            $where[]=array('chain_truename','like', '%' . input('param.search_name') . '%');
+            View::assign('search_name', input('param.search_name'));
+        }
+        if (input('param.sign') == 'verify') {
+            View::assign('sign', 'verify');
+            $dp_list = $chain_model->getChainWaitVerifyList($where, 10);
+            $this->setAdminCurItem('verify');
+        }
+        else {
+            $dp_list = $chain_model->getChainList($where, 10);
+            $this->setAdminCurItem('index');
+        }
+        View::assign('show_page', $chain_model->page_info->render());
+        View::assign('dp_list', $dp_list);
+
+        View::assign('chain_state', $chain_model->getChainState());
+        return View::fetch();
+    }
+
+    /**
+     * 门店设置
+     */
+    public function setting()
+    {
+        if (!request()->isPost()) {
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            return View::fetch();
+        } else {
+            $update_array = array();
+            $update_array['chain_isuse'] = intval(input('post.chain_isuse'));
+            $result = model('config')->editConfig($update_array);
+            $log = lang('ds_open');
+            if ($result === true) {
+                if ($update_array['chain_isuse'] == 0) {
+                    $log = lang('ds_close');
+                    // 删除相关联的收货地址
+                    model('address')->delAddress(array(array('chain_id','<>', 0)));
+                }
+                $this->log($log . lang('chain_function'), 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->log($log . lang('chain_function'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑门店信息
+     */
+    public function edit_chain()
+    {
+        $chain_id = intval(input('param.d_id'));
+        if ($chain_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $chain_info = model('chain')->getChainInfo(array('chain_id' => $chain_id));
+        if (empty($chain_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('chain_info', $chain_info);
+        $this->setAdminCurItem('edit_chain');
+        return View::fetch();
+    }
+
+    /**
+     * 编辑保存
+     */
+    public function save_edit()
+    {
+        $chain_id = intval(input('param.did'));
+        if (!request()->isPost() || $chain_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $where = array('chain_id' => $chain_id);
+        $update = array();
+        $update['chain_mobile'] = input('post.dmobile');
+        $update['chain_telephony'] = input('post.dtelephony');
+        $update['chain_addressname'] = input('post.daddressname');
+        $update['chain_address'] = input('post.daddress');
+        
+        $chain_passwd = input('post.dpasswd');
+        if (!empty($chain_passwd)) {
+            $update['chain_passwd'] = md5($chain_passwd);
+        }
+        $update['chain_state'] = intval(input('post.dstate'));
+        $update['chain_failreason'] = input('post.fail_reason');
+        $result = model('chain')->editChain($update, $where);
+        if ($result) {
+            // 删除相关联的收货地址
+            model('address')->delAddress(array('chain_id' => $chain_id));
+            $this->log(lang('ds_edit').lang('chain_function').',ID:' . $chain_id, 1);
+            $this->success(lang('ds_common_op_succ'), (string)url('Chain/index'));
+        }
+        else {
+            $this->log(lang('ds_edit').lang('chain_function').',ID:' . $chain_id, 0);
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Chain/index')
+            )/*, array(
+                'name' => 'verify',
+                'text' => lang('chain_verify'),
+                'url' => (string)url('Chain/index',['sign'=>'verify'])
+            ), array(
+                'name' => 'setting', 
+                'text' => lang('ds_set'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Chain/setting')."','".lang('ds_set')."')"
+            ),*/
+        );
+        if (request()->action() == 'edit_chain') {
+            $menu_array[] = array('name' => 'edit_chain', 'text' => lang('ds_edit'), 'url' => (string)url('Chain/edit_chain'));
+        }
+        return $menu_array;
+    }
+}

+ 65 - 0
app/admin/controller/Common.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace app\admin\controller;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Common extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 查询每月的周数组
+     */
+    public function getweekofmonth() {
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $year = input('param.y');
+        $month = input('param.m');
+        $week_arr = getMonthWeekArr($year, $month);
+        echo json_encode($week_arr);
+        die;
+    }
+
+    public function ajax_get_brand() {
+        $initial = trim(input('param.letter'));
+        $keyword = trim(input('param.keyword'));
+        $type = trim(input('param.type'));
+        if (!in_array($type, array('letter', 'keyword')) || ($type == 'letter' && empty($initial)) || ($type == 'keyword' && empty($keyword))) {
+            echo json_encode(array());
+            die();
+        }
+
+        // 实例化模型
+        $where = array();
+        // 验证类型是否关联品牌
+        if ($type == 'letter') {
+            switch ($initial) {
+                case 'all':
+                    break;
+                case '0-9':
+                    $where[]=array('brand_initial','in', array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
+                    break;
+                default:
+                    $where[]=array('brand_initial','=',$initial);
+                    break;
+            }
+        } else {
+            $where[]=array('brand_name|brand_initial','like', '%' . $keyword . '%');
+        }
+        $brand_array = model('brand')->getBrandPassedList($where, 'brand_id,brand_name,brand_initial', 0, 'brand_initial asc, brand_sort asc');
+        echo json_encode($brand_array);
+        die();
+    }
+
+}

+ 660 - 0
app/admin/controller/Complain.php

@@ -0,0 +1,660 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Complain extends AdminControl
+{
+    //定义投诉状态常量
+    const STATE_NEW = 10;
+    const STATE_APPEAL = 20;
+    const STATE_TALK = 30;
+    const STATE_HANDLE = 40;
+    const STATE_FINISH = 99;
+    const STATE_ACTIVE = 2;
+    const STATE_UNACTIVE = 1;
+
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/complain.lang.php');
+    }
+
+
+    /*
+     * 未处理的投诉列表
+     */
+    public function complain_new_list()
+    {
+        $this->get_complain_list(self::STATE_NEW, 'complain_new_list');
+        return View::fetch('complain_list');
+    }
+
+    /*
+     * 待申诉的投诉列表
+     */
+    public function complain_appeal_list()
+    {
+        $this->get_complain_list(self::STATE_APPEAL, 'complain_appeal_list');
+        return View::fetch('complain_list');
+    }
+
+    /*
+     * 对话的投诉列表
+     */
+    public function complain_talk_list()
+    {
+        $this->get_complain_list(self::STATE_TALK, 'complain_talk_list');
+        return View::fetch('complain_list');
+    }
+
+    /*
+     * 待仲裁的投诉列表
+     */
+    public function complain_handle_list()
+    {
+        $this->get_complain_list(self::STATE_HANDLE, 'complain_handle_list');
+        return View::fetch('complain_list');
+    }
+
+    /*
+     * 已关闭的投诉列表
+     */
+    public function complain_finish_list()
+    {
+        $this->get_complain_list(self::STATE_FINISH, 'complain_finish_list');
+        return View::fetch('complain_list');
+    }
+
+    /*
+     * 获取投诉列表
+     */
+    private function get_complain_list($complain_state, $action)
+    {
+        $complain_model = model('complain');
+        //搜索条件
+        $condition = array();
+        $condition[]=array('accuser_name','like', "%" . input('param.input_complain_accuser') . "%");
+        $condition[]=array('accused_name','like', "%" . input('param.input_complain_accused') . "%");
+        $condition[]=array('complain_subject_content','like', "%" . input('param.input_complain_subject_content') . "%");
+        if(input('param.input_complain_datetime_end')) {
+            $stime = strtotime(input('param.input_complain_datetime_start'));
+            $condition[]=array('complain_datetime','>=', $stime);
+        }
+        if(input('param.input_complain_datetime_end')){
+            $etime = strtotime(input('param.input_complain_datetime_end'))+86399;
+            $condition[]=array('complain_datetime','<=', $etime);
+        }
+        if ($action === 'complain_finish_list') {
+            $order= 'complain_id desc';
+        } else {
+            $order = 'complain_id asc';
+        }
+        $condition[]=array('complain_state','=',$complain_state);
+        $complain_list = $complain_model->getComplainList($condition, 10 ,$order);
+        $this->setAdminCurItem($action);
+        View::assign('complain_list', $complain_list);
+        View::assign('show_page', $complain_model->page_info->render());
+    }
+
+    /*
+     * 进行中的投诉
+     */
+    public function complain_progress()
+    {
+        $complain_id = intval(input('param.complain_id'));
+        //获取投诉详细信息
+        $complain_info = $this->get_complain_info($complain_id);
+        //获取订单详细信息
+        $order_info = $this->get_order_info($complain_info['order_id']);
+        //获取投诉的商品列表
+        $complain_goods_list = $this->get_complain_goods_list($complain_info['order_goods_id']);
+        View::assign('complain_goods_list', $complain_goods_list);
+        if (intval($complain_info['complain_subject_id']) == 1) {//退款信息
+            $refundreturn_model = model('refundreturn');
+            $this->getRefundStateArray();//向模板页面输出退款退货状态
+            $list = $refundreturn_model->getComplainRefundList($order_info, $complain_info['order_goods_id']);
+            View::assign('refund_list', $list['refund']);//已退或处理中商品
+            View::assign('refund_goods', $list['goods']);//可退商品
+        }
+        $this->setAdminCurItem('complain_progress');
+        View::assign('order_info', $order_info);
+        View::assign('complain_info', $complain_info);
+        return View::fetch('complain_info');
+    }
+
+    function getRefundStateArray($type = 'all') {
+        $state_array = array(
+            '1' => lang('refund_state_confirm'),
+            '2' => lang('refund_state_yes'),
+            '3' => lang('refund_state_no')
+        ); //卖家处理状态:1为待审核,2为同意,3为不同意
+        View::assign('state_array', $state_array);
+
+        $admin_array = array(
+            '1' => lang('ds_processing'),
+            '2' => lang('ds_processed'),
+            '3' => lang('order_state_success')
+        ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
+        View::assign('admin_array', $admin_array);
+
+        $state_data = array(
+            'seller' => $state_array,
+            'admin' => $admin_array
+        );
+        if ($type == 'all') {
+            return $state_data; //返回所有
+        }
+        return $state_data[$type];
+    }
+    /*
+     * 审核提交的投诉
+     */
+    public function complain_verify()
+    {
+        $complain_id = intval(input('post.complain_id'));
+        $complain_info = $this->get_complain_info($complain_id);
+        if (intval($complain_info['complain_state']) === self::STATE_NEW) {
+            $complain_model = model('complain');
+            $update_array = array();
+            $update_array['complain_state'] = self::STATE_APPEAL;
+            $update_array['complain_handle_datetime'] = TIMESTAMP;
+            $update_array['complain_handle_member_id'] = $this->get_admin_id();
+            $update_array['complain_active'] = self::STATE_ACTIVE;
+            $condition = array();
+            $condition[] = array('complain_id','=',$complain_id);
+            if ($complain_model->editComplain($update_array, $condition)) {
+                $this->log(lang('complain_verify_success') . '[' . $complain_id . ']', 1);
+
+                // 发送商家消息
+                $param = array();
+                $param['code'] = 'complain';
+                $param['store_id'] = $complain_info['accused_id'];
+                $param['ali_param'] = array(
+                    'complain_id' => $complain_id
+                );
+                $param['ten_param'] = array(
+                    $complain_id
+                );
+                $param['param'] = $param['ali_param'];
+                //微信模板消息
+                $param['weixin_param'] = array(
+                    'url' => config('ds_config.h5_site_url').'/seller/complaint_form?complain_id='.$complain_id,
+                    'data'=>array(
+                        "keyword1" => array(
+                            "value" => $complain_info['accuser_name'],
+                            "color" => "#333"
+                        ),
+                        "keyword2" => array(
+                            "value" => $complain_info['complain_subject_content'],
+                            "color" => "#333"
+                        )
+                    ),
+                );
+                model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize($param)));
+
+                $this->success(lang('complain_verify_success'), (string)url('Complain/complain_new_list'));
+            } else {
+                $this->error(lang('complain_verify_fail'), (string)url('Complain/complain_new_list'));
+            }
+        } else {
+            $this->error(lang('param_error'), '');
+        }
+    }
+
+    /*
+     * 关闭投诉
+     */
+    public function complain_close()
+    {
+        //获取输入的数据
+        $complain_id = intval(input('post.complain_id'));
+        $final_handle_message = trim(input('post.final_handle_message'));
+        $data=[
+            'final_handle_message'=>$final_handle_message
+        ];
+        $complain_validate = ds_validate('complain');
+        if (!$complain_validate->scene('complain_close')->check($data)) {
+            $this->error($complain_validate->getError());
+        }
+
+        $complain_info = $this->get_complain_info($complain_id);
+        $current_state = intval($complain_info['complain_state']);
+        if ($current_state !== self::STATE_FINISH) {
+            $complain_model = model('complain');
+            $update_array = array();
+            $update_array['complain_state'] = self::STATE_FINISH;
+            $update_array['final_handle_message'] = $final_handle_message;
+            $update_array['final_handle_datetime'] = TIMESTAMP;
+            $update_array['final_handle_member_id'] = $this->get_admin_id();
+            $condition = array();
+            $condition[] = array('complain_id','=',$complain_id);
+            if ($complain_model->editComplain($update_array, $condition)) {
+                if (intval($complain_info['complain_subject_id']) == 1) {//退款信息
+                    $order = $this->get_order_info($complain_info['order_id']);
+                    $refundreturn_model = model('refundreturn');
+                    $list = $refundreturn_model->getComplainRefundList($order, $complain_info['order_goods_id']);
+                    $refund_goods = $list['goods'];//可退商品
+                    if (!empty($refund_goods) && is_array($refund_goods)) {
+                        $checked_goods = input('post.checked_goods/a');#获取数组
+                        foreach ($refund_goods as $key => $value) {
+                            $goods_id = $value['rec_id'];//订单商品表编号
+                            if (!empty($checked_goods) && array_key_exists($goods_id, $checked_goods)) {//验证提交的商品属于订单
+                                $refund_array = array();
+                                $refund_array['refund_type'] = '1';//类型:1为退款,2为退货
+                                $refund_array['seller_state'] = '2';//卖家处理状态:1为待审核,2为同意,3为不同意
+                                $refund_array['refund_state'] = '2';//状态:1为处理中,2为待管理员处理,3为已完成
+                                $refund_array['order_lock'] = '1';//锁定类型:1为不用锁定,2为需要锁定
+                                $refund_array['refund_amount'] = ds_price_format($value['goods_refund']);
+                                $refund_array['reason_id'] = '0';
+                                $refund_array['reason_info'] = lang('complaints_success');
+                                $refund_array['buyer_message'] = lang('complaints_success_confirm');
+                                $refund_array['seller_message'] = lang('complaints_success_confirm');
+                                $refund_array['add_time'] = TIMESTAMP;
+                                $refund_array['seller_time'] = TIMESTAMP;
+                                $refundreturn_model->addRefundreturn($refund_array, $order, $value);
+                            }
+                        }
+                    }
+                }
+                $this->log(lang('complain_close_success') . '[' . $complain_id . ']', 1);
+                $this->success(lang('complain_close_success'), $this->get_complain_state_link($current_state));
+            } else {
+                $this->error(lang('complain_close_fail'), $this->get_complain_state_link($current_state));
+            }
+        } else {
+            $this->error(lang('param_error'), '');
+        }
+    }
+
+    /*
+     * 投诉主题列表
+     */
+    public function complain_subject_list()
+    {
+        /*
+         * 获得举报主题列表
+         */
+        $complainsubject_model = model('complainsubject');
+        //搜索条件
+        $condition = array();
+        $condition[] = array('complainsubject_state','=',1);
+        $complainsubject_list = $complainsubject_model->getComplainsubject($condition, 10);
+        $this->setAdminCurItem('complain_subject_list');
+        View::assign('complainsubject_list', $complainsubject_list);
+        View::assign('show_page', $complainsubject_model->page_info->render());
+        return View::fetch('complain_subject_list');
+    }
+
+    /*
+     * 添加投诉主题页面
+     */
+    public function complain_subject_add() {
+        if (!request()->isPost()) {
+            $this->setAdminCurItem('complain_subject_add');
+            return View::fetch();
+        } else {
+
+            //获取提交的内容
+            $input['complainsubject_content'] = trim(input('post.complain_subject_content'));
+            $input['complainsubject_desc'] = trim(input('post.complain_subject_desc'));
+            //验证提交的内容
+            $data = [
+                'complain_subject_content' => $input['complainsubject_content'],
+                'complain_subject_desc' => $input['complainsubject_desc'],
+            ];
+
+            $complain_validate = ds_validate('complain');
+            if (!$complain_validate->scene('complain_subject_add')->check($data)) {
+                $this->error($complain_validate->getError());
+            } else {
+                //验证成功保存
+                $input['complainsubject_state'] = 1;
+                $complainsubject_model = model('complainsubject');
+                $complainsubject_model->addComplainsubject($input);
+                $this->log(lang('complain_subject_add_success') . '[' . input('complain_subject_content') . ']', 1);
+                $this->success(lang('complain_subject_add_success'), 'complain/complain_subject_list');
+            }
+        }
+    }
+
+
+    /*
+     * 删除投诉主题,伪删除只是修改标记
+     */
+    public function complain_subject_drop()
+    {
+        $complain_subject_id = input('param.complain_subject_id');
+        $complain_subject_id_array = ds_delete_param($complain_subject_id);
+        if ($complain_subject_id_array == FALSE) {
+            $this->error(lang('param_error'));
+        }
+        $condition = array();
+        $condition[]=array('complainsubject_id','in',$complain_subject_id_array);
+        
+        $complainsubject_model = model('complainsubject');
+        $update_array = array();
+        $update_array['complainsubject_state'] = 2;
+        
+        if ($complainsubject_model->editComplainsubject($update_array, $condition)) {
+            $this->log(lang('complain_subject_delete_success') . '[ID:' . input('post.complain_subject_id') . ']', 1);
+            ds_json_encode(10000, lang('complain_subject_delete_success'));
+        } else {
+            ds_json_encode(10001, lang('complain_subject_delete_fail'));
+        }
+    }
+
+    /*
+     * 根据投诉id获取投诉对话列表
+     */
+    public function get_complain_talk()
+    {
+        $complain_id = intval(input('param.complain_id'));
+        $complain_info = $this->get_complain_info($complain_id);
+        $complain_talk_list = $this->get_talk_list($complain_id);
+        $talk_list = array();
+        $i = 0;
+        foreach ($complain_talk_list as $talk) {
+            $talk_list[$i]['css'] = $talk['talk_member_type'];
+            $talk_list[$i]['talk'] = date("Y-m-d", $talk['talk_datetime']);
+            switch ($talk['talk_member_type']) {
+                case 'accuser':
+                    $talk_list[$i]['talk'] .= lang('complain_accuser');
+                    break;
+                case 'accused':
+                    $talk_list[$i]['talk'] .= lang('complain_accused');
+                    break;
+                case 'admin':
+                    $talk_list[$i]['talk'] .= lang('complain_admin');
+                    break;
+                default:
+                    $talk_list[$i]['talk'] .= lang('complain_unknow');
+            }
+            if (intval($talk['talk_state']) === 2) {
+                $talk['talk_content'] = lang('talk_forbit_message');
+                $forbit_link = '';
+            } else {
+                $forbit_link = "&nbsp;&nbsp;<a href='#' onclick=forbit_talk(" . $talk['talk_id'] . ")>" . lang('complain_text_forbit') . "</a>";
+            }
+            $talk_list[$i]['talk'] .= '(' . $talk['talk_member_name'] . ')' . lang('complain_text_say') . ':' . $talk['talk_content'] . $forbit_link;
+            $i++;
+        }
+
+        echo json_encode($talk_list);
+    }
+
+    /*
+     * 发布投诉对话
+     */
+    public function publish_complain_talk()
+    {
+        $complain_id = intval(input('param.complain_id'));
+        $complain_talk = trim(input('param.complain_talk'));
+        $talk_len = strlen($complain_talk);
+        if ($talk_len > 0 && $talk_len < 255) {
+            $complain_info = $this->get_complain_info($complain_id);
+            $complaintalk_model = model('complaintalk');
+            $param = array();
+            $param['complain_id'] = $complain_id;
+            $param['talk_member_id'] = $this->get_admin_id();
+            $param['talk_member_name'] = $this->get_admin_name();
+            $param['talk_member_type'] = 'admin';
+
+            $param['talk_content'] = $complain_talk;
+            $param['talk_state'] = 1;
+            $param['talk_admin'] = 0;
+            $param['talk_datetime'] = TIMESTAMP;
+            if ($complaintalk_model->addComplaintalk($param)) {
+                echo json_encode('success');
+            } else {
+                echo json_encode('error2');
+            }
+        } else {
+            echo json_encode('error1');
+        }
+    }
+
+    /*
+     * 屏蔽对话
+     */
+    public function forbit_talk()
+    {
+        $talk_id = intval(input('post.talk_id'));
+        if (!empty($talk_id) && is_integer($talk_id)) {
+            $complaintalk_model = model('complaintalk');
+            $update_array = array();
+            $update_array['talk_state'] = 2;
+            $update_array['talk_admin'] = $this->get_admin_id();
+            $condition = array();
+            $condition[] = array('talk_id','=',$talk_id);
+            if ($complaintalk_model->editComplaintalk($update_array, $condition)) {
+                echo json_encode('success');
+            } else {
+                echo json_encode('error2');
+            }
+        } else {
+            echo json_encode('error1');
+        }
+    }
+
+    /**
+     * 投诉设置
+     **/
+   public function complain_setting() {
+        if (!request()->isPost()) {
+            //读取设置内容 $list_setting
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('complain_setting');
+            return View::fetch('complain_setting');
+        } else {
+
+            $setting_model = model('config');
+            $complain_time_limit = intval(input('post.complain_time_limit'));
+            if (empty($complain_time_limit)) {
+                //如果输入不合法默认30天
+                $complain_time_limit = 2592000;
+            } else {
+                $complain_time_limit = $complain_time_limit * 86400;
+            }
+            $update_array['complain_time_limit'] = $complain_time_limit;
+            if ($setting_model->editConfig($update_array)) {
+                $this->log(lang('complain_setting_save_success'), 1);
+                $this->success(lang('complain_setting_save_success'));
+            } else {
+                $this->error(lang('complain_setting_save_fail'));
+            }
+        }
+    }
+
+
+    /*
+     * 获取订单信息
+     */
+    private function get_order_info($order_id)
+    {
+        $order_model = model('order');
+        $order_info = $order_model->getOrderInfo(array('order_id' => $order_id), array('order_goods'));
+        if (empty($order_info)) {
+            $this->error(lang('param_error'));
+        }
+        $order_info['order_state_text'] = get_order_state($order_info);
+        return $order_info;
+    }
+
+    /*
+     * 获取投诉信息
+     */
+    private function get_complain_info($complain_id)
+    {
+        $complain_model = model('complain');
+        $complain_info = $complain_model->getOneComplain($complain_id);
+        if (empty($complain_info)) {
+            $this->error(lang('param_error'));
+        }
+        $complain_info['complain_state_text'] = $this->get_complain_state_text($complain_info['complain_state']);
+        return $complain_info;
+    }
+
+    /*
+     * 获取投诉商品列表
+     */
+    private function get_complain_goods_list($order_goods_id)
+    {
+        $order_model = model('order');
+        $param = array();
+        $param['rec_id'] = $order_goods_id;
+        $complain_goods_list = $order_model->getOrdergoodsList($param);
+        return $complain_goods_list;
+    }
+
+    /*
+     * 获取对话列表
+     */
+    private function get_talk_list($complain_id)
+    {
+        $complaintalk_model = model('complaintalk');
+        $param = array();
+        $param['complain_id'] = $complain_id;
+        $talk_list = $complaintalk_model->getComplaintalkList($param);
+        return $talk_list;
+    }
+
+    /*
+     * 获得投诉状态文本
+     */
+    private function get_complain_state_text($complain_state)
+    {
+        switch (intval($complain_state)) {
+            case self::STATE_NEW:
+                return lang('complain_state_new');
+                break;
+            case self::STATE_APPEAL:
+                return lang('complain_state_appeal');
+                break;
+            case self::STATE_TALK:
+                return lang('complain_state_talk');
+                break;
+            case self::STATE_HANDLE:
+                return lang('complain_state_handle');
+                break;
+            case self::STATE_FINISH:
+                return lang('complain_state_finish');
+                break;
+            default:
+                $this->error(lang('param_error'), '');
+        }
+    }
+
+    /*
+     * 获得投诉状态文本
+     */
+    private function get_complain_state_link($complain_state)
+    {
+        switch (intval($complain_state)) {
+            case self::STATE_NEW:
+                return 'complain/complain_new_list';
+                break;
+            case self::STATE_APPEAL:
+                return 'complain/complain_appeal_list';
+                break;
+            case self::STATE_TALK:
+                return 'complain/complain_talk_list';
+                break;
+            case self::STATE_HANDLE:
+                return 'complain/complain_handle_list';
+                break;
+            case self::STATE_FINISH:
+                return 'complain/complain_finish_list';
+                break;
+            default:
+                $this->error(lang('param_error'));
+        }
+    }
+
+    /*
+     * 获得管理员id
+     */
+    private function get_admin_id()
+    {
+        $admin_info = $this->getAdminInfo();
+        return $admin_info['admin_id'];
+    }
+
+    /*
+     * 获得管理员name
+     */
+    private function get_admin_name()
+    {
+        $admin_info = $this->getAdminInfo();
+        return $admin_info['admin_name'];
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'complain_new_list',
+                'text' => lang('complain_new_list'),
+                'url' => (string)url('complain/complain_new_list')
+            ),
+            array(
+                'name' => 'complain_appeal_list',
+                'text' => lang('complain_appeal_list'),
+                'url' => (string)url('Complain/complain_appeal_list')
+            ),
+            array(
+                'name' => 'complain_talk_list',
+                'text' => lang('complain_talk_list'),
+                'url' => (string)url('Complain/complain_talk_list')
+            ),
+            array(
+                'name' => 'complain_handle_list',
+                'text' => lang('complain_handle_list'),
+                'url' => (string)url('Complain/complain_handle_list')
+            ),
+            array(
+                'name' => 'complain_finish_list',
+                'text' => lang('complain_finish_list'),
+                'url' => (string)url('Complain/complain_finish_list')
+            ),
+            array(
+                'name' => 'complain_subject_list',
+                'text' => lang('complain_subject_list'),
+                'url' => (string)url('Complain/complain_subject_list')
+            ),
+            array(
+                'name' => 'complain_subject_add',
+                'text' => lang('complain_subject_add'),
+                'url' => (string)url('Complain/complain_subject_add')
+            ),
+            array(
+                'name' => 'complain_setting',
+                'text' => lang('complain_setting'),
+                'url' => (string)url('Complain/complain_setting')
+            )
+        );
+
+        if (request()->action() == 'complain_progress') {
+            $menu_array[] = array(
+                'name' => 'complain_progress',
+                'text' => lang('complain_progress'),
+                'url' => '###'
+            );
+        }
+        return $menu_array;
+    }
+}

+ 348 - 0
app/admin/controller/Config.php

@@ -0,0 +1,348 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Config extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/config.lang.php');
+    }
+
+    public function base() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('base');
+            return View::fetch();
+        } else {
+			$update_array = array();
+            //首页首次访问悬浮图片
+            if (!empty($_FILES['fixed_suspension_img']['name'])) {
+                $res=ds_upload_pic(ATTACH_COMMON,'fixed_suspension_img', 'fixed_suspension_img.png');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $upload['fixed_suspension_img'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+            if (!empty($upload['fixed_suspension_img'])) {
+                $update_array['fixed_suspension_img'] = $upload['fixed_suspension_img'];
+            }
+			$update_array['goods_verify'] = intval(input('post.goods_verify')) ;//店铺商品审核
+			$update_array['goods_all_verify'] = intval(input('post.goods_all_verify')) ;//店铺所有商品是否通过审核
+            $update_array['baidu_ak'] = input('post.baidu_ak');
+			$update_array['baiduservice_ak'] = input('post.baiduservice_ak');
+			$update_array['mapak_type'] = input('post.mapak_type');
+			$update_array['gaode_ak'] = input('post.gaode_ak');
+			$update_array['gaode_jscode'] = input('post.gaode_jscode');
+            $update_array['site_name'] = input('post.site_name');
+            $update_array['icp_number'] = input('post.icp_number');
+            $update_array['wab_number'] = input('post.wab_number');
+            $update_array['site_phone'] = input('post.site_phone');
+            $update_array['site_tel400'] = input('post.site_tel400');
+            $update_array['site_email'] = input('post.site_email');
+            $update_array['flow_static_code'] = input('post.flow_static_code');
+            $update_array['site_state'] = intval(input('post.site_state'));
+            $update_array['cache_open'] = intval(input('post.cache_open'));
+            $update_array['closed_reason'] = input('post.closed_reason');
+            $update_array['hot_search'] = input('post.hot_search');
+            $update_array['h5_site_url'] = input('post.h5_site_url');
+            $update_array['h5_force_redirect'] = input('post.h5_force_redirect');
+            $update_array['fixed_suspension_state'] = input('post.fixed_suspension_state'); //首页首次访问悬浮状态
+            $update_array['fixed_suspension_url'] = input('post.fixed_suspension_url');
+			$update_array['member_auth'] = input('post.member_auth');//会员实名认证
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+				if($update_array['goods_verify']==0 && $update_array['goods_all_verify']==1){
+				    $goods_model = model('goods');
+				    $update = array();
+				    $update['goods_verify'] = 1;
+				
+				    $where = array();
+				    $where[]=array('goods_commonid','>', 0);
+				    $goods_model->editProduces($where, $update);
+				}
+                $this->log(lang('ds_edit') . lang('web_set'), 1);
+                $this->success(lang('ds_common_save_succ'), 'Config/base');
+            } else {
+                $this->log(lang('ds_edit') . lang('web_set'), 0);
+            }
+        }
+    }
+
+	public function logo() {
+		$config_model = model('config');
+		if (!request()->isPost()) {
+		    $list_config = rkcache('config', true);
+		    View::assign('list_config', $list_config);
+		    /* 设置卖家当前栏目 */
+		    $this->setAdminCurItem('logo');
+		    return View::fetch();
+		} else {
+			//上传文件保存路径
+			if (!empty($_FILES['site_logo']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'site_logo', 'site_logo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['site_logo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['site_logo'])) {
+			    $update_array['site_logo'] = $upload['site_logo'];
+			}
+			if (!empty($_FILES['member_logo']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'member_logo', 'member_logo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['member_logo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['member_logo'])) {
+			    $update_array['member_logo'] = $upload['member_logo'];
+			}
+			if (!empty($_FILES['seller_center_logo']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'seller_center_logo', 'seller_center_logo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['seller_center_logo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['seller_center_logo'])) {
+			    $update_array['seller_center_logo'] = $upload['seller_center_logo'];
+			}
+			if (!empty($_FILES['admin_backlogo']['name'])) {
+			    $res=ds_upload_pic('admin/common','admin_backlogo', 'backlogo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['admin_backlogo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['admin_backlogo'])) {
+			    $update_array['admin_backlogo'] = $upload['admin_backlogo'];
+			}
+			
+			if (!empty($_FILES['admin_logo']['name'])) {
+			    $res=ds_upload_pic('admin/common','admin_logo', 'logo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['admin_logo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['admin_logo'])) {
+			    $update_array['admin_logo'] = $upload['admin_logo'];
+			}
+			
+			
+			if (!empty($_FILES['site_mobile_logo']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'site_mobile_logo', 'site_mobile_logo.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['site_mobile_logo'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['site_mobile_logo'])) {
+			    $update_array['site_mobile_logo'] = $upload['site_mobile_logo'];
+			}
+			
+			if (!empty($_FILES['site_logowx']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'site_logowx', 'site_logowx.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['site_logowx'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['site_logowx'])) {
+			    $update_array['site_logowx'] = $upload['site_logowx'];
+			}
+			if (!empty($_FILES['business_licence']['name'])) {
+			    $res=ds_upload_pic(ATTACH_COMMON,'business_licence', 'business_licence.png');
+			    if($res['code']){
+			        $file_name=$res['data']['file_name'];
+			        $upload['business_licence'] = $file_name;
+			    }else{
+			        $this->error($res['msg']);
+			    }
+			}
+			if (!empty($upload['business_licence'])) {
+			    $update_array['business_licence'] = $upload['business_licence'];
+			}
+			$result = $config_model->editConfig($update_array);
+			if ($result) {
+			    $this->log(lang('ds_edit') . lang('web_set'), 1);
+			    $this->success(lang('ds_common_save_succ'), 'Config/logo');
+			} else {
+			    $this->log(lang('ds_edit') . lang('web_set'), 0);
+			}
+		}
+	}
+
+    /**
+     * 敏感词过滤设置
+     */
+    public function word_filter() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('word_filter');
+            return View::fetch();
+        } else {
+            $update_array = array();
+            $update_array['word_filter_open'] = intval(input('post.word_filter_open'));
+            $update_array['word_filter_appid'] = trim(input('post.word_filter_appid'));
+            $update_array['word_filter_secret'] = trim(input('post.word_filter_secret'));
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('word_filter_set'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('word_filter_set'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+    /**
+     * 防灌水设置
+     */
+    public function dump() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('dump');
+            return View::fetch();
+        } else {
+            $update_array = array();
+            $update_array['guest_comment'] = intval(input('post.guest_comment'));
+            $update_array['captcha_status_login'] = intval(input('post.captcha_status_login'));
+            $update_array['captcha_status_register'] = intval(input('post.captcha_status_register'));
+            $update_array['captcha_status_goodsqa'] = intval(input('post.captcha_status_goodsqa'));
+            $update_array['captcha_status_storelogin'] = intval(input('post.captcha_status_storelogin'));
+            $update_array['member_normal_register'] = intval(input('post.member_normal_register'));
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('dis_dump'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('dis_dump'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+ 
+
+    /*
+     * 设置自动收货时间
+     */
+
+    public function auto() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('auto');
+            return View::fetch();
+        } else {
+            $order_auto_receive_day = intval(input('post.order_auto_receive_day'));
+            $order_auto_cancel_day = intval(input('post.order_auto_cancel_day'));
+            $code_invalid_refund = intval(input('post.code_invalid_refund'));
+            $store_bill_cycle = intval(input('post.store_bill_cycle'));
+            if ($order_auto_receive_day < 1 || $order_auto_receive_day > 100) {
+                $this->error(lang('automatic_confirmation_receipt') . '1-100' . lang('numerical'));
+            }
+            if ($order_auto_cancel_day < 1 || $order_auto_cancel_day > 50) {
+                $this->error(lang('automatic_confirmation_receipt') . '1-50' . lang('numerical'));
+            }
+            if ($code_invalid_refund < 1 || $code_invalid_refund > 100) {
+                $this->error(lang('exchange_code_refunded_automatically') . '1-100' . lang('numerical'));
+            }
+            if ($store_bill_cycle < 7) {
+                $this->error(lang('store_bill_cycle_error'));
+            }
+            $update_array['order_auto_receive_day'] = $order_auto_receive_day;
+            $update_array['order_auto_cancel_day'] = $order_auto_cancel_day;
+            $update_array['code_invalid_refund'] = $code_invalid_refund;
+            $update_array['store_bill_cycle'] = $store_bill_cycle;
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log(lang('ds_edit') . lang('auto_set'), 1);
+                $this->success(lang('ds_common_save_succ'), 'Config/auto');
+            } else {
+                $this->log(lang('ds_edit') . lang('auto_set'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'base',
+                'text' => lang('ds_base'),
+                'url' => (string) url('Config/base')
+            ),
+			array(
+			    'name' => 'logo',
+			    'text' => lang('ds_logo'),
+			    'url' => (string) url('Config/logo')
+			),
+            array(
+                'name' => 'dump',
+                'text' => lang('dis_dump'),
+                'url' => (string) url('Config/dump')
+            ),
+            array(
+                'name' => 'word_filter',
+                'text' => lang('word_filter_set'),
+                'url' => (string) url('Config/word_filter')
+            ),
+            array(
+                'name' => 'auto',
+                'text' => lang('automatic_execution_time_setting'),
+                'url' => (string) url('Config/auto')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 224 - 0
app/admin/controller/Consulting.php

@@ -0,0 +1,224 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Consulting extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/consulting.lang.php');
+    }
+
+    /**
+     * 咨询管理
+     */
+    public function consulting() {
+        $condition = array();
+        $member_name = trim(input('param.member_name'));
+        if ($member_name != '') {
+            $condition[]=array('member_name','like', '%' . $member_name . '%');
+            View::assign('member_name', $member_name);
+        }
+        $consult_content = trim(input('param.consult_content'));
+        if ($consult_content != '') {
+            $condition[]=array('consult_content','like', '%' . $consult_content . '%');
+            View::assign('consult_content', $consult_content);
+        }
+        $ctid = intval(input('param.ctid'));
+        if ($ctid > 0) {
+            $condition[]=array('consulttype_id','=',$ctid);
+            View::assign('ctid', $ctid);
+        }
+        $consult_model = model('consult');
+        $consult_list = $consult_model->getConsultList($condition, '*');
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        View::assign('show_page', $consult_model->page_info->render());
+        View::assign('consult_list', $consult_list);
+
+
+        // 咨询类型
+        $consult_type = rkcache('consulttype', true);
+        View::assign('consult_type', $consult_type);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function delete() {
+        $consult_id = input('param.consult_id');
+        $consult_id_array = ds_delete_param($consult_id);
+        if($consult_id_array === FALSE){
+            $this->error(lang('param_error'));
+        }
+        $condition=array();
+        $condition[] = array('consult_id','in', $consult_id_array);
+        $consult = model('consult');
+        if ($consult->delConsult($condition)) {
+            $this->log(lang('delete_consulting') . '[ID:' . $consult_id . ']', null);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+
+    /**
+     * 咨询类型列表
+     */
+    public function type_list() {
+        $consulttype_model = model('consulttype');
+        $type_list = $consulttype_model->getConsulttypeList(array(), 'consulttype_id,consulttype_name,consulttype_sort');
+        View::assign('type_list', $type_list);
+        $this->setAdminCurItem('type_list');
+        return View::fetch();
+    }
+
+    /**
+     * 新增咨询类型
+     */
+    public function type_add() {
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'consulttype_name' => input('post.consulttype_name'),
+                'consulttype_sort' => input('post.consulttype_sort'),
+            ];
+            $consulting_validate = ds_validate('consulting');
+            if (!$consulting_validate->scene('type_add')->check($data)) {
+                $this->error($consulting_validate->getError());
+            }
+
+            $insert = array();
+            $insert['consulttype_name'] = trim(input('post.consulttype_name'));
+            $insert['consulttype_sort'] = intval(input('post.consulttype_sort'));
+            $insert['consulttype_introduce'] = input('post.consulttype_introduce');
+            $result = model('consulttype')->addConsulttype($insert);
+            if ($result) {
+                $this->log(lang('add_consulttype'), 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('add_consulttype'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        $consulttype_info = array(
+            'consulttype_id' => '',
+            'consulttype_name' => '',
+            'consulttype_sort' => '',
+            'consulttype_introduce' => '',
+        );
+        View::assign('build_editor', build_editor(array(
+            'name' => 'consulttype_introduce',
+        )));
+        View::assign('consulttype_info', $consulttype_info);
+        return View::fetch('type_edit');
+    }
+
+    /**
+     * 编辑咨询类型
+     */
+    public function type_edit() {
+        $consulttype_model = model('consulttype');
+        $consulttype_id = intval(input('param.consulttype_id'));
+        if ($consulttype_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'consulttype_name' => input('post.consulttype_name'),
+                'consulttype_sort' => input('post.consulttype_sort'),
+            ];
+            $consulting_validate = ds_validate('consulting');
+            if (!$consulting_validate->scene('type_edit')->check($data)) {
+                $this->error($consulting_validate->getError());
+            }
+
+            $condition = array();
+            $condition[] = array('consulttype_id','=',$consulttype_id);
+            $update = array();
+            $update['consulttype_name'] = trim(input('post.consulttype_name'));
+            $update['consulttype_sort'] = intval(input('post.consulttype_sort'));
+            $update['consulttype_introduce'] = input('post.consulttype_introduce');
+            $result = $consulttype_model->editConsulttype($condition, $update);
+            if ($result) {
+                $this->log(lang('edit_consulttype').' ID:' . $consulttype_id, 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->log(lang('edit_consulttype').' ID:' . $consulttype_id, 0);
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }else {
+            $consulttype_info = $consulttype_model->getConsulttypeInfo(array('consulttype_id' => $consulttype_id));
+            View::assign('build_editor', build_editor(array(
+                'name' => 'consulttype_introduce',
+                'content' => htmlspecialchars_decode($consulttype_info['consulttype_introduce']),
+            )));
+            $this->setAdminCurItem('type_list');
+            View::assign('consulttype_info', $consulttype_info);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除咨询类型
+     */
+    public function type_del() {
+        $consulttype_id = input('param.consulttype_id');
+        $consulttype_id_array = ds_delete_param($consulttype_id);
+        if ($consulttype_id_array === FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition=array();
+        $condition[]=array('consulttype_id','in',$consulttype_id_array);
+        $result = model('consulttype')->delConsulttype($condition);
+        if ($result) {
+            $this->log(lang('del_consulttype').' ID:' . $consulttype_id, 1);
+            ds_json_encode('10000', lang('ds_common_op_succ'));
+        } else {
+            $this->log(lang('del_consulttype').' ID:' . $consulttype_id, 0);
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Consulting/consulting')
+            ),
+            array(
+                'name' => 'type_list',
+                'text' => lang('consulting_index_type'),
+                'url' => (string)url('Consulting/type_list')
+            ),
+            array(
+                'name' => 'type_add',
+                'text' => lang('add_consulttype'),
+                'url' =>"javascript:dsLayerOpen('".(string)url('Consulting/type_add')."','".lang('add_consulttype')."')"
+
+            )
+        );
+        return $menu_array;
+    }
+
+}

+ 715 - 0
app/admin/controller/Dashboard.php

@@ -0,0 +1,715 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Dashboard extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/dashboard.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+    }
+
+    function index() {
+        $this->welcome();
+    }
+
+    /*
+     * 检查是否为最新版本
+     */
+
+    function version() {
+        //当前版本
+        $curent_version = file_get_contents(base_path() . 'version.php');
+        //获取最新版本信息
+        $vaules = array(
+            'domain'=>$_SERVER['HTTP_HOST'], 
+            'version'=>$curent_version, 
+        );
+        $service_url = "http://service.csdeshang.com/index.php/home/Version/checkDsmall.html?".http_build_query($vaules);
+        //设置超时时间
+        $opts = array(
+            'http' =>
+            array(
+                'timeout' => 3
+            )
+        );
+        $context = stream_context_create($opts);
+        $service_info = @file_get_contents($service_url,FALSE,$context);
+        $version_message = json_decode($service_info);
+        View::assign('version_message', $version_message);
+    }
+
+    function welcome() {
+        $this->version();
+        /**
+         * 管理员信息
+         */
+        $admin_model = model('admin');
+        $tmp = $this->getAdminInfo();
+        $condition = array();
+        $condition[] = array('admin_id','=',$tmp['admin_id']);
+        $admin_info = $admin_model->infoAdmin($condition);
+        $admin_info['admin_login_time'] = date('Y-m-d H:i:s', ($admin_info['admin_login_time'] == '' ? TIMESTAMP : $admin_info['admin_login_time']));
+        /**
+         * 系统信息
+         */
+        $setup_date = config('ds_config.setup_date');
+        $statistics['tp_version'] = \think\App::VERSION;
+        $statistics['os'] = PHP_OS;
+        $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
+        $statistics['php_version'] = PHP_VERSION;
+        $statistics['sql_version'] = $this->_mysql_version();
+        //$statistics['shop_version'] = $version;
+        $statistics['setup_date'] = substr($setup_date, 0, 10);
+
+        $statistics['domain'] = $_SERVER['HTTP_HOST'];
+        $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
+        $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
+        $statistics['safe_mode'] = (boolean) ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
+        $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
+        $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
+        $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
+        $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
+        $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
+        $statistics['memory_limit'] = ini_get('memory_limit');
+        $statistics['version'] = file_get_contents(base_path() . 'version.php');
+        if (function_exists("gd_info")) {
+            $gd = gd_info();
+            $statistics['gdinfo'] = $gd['GD Version'];
+        } else {
+            $statistics['gdinfo'] = lang('ds_unknown');
+        }
+
+        View::assign('statistics', $statistics);
+        View::assign('admin_info', $admin_info);
+        $this->_stat_json();
+        $this->setAdminCurItem('welcome');
+        echo View::fetch('welcome');
+        exit;
+    }
+    private function _stat_json()
+    {
+        $this->_get_week_member();
+        $this->_get_week_goods();
+        $this->_get_week_store();
+        $this->_get_week_order();
+    }
+     /**
+     * 获取本周新增订单数量
+     */
+    private function _get_week_order()
+    {
+        $field = ' COUNT(*) as allnum ';
+        $current_weekarr = getWeek_SdateAndEdate(TIMESTAMP);
+        $stime = strtotime($current_weekarr['sdate']) - 86400 * 7;
+        $etime = strtotime($current_weekarr['edate']) + 86400 - 1;
+        //总计的查询时间
+        $count_arr['seartime'] = ($stime + 86400 * 7) . '|' . $etime;
+
+        $up_week = @date('W', $stime); //上周
+        $curr_week = @date('W', $etime); //本周
+        //构造横轴数据
+        for ($i = 1; $i <= 7; $i++) {
+            //统计图数据
+            $up_arr[$i] = 0;
+            $curr_arr[$i] = 0;
+            $tmp_weekarr = getSystemWeekArr();
+            //统计表数据
+            $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+            //方便搜索会员列表,计算开始时间和结束时间
+            $currlist_arr[$i]['stime'] = strtotime($current_weekarr['sdate']) + ($i - 1) * 86400;
+            $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+            $uplist_arr[$i]['val'] = 0;
+            $currlist_arr[$i]['val'] = 0;
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+            unset($tmp_weekarr);
+        }
+        $where = array();
+        $where[] = array('add_time','between', array($stime, $etime));
+        $field .= ',WEEKOFYEAR(FROM_UNIXTIME(add_time)) as weekval,WEEKDAY(FROM_UNIXTIME(add_time))+1 as dayofweekval ';
+        
+        $orderlist = Db::name('order')->field($field)->where($where)->group('weekval,dayofweekval')->select()->toArray();
+
+        if ($orderlist) {
+            foreach ($orderlist as $k => $v) {
+                if ($up_week == intval($v['weekval'])) {
+                    $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['up'])){
+                        $count_arr['up'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['up'] = 0;
+                    }
+                }
+                if ($curr_week == $v['weekval']) {
+                    $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['curr'])){
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['curr'] = 0;
+                    }
+                }
+            }
+        }
+
+        $stat_arr['series'][0]['name'] = lang('last_week');
+        $stat_arr['series'][0]['data'] = array_values($up_arr);
+        $stat_arr['series'][1]['name'] = lang('this_week');
+        $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+        //得到统计图数据
+        $stat_arr['title'] = lang('new_order_statistics');
+        $stat_arr['yAxis'] = lang('new_order_count');
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json_week_order', $stat_json);
+    }
+        /**
+     * 获取本周新增店铺数量
+     */
+    private function _get_week_store()
+    {
+        $field = ' COUNT(*) as allnum ';
+        $current_weekarr = getWeek_SdateAndEdate(TIMESTAMP);
+        $stime = strtotime($current_weekarr['sdate']) - 86400 * 7;
+        $etime = strtotime($current_weekarr['edate']) + 86400 - 1;
+        //总计的查询时间
+        $count_arr['seartime'] = ($stime + 86400 * 7) . '|' . $etime;
+
+        $up_week = @date('W', $stime); //上周
+        $curr_week = @date('W', $etime); //本周
+        //构造横轴数据
+        for ($i = 1; $i <= 7; $i++) {
+            //统计图数据
+            $up_arr[$i] = 0;
+            $curr_arr[$i] = 0;
+            $tmp_weekarr = getSystemWeekArr();
+            //统计表数据
+            $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+            //方便搜索会员列表,计算开始时间和结束时间
+            $currlist_arr[$i]['stime'] = strtotime($current_weekarr['sdate']) + ($i - 1) * 86400;
+            $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+            $uplist_arr[$i]['val'] = 0;
+            $currlist_arr[$i]['val'] = 0;
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+            unset($tmp_weekarr);
+        }
+        $where = array();
+        $where[] = array('store_addtime','between', array($stime, $etime));
+        $field .= ',WEEKOFYEAR(FROM_UNIXTIME(store_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(store_addtime))+1 as dayofweekval ';
+        
+        $storelist = Db::name('store')->field($field)->where($where)->group('weekval,dayofweekval')->select()->toArray();
+
+        if ($storelist) {
+            foreach ($storelist as $k => $v) {
+                if ($up_week == intval($v['weekval'])) {
+                    $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['up'])){
+                        $count_arr['up'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['up'] = 0;
+                    }
+                }
+                if ($curr_week == $v['weekval']) {
+                    $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['curr'])){
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['curr'] = 0;
+                    }
+                }
+            }
+        }
+
+        $stat_arr['series'][0]['name'] = lang('last_week');
+        $stat_arr['series'][0]['data'] = array_values($up_arr);
+        $stat_arr['series'][1]['name'] = lang('this_week');
+        $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+        //得到统计图数据
+        $stat_arr['title'] = lang('new_store_statistics');
+        $stat_arr['yAxis'] =  lang('new_store_count');
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json_week_store', $stat_json);
+    }
+
+    /**
+     * 获取本周新增商品数量
+     */
+    private function _get_week_goods() {
+        $field = ' COUNT(*) as allnum ';
+        $current_weekarr = getWeek_SdateAndEdate(TIMESTAMP);
+        $stime = strtotime($current_weekarr['sdate']) - 86400 * 7;
+        $etime = strtotime($current_weekarr['edate']) + 86400 - 1;
+        //总计的查询时间
+        $count_arr['seartime'] = ($stime + 86400 * 7) . '|' . $etime;
+
+        $up_week = @date('W', $stime); //上周
+        $curr_week = @date('W', $etime); //本周
+        //构造横轴数据
+        for ($i = 1; $i <= 7; $i++) {
+            //统计图数据
+            $up_arr[$i] = 0;
+            $curr_arr[$i] = 0;
+            $tmp_weekarr = getSystemWeekArr();
+            //统计表数据
+            $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+            //方便搜索会员列表,计算开始时间和结束时间
+            $currlist_arr[$i]['stime'] = strtotime($current_weekarr['sdate']) + ($i - 1) * 86400;
+            $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+            $uplist_arr[$i]['val'] = 0;
+            $currlist_arr[$i]['val'] = 0;
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+            unset($tmp_weekarr);
+        }
+        $where = array();
+        $where[] = array('goods_addtime','between', array($stime, $etime));
+        $field .= ',WEEKOFYEAR(FROM_UNIXTIME(goods_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(goods_addtime))+1 as dayofweekval ';
+        
+        $goodslist = Db::name('goodscommon')->field($field)->where($where)->group('weekval,dayofweekval')->select()->toArray();
+
+        if ($goodslist) {
+            foreach ($goodslist as $k => $v) {
+                if ($up_week == intval($v['weekval'])) {
+                    $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['up'])){
+                        $count_arr['up'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['up'] = 0;
+                    }
+                }
+                if ($curr_week == $v['weekval']) {
+                    $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['curr'])){
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['curr'] = 0;
+                    }
+                }
+            }
+        }
+        
+        
+
+        $stat_arr['series'][0]['name'] = lang('last_week');
+        $stat_arr['series'][0]['data'] = array_values($up_arr);
+        $stat_arr['series'][1]['name'] = lang('this_week');
+        $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+        //得到统计图数据
+        $stat_arr['title'] = lang('new_goods_statistics');
+        $stat_arr['yAxis'] = lang('new_goods_count');
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json_week_goods', $stat_json);
+    }
+    
+     /**
+     * 获取本周新增会员数量
+     */
+    private function _get_week_member() {
+        $field = ' COUNT(*) as allnum ';
+        $current_weekarr = getWeek_SdateAndEdate(TIMESTAMP);
+        $stime = strtotime($current_weekarr['sdate']) - 86400 * 7;
+        $etime = strtotime($current_weekarr['edate']) + 86400 - 1;
+        //总计的查询时间
+        $count_arr['seartime'] = ($stime + 86400 * 7) . '|' . $etime;
+
+        $up_week = @date('W', $stime); //上周
+        $curr_week = @date('W', $etime); //本周
+        //构造横轴数据
+        for ($i = 1; $i <= 7; $i++) {
+            //统计图数据
+            $up_arr[$i] = 0;
+            $curr_arr[$i] = 0;
+            $tmp_weekarr = getSystemWeekArr();
+            //统计表数据
+            $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+            //方便搜索会员列表,计算开始时间和结束时间
+            $currlist_arr[$i]['stime'] = strtotime($current_weekarr['sdate']) + ($i - 1) * 86400;
+            $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+            $uplist_arr[$i]['val'] = 0;
+            $currlist_arr[$i]['val'] = 0;
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+            unset($tmp_weekarr);
+        }
+        $where = array();
+        $where[] = array('member_addtime','between', array($stime, $etime));
+        $field .= ',WEEKOFYEAR(FROM_UNIXTIME(member_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(member_addtime))+1 as dayofweekval ';
+        $memberlist = Db::name('member')->field($field)->where($where)->group('weekval,dayofweekval')->select()->toArray();
+
+        if ($memberlist) {
+            foreach ($memberlist as $k => $v) {
+                if ($up_week == intval($v['weekval'])) {
+                    $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['up'])){
+                        $count_arr['up'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['up'] = 0;
+                    }
+                }
+                if ($curr_week == $v['weekval']) {
+                    $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                    $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    if(isset($count_arr['curr'])){
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }else{
+                        $count_arr['curr'] = 0;
+                    }
+                }
+            }
+        }
+        
+        $stat_arr['series'][0]['name'] = lang('last_week');
+        $stat_arr['series'][0]['data'] = array_values($up_arr);
+        $stat_arr['series'][1]['name'] = lang('this_week');
+        $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+        //得到统计图数据
+        $stat_arr['title'] = lang('new_member_statistics');
+        $stat_arr['yAxis'] = lang('new_member_count');
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json_week_member', $stat_json);
+    }
+
+    /**
+     * 获取当前数据库版本
+     */
+    private function _mysql_version() {
+        $version = Db::query("select version() as ver");
+        return $version[0]['ver'];
+    }
+
+    function aboutus() {
+        $this->setAdminCurItem('aboutus');
+        return View::fetch();
+    }
+
+    /**
+     * 统计
+     */
+    public function statistics() {
+        $statistics = array();
+        // 本周开始时间点
+        $tmp_time = mktime(0, 0, 0, date('m'), date('d'), date('Y')) - (date('w') == 0 ? 7 : date('w') - 1) * 24 * 60 * 60;
+        /**
+         * 会员
+         */
+        $member_model = model('member');
+        // 会员总数
+        $statistics['member'] = $member_model->getMemberCount(array());
+        // 新增会员数
+        $statistics['week_add_member'] = $member_model->getMemberCount(array(array('member_addtime','>=', $tmp_time)));
+        // 预存款提现
+        $statistics['cashlist'] = model('predeposit')->getPdcashCount(array('pdc_payment_state' => 0));
+        // 会员认证
+        $statistics['member_auth'] = $member_model->getMemberCount(array(array('member_auth_state' ,'=', 1)));
+
+        /**
+         * 店铺
+         */
+        $store_model = model('store');
+        // 店铺总数
+        $statistics['store'] = model('store')->getStoreCount(array());
+        // 店铺申请数
+        $statistics['store_joinin'] = model('storejoinin')->getStorejoininCount(array(array('joinin_state','in', array(10, 11))));
+        //经营类目申请
+        $statistics['store_bind_class_applay'] = model('storebindclass')->getStorebindclassCount(array('storebindclass_state' => 0));
+        //店铺续签申请
+        $statistics['store_reopen_applay'] = model('storereopen')->getStorereopenCount(array('storereopen_state' => 1));
+        // 即将到期
+        $statistics['store_expire'] = $store_model->getStoreCount(array(array('store_state','=',1),array('store_endtime','between',array(TIMESTAMP, TIMESTAMP + 864000))));
+        // 已经到期
+        $statistics['store_expired'] = $store_model->getStoreCount(array(array('store_state','=',1),array('store_endtime','between',array(1, TIMESTAMP))));
+
+        /**
+         * 商品
+         */
+        $goods_model = model('goods');
+        // 商品总数
+        $statistics['goods'] = $goods_model->getGoodsCommonCount(array());
+        // 新增商品数
+        $statistics['week_add_product'] = $goods_model->getGoodsCommonCount(array(array('goods_addtime','>=', $tmp_time)));
+        // 等待审核
+        $statistics['product_verify'] = $goods_model->getGoodsCommonWaitVerifyCount(array());
+        // 举报
+        $statistics['inform_list'] = model('inform')->getInformCount(array('inform_state' => 1));
+        // 品牌申请
+        $statistics['brand_apply'] = model('brand')->getBrandCount(array('brand_apply' => '0'));
+
+        /**
+         * 交易
+         */
+        $order_model = model('order');
+        $refundreturn_model = model('refundreturn');
+        $vrrefund_model = model('vrrefund');
+        $complain_model = model('complain');
+        // 订单总数
+        $statistics['order'] = $order_model->getOrderCount(array());
+        // 退款
+        $statistics['refund'] = $refundreturn_model->getRefundreturnCount(array('refund_type' => 1, 'refund_state' => 2));
+        // 退货
+        $statistics['return'] = $refundreturn_model->getRefundreturnCount(array('refund_type' => 2, 'refund_state' => 2));
+        // 虚拟订单退款
+        $statistics['vr_refund'] = $vrrefund_model->getVrrefundCount(array('admin_state' => 1));
+        // 投诉
+        $statistics['complain_new_list'] = $complain_model->getComplainCount(array('complain_state' => 10));
+        // 待仲裁
+        $statistics['complain_handle_list'] = $complain_model->getComplainCount(array('complain_state' => 40));
+
+        /**
+         * 运营
+         */
+        // 抢购数量
+        $statistics['groupbuy_verify_list'] = model('groupbuy')->getGroupbuyCount(array('groupbuy_state' => 10));
+        // 积分订单
+        $pointsorder_model = model('pointorder');
+        $condition =array();
+        $condition =array(array('point_orderstate','in', array(11, 20)));
+        $statistics['points_order'] = $pointsorder_model->getPointorderCount($condition);
+        //待审核账单
+        $bill_model = model('bill');
+        $statistics['check_billno'] = $bill_model->getOrderbillCount(array('ob_state'=>BILL_STATE_STORE_COFIRM));
+        //待支付账单
+        $statistics['pay_billno'] = $bill_model->getOrderbillCount(array('ob_state'=>BILL_STATE_STORE_COFIRM));
+        // 平台客服
+        $statistics['mall_consult'] = model('mallconsult')->getMallconsultCount(array('mallconsult_isreply' => 0));
+        // 服务站
+        $statistics['chain'] = model('chain')->getChainWaitVerifyCount(array());
+
+        echo json_encode($statistics);
+        exit;
+    }
+    /**
+     * h5链接
+     */
+    public function h5_link(){
+        return View::fetch();
+    }
+    public function h5_activity(){
+        $activity_model = model('activity');
+        $keyword=input('param.keyword');
+        $condition = array();
+        $condition[] = array('activity_type','=',1); //只显示商品活动
+        $condition[] = array('activity_state','=',1);
+        if($keyword){
+            $condition[] = array('activity_title','like','%'.$keyword.'%');
+        }
+        $activity_list = $activity_model->getActivityList($condition, 10 , 'activity_sort asc');
+        View::assign('show_page', $activity_model->page_info->render());
+        View::assign('activity_list', $activity_list);
+        return View::fetch();
+    }
+    public function h5_live(){
+        $condition = array();
+        $store_model = model('store');
+        $keyword=input('param.keyword');
+        if (config('ds_config.live_type') == 1) {
+            $minipro_live_model = model('minipro_live');
+            if($keyword){
+                $condition[] = array('minipro_live_name','like','%'.$keyword.'%');
+            }
+            $minipro_live_list = $minipro_live_model->getMiniproLiveList($condition);
+            $store_list = array();
+            foreach ($minipro_live_list as $key => $val) {
+                if (!isset($store_list[$val['store_id']])) {
+                    $store_list[$val['store_id']] = $store_model->getStoreInfo(array('store_id' => $val['store_id']));
+                }
+                $minipro_live_list[$key]['store_name'] = $store_list[$val['store_id']]['store_name'] ? $store_list[$val['store_id']]['store_name'] : '';
+            }
+            View::assign('minipro_live_list', $minipro_live_list);
+            View::assign('show_page', $minipro_live_model->page_info->render());
+        } else {
+            $live_apply_model = model('live_apply');
+            $condition[] = array('live_apply_state', '=', 1);
+            if($keyword){
+                $condition[] = array('live_apply_name','like','%'.$keyword.'%');
+            }
+            
+
+            $live_apply_list = $live_apply_model->getLiveApplyList($condition, '*', 10, 'live_apply_state asc,live_apply_id desc');
+
+            $store_list = array();
+            foreach ($live_apply_list as $key => $val) {
+                $live_apply_list[$key]['live_apply_user_name'] = '';
+                switch ($val['live_apply_user_type']) {
+                    case 2:
+                        if (!isset($store_list[$val['live_apply_user_id']])) {
+                            $store_list[$val['live_apply_user_id']] = $store_model->getStoreInfo(array('store_id' => $val['live_apply_user_id']));
+                        }
+                        $live_apply_list[$key]['live_apply_user_name'] = $store_list[$val['live_apply_user_id']]['store_name'] ? $store_list[$val['live_apply_user_id']]['store_name'] : '';
+                        break;
+                }
+            }
+            View::assign('live_apply_list', $live_apply_list);
+            View::assign('show_page', $live_apply_model->page_info->render());
+        }
+        return View::fetch();
+    }
+    public function h5_market(){
+        $condition = array();
+        $keyword=input('param.keyword');
+        $marketmanage_type=intval(input('param.type'));
+        $condition[]=array('marketmanage_type','=',$marketmanage_type);
+        if($keyword){
+            $condition[] = array('marketmanage_name','like','%'.$keyword.'%');
+        }
+        $marketmanage_model = model('marketmanage');
+        $marketmanage_list = $marketmanage_model->getMarketmanageList($condition, 10);
+        View::assign('marketmanage_list', $marketmanage_list);
+        View::assign('show_page', $marketmanage_model->page_info->render());
+        return View::fetch();
+    }
+    public function h5_bonus(){
+        $keyword=input('param.keyword');
+        $condition = array();
+        $condition[]=array('bonus_state','=',1);
+        $condition[]=array('bonus_type','=',1);
+        if($keyword){
+            $condition[] = array('bonus_name','like','%'.$keyword.'%');
+        }
+        $bonus_model = model('bonus');
+        $bonus_list = $bonus_model->getBonusList($condition, 10);
+        View::assign('bonus_list', $bonus_list);
+        View::assign('show_page', $bonus_model->page_info->render());
+        return View::fetch();
+    }
+    public function h5_special(){
+        $keyword=input('param.keyword');
+        $editable_page_model = model('editable_page');
+        $store_id=intval(input('param.store_id'));
+        $condition = array();
+        $condition[]=array('store_id','=',$store_id);
+        $condition[]=array('editable_page_client','=','h5');
+        if($keyword){
+            $condition[] = array('editable_page_name','like','%'.$keyword.'%');
+        }
+        $editable_page_list = $editable_page_model->getEditablePageList($condition, 10);
+        View::assign('show_page', $editable_page_model->page_info->render());
+        View::assign('editable_page_list', $editable_page_list);
+        return View::fetch();
+    }
+    public function h5_point_prod(){
+        $keyword=input('param.keyword');
+        $pointprod_model = model('pointprod');
+        $condition = array();
+        $condition[] = array('pgoods_show', '=', 1);
+        if($keyword){
+            $condition[] = array('pgoods_name','like','%'.$keyword.'%');
+        }
+        $prod_list = $pointprod_model->getPointProdList($condition, '*', 'pgoods_sort asc,pgoods_id desc', 0, 10);
+        //信息输出
+        View::assign('prod_list', $prod_list);
+        View::assign('show_page', $pointprod_model->page_info->render());
+        return View::fetch();
+    }
+    public function h5_article_class(){
+        if(input('param.ajax')==1){
+            $articleclass_model = model('articleclass');
+            $parent_id=intval(input('param.parent_id'));
+            $condition=array();
+            $condition[]=array('ac_parent_id','=',$parent_id);
+            $data=$articleclass_model->getArticleclassList($condition);
+            ds_json_encode(10000, '', $data);
+        }else{
+            return View::fetch();
+        }
+    }
+    public function h5_article(){
+        $keyword=input('param.keyword');
+        $article_model = model('article');
+        $condition=array();
+        $condition[]=array('article_show','=',1);
+        if($keyword){
+            $condition[] = array('article_title','like','%'.$keyword.'%');
+        }
+        $article_list = $article_model->getArticleList($condition, 10);
+        return View::fetch();
+    }
+    public function h5_document(){
+        $condition=array();
+        $keyword=input('param.keyword');
+        $document_model = model('document');
+        if($keyword){
+            $condition[] = array('document_title','like','%'.$keyword.'%');
+        }
+        $doc_list = $document_model->getDocumentList($condition);
+        View::assign('doc_list', $doc_list);
+        return View::fetch();
+    }
+    public function h5_store_class(){
+        $storeclass_model = model('storeclass');
+        $keyword=input('param.keyword');
+        $store_class_list = $storeclass_model->getStoreclassList(array(), 10);
+        View::assign('class_list', $store_class_list);
+        View::assign('show_page', $storeclass_model->page_info->render());
+        return View::fetch();
+    }
+    public function h5_store(){
+        $keyword=input('param.keyword');
+        $store_model=model('store');
+        $condition=array();
+        $condition[] = array('store_state', '=', 1);
+        if($keyword){
+            $condition[] = array('store_name','like','%'.$keyword.'%');
+        }
+        $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
+        View::assign('store_list', $store_list);
+        View::assign('show_page', $store_model->page_info->render());
+        return View::fetch();
+    }
+    public function h5_goods_class(){
+        if(input('param.ajax')==1){
+            $goodsclass_model = model('goodsclass');
+            $parent_id=intval(input('param.parent_id'));
+            $data=$goodsclass_model->getGoodsclassListByParentId($parent_id);
+            ds_json_encode(10000, '', $data);
+        }else{
+            return View::fetch();
+        }
+    }
+    public function h5_goods(){
+        $keyword=input('param.keyword');
+        $goods_model = model('goods');
+        $condition=array();
+        $condition[]=array('goods_state','=',1);
+        $condition[]=array('goods_verify','=',1);
+        if($keyword){
+            $condition[] = array('goods_name','like','%'.$keyword.'%');
+        }
+        $goods_list = $goods_model->getGoodsList($condition, '*', '', '', 0, 10);
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $goods_model->page_info->render());
+        return View::fetch();
+    }
+}
+
+?>

+ 339 - 0
app/admin/controller/Database.php

@@ -0,0 +1,339 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+//数据库备份根路径
+define('DATA_BACKUP_PATH', 'uploads/sqldata/');
+//数据库备份卷大小  20971520表示为 20M
+//define('DATA_BACKUP_PART_SIZE', 20971520);
+define('DATA_BACKUP_PART_SIZE', 1024*1024*10);
+//数据库备份文件是否启用压缩
+define('DATA_BACKUP_COMPRESS', 0);
+//数据库备份文件压缩级别
+define('DATA_BACKUP_COMPRESS_LEVEL', 9);
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Database extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/db.lang.php');
+    }
+
+    public function db() {
+        $dbtable_list = Db::query('SHOW TABLE STATUS');
+        $total = 0;
+        foreach ($dbtable_list as $k => $v) {
+            $dbtable_list[$k]['size'] = format_bytes($v['Data_length'] + $v['Index_length']);
+            $total += $v['Data_length'] + $v['Index_length'];
+        }
+        View::assign('dbtable_list', $dbtable_list);
+        View::assign('total', format_bytes($total));
+        View::assign('tableNum', count($dbtable_list));
+        $this->setAdminCurItem('db');
+        return View::fetch();
+    }
+
+    public function export($tables = null, $id = null, $start = null) {
+        //防止备份数据过程超时
+        function_exists('set_time_limit') && set_time_limit(0);
+        if (request()->isPost() && !empty($tables) && is_array($tables)) { //初始化
+            $path = DATA_BACKUP_PATH;
+            if (!is_dir($path)) {
+                mkdir($path, 0755, true);
+            }
+            //读取备份配置
+            $config = array(
+                'path' => realpath($path) . DIRECTORY_SEPARATOR,
+                'part' => DATA_BACKUP_PART_SIZE,
+                'compress' => DATA_BACKUP_COMPRESS,
+                'level' => DATA_BACKUP_COMPRESS_LEVEL,
+            );
+            //检查是否有正在执行的任务
+            $lock = "{$config['path']}backup.lock";
+            if (is_file($lock)) {
+                return json(array('info' => lang('file_conflict'), 'status' => 0, 'url' => ''));
+            } else {
+                //创建锁文件
+                file_put_contents($lock, TIMESTAMP);
+            }
+
+            //检查备份目录是否可写
+            if (!is_writeable($config['path'])) {
+                return json(array('info' => lang('file_cannot_write'), 'status' => 0, 'url' => ''));
+            }
+            session('backup_config', $config);
+
+            //生成备份文件信息
+            $file = array(
+                'name' => date('Ymd-His', $_SERVER['REQUEST_TIME']),
+                'part' => 1,
+            );
+            session('backup_file', $file);
+            //缓存要备份的表
+            session('backup_tables', $tables);
+            //创建备份文件
+            $Database = new \mall\Backup($file, $config);
+            if (false !== $Database->create()) {
+                $tab = array('id' => 0, 'start' => 0);
+                return json(array('tables' => $tables, 'tab' => $tab, 'info' => lang('init_success'), 'status' => 1, 'url' => ''));
+            } else {
+                return json(array('info' => lang('init_error'), 'status' => 0, 'url' => ''));
+            }
+        } elseif (request()->isGet() && is_numeric($id) && is_numeric($start)) { //备份数据
+            $tables = session('backup_tables');
+            //备份指定表
+            $Database = new \mall\Backup(session('backup_file'), session('backup_config'));
+            $start = $Database->backup($tables[$id], $start);
+            if (false === $start) { //出错
+                return json(array('info' => lang('back_error'), 'status' => 0, 'url' => ''));
+            } elseif (0 === $start) { //下一表
+                if (isset($tables[++$id])) {
+                    $tab = array('id' => $id, 'start' => 0);
+                    return json(array('tab' => $tab, 'info' => lang('back_finish'), 'status' => 1, 'url' => ''));
+                } else { //备份完成,清空缓存
+                    unlink(session('backup_config.path') . 'backup.lock');
+                    session('backup_tables', null);
+                    session('backup_file', null);
+                    session('backup_config', null);
+                    return json(array('info' => lang('back_finish'), 'status' => 1, 'url' => ''));
+                }
+            } else {
+                $tab = array('id' => $id, 'start' => $start[0]);
+                $rate = floor(100 * ($start[0] / $start[1]));
+                return json(array('tab' => $tab, 'info' => lang('backup_in_progress')."...({$rate}%)", 'status' => 1, 'url' => ''));
+            }
+        } else {
+            //出错
+            return json(array('info' => lang('param_error'), 'status' => 0, 'url' => ''));
+        }
+    }
+
+    public function restore() {
+        $path = DATA_BACKUP_PATH;
+        if (!is_dir($path)) {
+            mkdir($path, 0755, true);
+        }
+        $path = realpath($path);
+        $flag = \FilesystemIterator::KEY_AS_FILENAME;
+        $glob = new \FilesystemIterator($path, $flag);
+        $restore_list = array();
+        $filenum = $total = 0;
+        foreach ($glob as $name => $file) {
+            if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
+                $name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
+                $date = "{$name[0]}-{$name[1]}-{$name[2]}";
+                $time = "{$name[3]}:{$name[4]}:{$name[5]}";
+                $part = $name[6];
+                $info = pathinfo($file);
+                if (isset($restore_list["{$date} {$time}"])) {
+                    $info = $restore_list["{$date} {$time}"];
+                    $info['part'] = max($info['part'], $part);
+                    $info['size'] = $info['size'] + $file->getSize();
+                } else {
+                    $info['part'] = $part;
+                    $info['size'] = $file->getSize();
+                }
+                $info['compress'] = ($info['extension'] === 'sql') ? '-' : $info['extension'];
+                $info['time'] = strtotime("{$date} {$time}");
+                $filenum++;
+                $total += $info['size'];
+                $restore_list["{$date} {$time}"] = $info;
+            }
+        }
+        View::assign('restore_list', $restore_list);
+        View::assign('filenum', $filenum);
+        View::assign('total', $total);
+        $this->setAdminCurItem('restore');
+        return View::fetch();
+    }
+
+    /**
+     * 执行还原数据库操作
+     * @param int $time
+     * @param null $part
+     * @param null $start
+     */
+    public function import($time = 0, $part = null, $start = null) {
+        function_exists('set_time_limit') && set_time_limit(0);
+
+        if (is_numeric($time) && is_null($part) && is_null($start)) { //初始化
+            //获取备份文件信息
+            $name = date('Ymd-His', $time) . '-*.sql*';
+            $path = realpath(DATA_BACKUP_PATH) . DIRECTORY_SEPARATOR . $name;
+            $files = glob($path);
+            $list = array();
+            foreach ($files as $name) {
+                $basename = basename($name);
+                $match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d');
+                $gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename);
+                $list[$match[6]] = array($match[6], $name, $gz);
+            }
+            ksort($list);
+
+            //检测文件正确性
+            $last = end($list);
+            if (count($list) === $last[0]) {
+                session('backup_list', $list); //缓存备份列表
+                $this->success(lang('init_success'), NULL ,['part'=>1,'start'=>0]);
+            } else {
+                $this->error(lang('file_break_please_check'));
+            }
+        } elseif (is_numeric($part) && is_numeric($start)) {
+            $list = session('backup_list');
+            $db = new \mall\Backup($list[$part], array(
+                'path' => realpath(DATA_BACKUP_PATH) . DIRECTORY_SEPARATOR,
+                'compress' => $list[$part][2])
+            );
+            $start = $db->import($start);
+            if (false === $start) {
+                $this->error(lang('recover_error'));
+            } elseif (0 === $start) { //下一卷
+                if (isset($list[++$part])) {
+                    $data = array('part' => $part, 'start' => 0);
+                    $this->success(lang('restoring')."...#{$part}", null, $data);
+                } else {
+                    session('backup_list', null);
+                    $this->success(lang('recover_success'));
+                }
+            } else {
+                $data = array('part' => $part, 'start' => $start[0]);
+                if ($start[1]) {
+                    $rate = floor(100 * ($start[0] / $start[1]));
+                    $this->success(lang('restoring')."...#{$part} ({$rate}%)", null, $data);
+                } else {
+                    $data['gz'] = 1;
+                    $this->success(lang('restoring')."...#{$part}", null, $data);
+                }
+            }
+        } else {
+            $this->error(lang('param_error'));
+        }
+    }
+
+    /**
+     * 优化
+     */
+    public function optimize() {
+        $batchFlag = intval(input('param.batchFlag'));
+        //批量删除
+        if ($batchFlag) {
+            $table = input('param.key');
+        } else {
+            $table[] = input('param.tablename');
+        }
+        if (empty($table)) {
+            $this->error(lang('please_select_repire_table'));
+        }
+
+        $strTable = implode(',', $table);
+
+        if (!Db::query("OPTIMIZE TABLE {$strTable} ")) {
+            $strTable = '';
+        }
+        $this->success(lang('optimization_table_succ') . $strTable, (string)url('Database/db'));
+    }
+
+    /**
+     * 修复
+     */
+    public function repair() {
+        $batchFlag = intval(input('param.batchFlag'));
+        //批量删除
+        if ($batchFlag) {
+            $table = I('key', array());
+        } else {
+            $table[] = input('param.tablename');
+        }
+
+        if (empty($table)) {
+            $this->error(lang('please_repire_table'));
+        }
+
+        $strTable = implode(',', $table);
+        if (!Db::query("REPAIR TABLE {$strTable} ")) {
+            $strTable = '';
+        }
+
+        $this->success(lang('optimization_repair_succ') . $strTable, (string)url('Database/db'));
+    }
+
+    /**
+     * 下载
+     * @param int $time
+     */
+    public function downFile($time = 0) {
+        $name = date('Ymd-His', $time) . '-*.sql*';
+        $path = realpath(DATA_BACKUP_PATH) . DIRECTORY_SEPARATOR . $name;
+        $files = glob($path);
+        if (is_array($files)) {
+            foreach ($files as $filePath) {
+                if (!file_exists($filePath)) {
+                    $this->error(lang('file_not_exist'));
+                } else {
+                    $filename = basename($filePath);
+                    header("Content-type: application/octet-stream");
+                    header('Content-Disposition: attachment; filename="' . $filename . '"');
+                    header("Content-Length: " . filesize($filePath));
+                    readfile($filePath);
+                }
+            }
+        }
+    }
+
+    /**
+     * 删除备份文件
+     * @param  Integer $time 备份时间
+     */
+    public function del($time = 0) {
+        if ($time) {
+            $name = date('Ymd-His', $time) . '-*.sql*';
+            $path = realpath(DATA_BACKUP_PATH) . DIRECTORY_SEPARATOR . $name;
+            array_map("unlink", glob($path));
+            if (count(glob($path))) {
+                $this->error(lang('back_file_drop_fail'));
+            } else {
+                $this->success(lang('back_file_drop_success'));
+            }
+        } else {
+            $this->error(lang('param_error'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'db',
+                'text' => lang('data_backup'),
+                'url' => (string)url('Database/db')
+            ),
+            array(
+                'name' => 'restore',
+                'text' => lang('data_restoration'),
+                'url' => (string)url('Database/restore')
+            ),
+        );
+
+        return $menu_array;
+    }
+
+}
+
+?>

+ 216 - 0
app/admin/controller/Document.php

@@ -0,0 +1,216 @@
+<?php
+
+/**
+ * 会员协议管理
+ */
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Document extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/document.lang.php');
+    }
+
+    /**
+     * 系统文章管理首页
+     */
+    public function index() {
+        $document_model = model('document');
+        $doc_list = $document_model->getDocumentList();
+        View::assign('doc_list', $doc_list);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 系统文章编辑
+     */
+    public function edit() {
+        if (request()->isPost()) {
+            /**
+             * 验证
+             */
+            $data = [
+                'document_title' => input('post.document_title'),
+                'document_content' => input('post.document_content'),
+            ];
+            $document_validate = ds_validate('document');
+            if (!$document_validate->scene('edit')->check($data)) {
+                $this->error($document_validate->getError());
+            } else {
+                $param = array();
+                $param['document_id'] = intval(input('document_id'));
+                $param['document_title'] = trim(input('document_title'));
+                $param['document_content'] = trim(input('document_content'));
+                $param['document_time'] = TIMESTAMP;
+                $document_model = model('document');
+
+                $result = $document_model->editDocument($param);
+
+                if ($result) {
+                    /**
+                     * 更新图片信息ID
+                     */
+                    $upload_model = model('upload');
+                    $file_id_array = input('post.file_id/a');
+                    if (is_array($file_id_array) && !empty($file_id_array)) {
+                        foreach ($file_id_array as $k => $v) {
+                            $v = intval($v);
+                            $update_array = array();
+                            $update_array['item_id'] = intval(input('document_id'));
+                            $upload_model->editUpload($update_array,array(array('upload_id','=',intval($v))));
+                            unset($update_array);
+                        }
+                    }
+
+                    $this->log(lang('ds_edit') . lang('document_index_document') . '[ID:' . input('document_id') . ']', 1);
+                    $this->success(lang('ds_common_save_succ'), 'document/index');
+                } else {
+                    $this->error(lang('ds_common_save_fail'));
+                }
+            }
+        } else {
+            if (empty(input('param.document_id'))) {
+                $this->error(lang('miss_argument'));
+            }
+            $document_model = model('document');
+            $doc = $document_model->getOneDocumentById(intval(input('param.document_id')));
+
+            /**
+             * 模型实例化
+             */
+            $upload_model = model('upload');
+            $condition = array();
+            $condition[] = array('upload_type', '=', '4');
+            $condition[] = array('item_id', '=', $doc['document_id']);
+            $file_upload = $upload_model->getUploadList($condition);
+            if (is_array($file_upload)) {
+                foreach ($file_upload as $k => $v) {
+                    $file_upload[$k]['upload_path'] = $file_upload[$k]['file_name'];
+                }
+            }
+
+            View::assign('PHPSESSID', session_id());
+            View::assign('file_upload', $file_upload);
+            View::assign('doc', $doc);
+            $this->setAdminCurItem('edit');
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 系统文章图片上传
+     */
+    public function document_pic_upload() {
+        /**
+         * 上传图片
+         */
+        $file_name = '';
+        $file_object = request()->file('fileupload');
+        if ($file_object) {
+                $res=ds_upload_pic(ATTACH_ARTICLE,'fileupload');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                }else{
+                    echo $res['msg'];
+                    exit;
+                }
+        } else {
+            echo 'error';
+            exit;
+        }
+
+        /**
+         * 模型实例化
+         */
+        $upload_model = model('upload');
+        /**
+         * 图片数据入库
+         */
+        $insert_array = array();
+        $insert_array['file_name'] = $file_name;
+        $insert_array['upload_type'] = '4';
+        $insert_array['file_size'] = $_FILES['fileupload']['size'];
+        $insert_array['item_id'] = intval(input('param.item_id'));
+        $insert_array['upload_time'] = TIMESTAMP;
+        $result = $upload_model->addUpload($insert_array);
+        if ($result) {
+            $data = array();
+            $data['file_id'] = $result;
+            $data['file_name'] = $file_name;
+            $data['file_path'] = ds_get_pic(ATTACH_ARTICLE , $file_name);
+            /**
+             * 整理为json格式
+             */
+            $output = json_encode($data);
+            echo $output;
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        switch (input('param.branch')) {
+            /**
+             * 删除文章图片
+             */
+            case 'del_file_upload':
+                if (intval(input('param.file_id')) > 0) {
+                    $upload_model = model('upload');
+                    /**
+                     * 删除图片
+                     */
+                    $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
+                    @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ARTICLE . DIRECTORY_SEPARATOR . $file_array['file_name']);
+                    /**
+                     * 删除信息
+                     */
+                    $condition = array();
+                    $condition[] = array('upload_id', '=', intval(input('param.file_id')));
+                    $upload_model->delUpload($condition);
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string) url('Document/index')
+            ),
+        );
+        if (request()->action() == 'edit') {
+            $menu_array[] = array(
+                'name' => 'edit', 'text' => lang('ds_edit'), 'url' => 'javascript:void(0)'
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 568 - 0
app/admin/controller/EditablePage.php

@@ -0,0 +1,568 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class EditablePage extends AdminControl {
+
+    var $type = 'pc';
+    var $model_dir = 'home@default/base/editable_page_model/';
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/editable_page.lang.php');
+        Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '.php');
+    }
+
+    /**
+     * 页面列表
+     */
+    public function page_list($type = 'pc') {
+        $this->type = $type;
+        $keyword = input('param.editable_page_name');
+
+        $condition = array();
+        if ($keyword) {
+            $condition[]=array('editable_page_name','like', '%' . $keyword . '%');
+        }
+        View::assign('filtered', empty($condition) ? 0 : 1);
+        if (!in_array($type, array('pc', 'h5'))) {
+            $type = 'pc';
+        }
+
+
+        $editable_page_model = model('editable_page');
+        $condition = array_merge(array(array('store_id', '=', 0), array('editable_page_client', '=', $type)), $condition);
+        $editable_page_list = $editable_page_model->getEditablePageList($condition, 10);
+        foreach ($editable_page_list as $key => $val) {
+            if ($val['editable_page_client'] == 'pc') {
+                $editable_page_list[$key]['edit_url'] = (string)url('admin/editable_page/page_setting', ['editable_page_id' => $val['editable_page_id']]);
+                $editable_page_list[$key]['view_url'] = (string)url('home/special/index', ['special_id' => $val['editable_page_id']]);
+            } else {
+                $editable_page_list[$key]['edit_url'] = (string)url('EditablePage/mobile_page_setting', array('editable_page_id' => $val['editable_page_id']));
+                $editable_page_list[$key]['view_url'] = config('ds_config.h5_site_url') . '/' . 'home/special' . '?' . http_build_query(['special_id' => $val['editable_page_id']]);
+            }
+        }
+
+        View::assign('show_page', $editable_page_model->page_info->render());
+        View::assign('editable_page_list', $editable_page_list);
+        View::assign('type', $type);
+        $this->setAdminCurItem($type . '_page_list');
+        return View::fetch('page_list');
+    }
+
+    public function h5_page_list() {
+        return $this->page_list('h5');
+    }
+
+    
+    /**
+     * 新增页面
+     */
+    public function page_add() {
+        $editable_page_path = input('param.editable_page_path');
+        $editable_page_item_id = intval(input('param.editable_page_item_id'));
+        $editable_page_model = model('editable_page');
+        if (!request()->isPost()) {
+            return View::fetch('page_form');
+        } else {
+            $data = array(
+                'editable_page_name' => input('post.editable_page_name'),
+                'editable_page_path' => $editable_page_path,
+                'editable_page_item_id' => $editable_page_item_id,
+                'editable_page_client' => input('param.type', 'pc'),
+                'editable_page_theme' => 'style_1',
+                'editable_page_edit_time' => TIMESTAMP,
+                'editable_page_theme_config' => json_encode(array(
+                    'back_color' => input('param.back_color')
+                ))
+            );
+            $result = $editable_page_model->addEditablePage($data);
+            $condition = array();
+            $condition[] = array('store_id','=',0);
+            $condition[] = array('editable_page_id','<>',$result);
+            $condition[] = array('editable_page_path','=',$data['editable_page_path']);
+            $condition[] = array('editable_page_client','=',$data['editable_page_client']);
+            if (!in_array($data['editable_page_path'], array('index/index'))) {
+                $condition[] = array('editable_page_item_id','=',$data['editable_page_item_id']);
+            }
+            $editable_page_model->editEditablePage($condition, array('editable_page_path' => '', 'editable_page_item_id' => 0));
+            if ($result) {
+                $this->log(lang('ds_add') . ($data['editable_page_client'] == 'h5' ? lang('editable_page_h5') : lang('editable_page_pc')) . '[flex_' . $result . ':' . input('post.editable_page_name') . ']', null);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    public function page_setting(){
+        $editable_page_id = intval(input('param.editable_page_id'));
+
+        $editable_page_model = model('editable_page');
+        $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_id' => $editable_page_id));
+        if (!$editable_page_info) {
+            $this->error(lang('param_error'));
+        }
+        $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
+        View::assign('editable_page', $editable_page_info);
+        $editable_page_config_model = model('editable_page_config');
+        $editable_page_config_list=$editable_page_config_model->getEditablePageConfigList(array(array('editable_page_id', '=', $editable_page_id)));
+        $config_list=array();
+        foreach($editable_page_config_list as $key => $val){
+            $config_info=json_decode($val['editable_page_config_content'], true);
+            $model_id=$val['editable_page_model_id'];
+            $var_html=array();
+        $var_config=array();
+        if(!empty($config_info)){
+            require_once PLUGINS_PATH.'/editable_page_model/'.$model_id.'/config.php';
+            $model_name='Model'.$model_id;
+            $model=new $model_name();
+            $res=$model->filterData($config_info);
+            if($res['code']){
+                $var_config['config_info']=$res['data'];
+                $res=$model->formatData(json_encode($res['data']));
+                if($res['code']){
+                    $var_html['config_info']=$res['data'];
+                }
+            }
+            
+        }
+        $html=View::fetch('../../../plugins/editable_page_model/'.$model_id.'/index',$var_html);
+        $config=View::fetch('../../../plugins/editable_page_model/'.$model_id.'/config',$var_config);
+            $config_list[]=array(
+                'val'=>$val,
+                'html'=>$html,
+                'config'=>$config
+            );
+        }
+        View::assign('config_list', $config_list);
+        return View::fetch('page_setting');
+    }
+
+    /**
+     * 设置手机端页面
+     */
+    public function mobile_page_setting() {
+        $this->type = 'h5';
+        $editable_page_id = intval(input('param.editable_page_id'));
+
+        $editable_page_model = model('editable_page');
+        $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_id' => $editable_page_id));
+        if (!$editable_page_info) {
+            $this->error(lang('param_error'));
+        }
+        $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
+        View::assign('editable_page', $editable_page_info);
+        $editable_page_config_model = model('editable_page_config');
+        $editable_page_config_list=$editable_page_config_model->getEditablePageConfigList(array(array('editable_page_id', '=', $editable_page_id)));
+        $config_list=array();
+        foreach($editable_page_config_list as $key => $val){
+            $config_info=json_decode($val['editable_page_config_content'], true);
+            $model_id=$val['editable_page_model_id'];
+            $var_html=array();
+        $var_config=array();
+        if(!empty($config_info)){
+            require_once PLUGINS_PATH.'/editable_page_model/h5_'.$model_id.'/config.php';
+            $model_name='Model'.$model_id;
+            $model=new $model_name();
+            $res=$model->filterData($config_info);
+            if($res['code']){
+                $var_config['config_info']=$res['data'];
+                $res=$model->formatData(json_encode($res['data']));
+                if($res['code']){
+                    $var_html['config_info']=$res['data'];
+                }
+            }
+            
+        }
+        $html=View::fetch('../../../plugins/editable_page_model/h5_'.$model_id.'/index',$var_html);
+        $config=View::fetch('../../../plugins/editable_page_model/h5_'.$model_id.'/config',$var_config);
+            $config_list[]=array(
+                'val'=>$val,
+                'html'=>$html,
+                'config'=>$config
+            );
+        }
+        View::assign('config_list', $config_list);
+        $this->setAdminCurItem('mobile_page_setting');
+        return View::fetch('mobile_page_setting');
+    }
+
+
+    /**
+     * 编辑页面
+     */
+    public function page_edit() {
+        $editable_page_id = intval(input('param.editable_page_id'));
+
+        $editable_page_model = model('editable_page');
+        $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_id' => $editable_page_id));
+        if (!$editable_page_info) {
+            $this->error(lang('param_error'));
+        }
+        $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
+        if (!request()->isPost()) {
+            View::assign('editable_page', $editable_page_info);
+            return View::fetch('page_form');
+        } else {
+            $data = array(
+                'editable_page_path' => input('post.editable_page_path'),
+                'editable_page_item_id' => intval(input('post.editable_page_item_id')),
+                'editable_page_name' => input('post.editable_page_name'),
+                'editable_page_theme_config' => json_encode(array(
+                    'back_color' => input('param.back_color')
+                ))
+            );
+            $result = $editable_page_model->editEditablePage(array('editable_page_id' => $editable_page_id), $data);
+            
+            $condition = array();
+            $condition[] = array('store_id','=',0);
+            $condition[] = array('editable_page_id','<>',$editable_page_id);
+            $condition[] = array('editable_page_path','=',$data['editable_page_path']);
+            $condition[] = array('editable_page_client','=',$editable_page_info['editable_page_client']);
+            if (!in_array($data['editable_page_path'], array('index/index'))) {
+                $condition[] = array('editable_page_item_id','=',$data['editable_page_item_id']);
+            }
+            $editable_page_model->editEditablePage($condition, array('editable_page_path' => '', 'editable_page_item_id' => 0));
+            if ($result) {
+                $this->log(lang('ds_edit') . ($editable_page_info['editable_page_client'] == 'h5' ? lang('editable_page_h5') : lang('editable_page_pc')) . '[' . $editable_page_info['editable_page_name'] . ']', null);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    /**
+     * 删除页面
+     */
+    public function page_del() {
+        $editable_page_id = intval(input('param.editable_page_id'));
+
+        $editable_page_model = model('editable_page');
+        $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_id' => $editable_page_id));
+        if (!$editable_page_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        if (!$editable_page_model->delEditablePage($editable_page_id)) {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+        $this->log(lang('ds_del') . ($editable_page_info['editable_page_client'] == 'h5' ? lang('editable_page_h5') : lang('editable_page_pc')) . '[ID:' . $editable_page_info['editable_page_id'] . ':' . $editable_page_info['editable_page_name'] . ']', null);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+
+
+
+    /**
+     * 搜索商品
+     */
+    public function search_goods() {
+        $goods_model = model('goods');
+
+        /**
+         * 查询条件
+         */
+        $where = array();
+        $search_goods_name = trim(input('param.keyword'));
+        $type = trim(input('param.type'));
+        if ($search_goods_name != '') {
+            $where[]=array('goods_name|store_name','like', '%' . $search_goods_name . '%');
+        }
+        switch($type){
+            case 'bargain':
+                $condition=array();
+                $condition[] = array('bargain_state','=',\app\common\model\Pbargain::PINTUAN_STATE_NORMAL);
+                $condition[] = array('bargain_endtime','>',TIMESTAMP);
+                $condition[] = array('bargain_begintime','<',TIMESTAMP);
+                $subQuery=Db::name('pbargain')->field('bargain_goods_id')->where($condition)->buildSql();
+                $where[]=array('goods_id','exp',Db::raw('in '.$subQuery));
+                break;
+            case 'groupbuy':
+                $condition=array();
+                $condition[] = array('groupbuy_state','=',\app\common\model\Groupbuy::GROUPBUY_STATE_NORMAL);
+                $condition[] = array('groupbuy_endtime','>',TIMESTAMP);
+                $condition[] = array('groupbuy_starttime','<',TIMESTAMP);
+                $subQuery=Db::name('groupbuy')->field('goods_commonid')->where($condition)->buildSql();
+                $where[]=array('goods_commonid','exp',Db::raw('in '.$subQuery));
+                break;
+            case 'pintuan':
+                $condition=array();
+                $condition[] = array('pintuan_state', '=', \app\common\model\Ppintuan::PINTUAN_STATE_NORMAL);
+                $condition[] = array('pintuan_end_time', '>', TIMESTAMP);
+                $condition[] = array('pintuan_starttime','<',TIMESTAMP);
+                $subQuery=Db::name('ppintuan')->field('pintuan_goods_commonid')->where($condition)->buildSql();
+                $where[]=array('goods_commonid','exp',Db::raw('in '.$subQuery));
+                break;
+            case 'presell':
+                $condition=array();
+                $condition[] = array('presell_state','=',\app\common\model\Presell::PRESELL_STATE_NORMAL);
+                $condition[] = array('presell_end_time','>',TIMESTAMP);
+                $condition[] = array('presell_start_time','<',TIMESTAMP);
+                $subQuery=Db::name('presell')->field('goods_id')->where($condition)->buildSql();
+                $where[]=array('goods_id','exp',Db::raw('in '.$subQuery));
+                break;
+            case 'xianshi':
+                $condition=array();
+                $condition[] = array('xianshigoods_state','=',\app\common\model\Pxianshigoods::XIANSHI_GOODS_STATE_NORMAL);
+                $condition[] = array('xianshigoods_end_time','>',TIMESTAMP);
+                $condition[] = array('xianshigoods_starttime','<',TIMESTAMP);
+                $subQuery=Db::name('pxianshigoods')->field('goods_id')->where($condition)->buildSql();
+                $where[]=array('goods_id','exp',Db::raw('in '.$subQuery));
+                break;
+        }
+
+        $goods_list = $goods_model->getGoodsOnlineList($where, '*', 12);
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $goods_model->page_info->render());
+        $goods_id=input('param.goods_id/a');
+        if(!empty($goods_id)){
+            $where = array();
+            $where[]=array('goods_id','in', array_keys($goods_id));
+            $goods_list = $goods_model->getGoodsOnlineList($where);
+            $selected_goods=array();
+            foreach($goods_list as $v){
+                $selected_goods[$v['goods_id']]=array_merge($v,array('sort'=>$goods_id[$v['goods_id']]['sort']));
+            }
+            View::assign('goods_id', $selected_goods);
+        }
+        
+        echo View::fetch('search_goods');
+        exit;
+    }
+
+
+    /**
+     * 搜索品牌
+     */
+    public function search_brand() {
+        $brand_model = model('brand');
+        /**
+         * 查询条件
+         */
+        $where = array();
+        $where[] = array('brand_apply', '=', 1);
+        $search_brand_name = trim(input('param.keyword'));
+        if ($search_brand_name != '') {
+            $where[]=array('brand_name','like', '%' . $search_brand_name . '%');
+        }
+
+        $brand_list = $brand_model->getBrandList($where, '*', 12);
+        View::assign('brand_list', $brand_list);
+        View::assign('show_page', $brand_model->page_info->render());
+        $brand_id=input('param.brand_id/a');
+        if(!empty($brand_id)){
+            $where = array();
+            $where[]=array('brand_id','in', array_keys($brand_id));
+            $brand_list = $brand_model->getBrandList($where);
+            $selected_brand=array();
+            foreach($brand_list as $v){
+                $selected_brand[$v['brand_id']]=array_merge($v,array('sort'=>$brand_id[$v['brand_id']]['sort']));
+            }
+            View::assign('brand_id', $selected_brand);
+        }
+        echo View::fetch('search_brand');
+        exit;
+    }
+
+
+    public function image_del() {
+        $file_id = intval(input('param.upload_id'));
+        $res = model('editable_page_model', 'logic')->imageDel($file_id);
+        if (!$res['code']) {
+            ds_json_encode(10001, $res['msg']);
+        }
+
+        ds_json_encode(10000);
+    }
+
+    /**
+     * 图片上传
+     */
+    public function image_upload() {
+        $res = model('editable_page_model', 'logic')->imageUpload(input('param.name'), input('param.config_id'));
+        if (!$res['code']) {
+            ds_json_encode(10001, $res['msg']);
+        }
+        $data = $res['data'];
+        ds_json_encode(10000, '', $data);
+    }
+
+    public function goods_class(){
+        $id=intval(input('param.id'));
+        $parent_id=intval(input('param.parent_id'));
+        $goodsclass_model=model('goodsclass');
+        if($id){
+            $data=array('id'=>array(),'list'=>array());
+            $goodsclass_info=$goodsclass_model->getGoodsclassInfoById($id);
+            if($goodsclass_info){
+                $data['id'][]=$goodsclass_info['gc_id'];
+                $data['list'][]=$goodsclass_model->getGoodsclassListByParentId($goodsclass_info['gc_parent_id']);
+                if($goodsclass_info['gc_parent_id']){
+                    $goodsclass_info=$goodsclass_model->getGoodsclassInfoById($goodsclass_info['gc_parent_id']);
+                    if($goodsclass_info){
+                        $data['id'][]=$goodsclass_info['gc_id'];
+                        $data['list'][]=$goodsclass_model->getGoodsclassListByParentId($goodsclass_info['gc_parent_id']);
+                        if($goodsclass_info['gc_parent_id']){
+                            $goodsclass_info=$goodsclass_model->getGoodsclassInfoById($goodsclass_info['gc_parent_id']);
+                            if($goodsclass_info){
+                                $data['id'][]=$goodsclass_info['gc_id'];
+                                $data['list'][]=$goodsclass_model->getGoodsclassListByParentId($goodsclass_info['gc_parent_id']);
+                            }
+                        }
+                    }
+                }
+            }
+            $data['id']=array_reverse($data['id']);
+            $data['list']=array_reverse($data['list']);
+        }else{
+            $data=$goodsclass_model->getGoodsclassListByParentId($parent_id);
+        }
+        
+        ds_json_encode(10000, '', $data);
+    }
+
+    public function config_load(){
+        $if_h5=intval(input('param.if_h5'));
+        $model_id=intval(input('param.model_id'));
+        $config_info=input('param.config_info/a');
+        if(!$model_id){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $var_html=array();
+        $var_config=array();
+        if(!empty($config_info)){
+            require_once PLUGINS_PATH.'/editable_page_model/'.($if_h5?'h5_':'').$model_id.'/config.php';
+            $model_name='Model'.$model_id;
+            $model=new $model_name();
+            $res=$model->filterData($config_info);
+            if($res['code']){
+                $res=$model->formatData(json_encode($res['data']));
+                if($res['code']){
+                    $var_html['config_info']=$res['data'];
+                }else{
+                    ds_json_encode(10001, $res['msg']);
+                }
+            }else{
+                ds_json_encode(10001, $res['msg']);
+            }
+            
+        }
+        $html=View::fetch('../../../plugins/editable_page_model/'.($if_h5?'h5_':'').$model_id.'/index',$var_html);
+        $config=View::fetch('../../../plugins/editable_page_model/'.($if_h5?'h5_':'').$model_id.'/config',$var_config);
+        ds_json_encode(10000, '', array('html'=>$html,'config'=>$config));
+    }
+
+    public function config_edit(){
+        $if_h5=intval(input('param.if_h5'));
+        $config_list=input('param.config_list/a');
+        $editable_page_id=intval(input('param.page_id'));
+
+        $editable_page_model = model('editable_page');
+        $editable_page_info = $editable_page_model->getOneEditablePage(array('editable_page_id' => $editable_page_id));
+        if (!$editable_page_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        try{
+        $data=array();
+        $new_data=array();
+        $editable_page_theme_config=array();
+        foreach($config_list as $sort_order => $config_info){
+            $model_id=$config_info['model_id'];
+            switch($model_id){
+                case 'page':
+                case 'jump':
+                case 'button':
+                    if($model_id=='page'){
+                        $data['editable_page_name']=$config_info['page_title'];
+                    }
+                    $editable_page_theme_config=array_merge($editable_page_theme_config,$config_info);
+                    
+                    break;
+                default:
+                    require_once PLUGINS_PATH.'/editable_page_model/'.($if_h5?'h5_':'').$model_id.'/config.php';
+                    $model_name='Model'.$model_id;
+                    $model=new $model_name();
+                    $res=$model->filterData($config_info);
+                    if($res['code']){
+                        $new_data[]=array(
+                            'editable_page_id'=>$editable_page_id,
+                            'editable_page_model_id'=>$model_id,
+                            'editable_page_config_sort_order'=>$sort_order,
+                            'editable_page_config_content'=>json_encode($res['data'])
+                        );
+                    }else{
+                        throw new \think\Exception($res['msg'], 10006);
+                    }
+            }
+        }
+        $data['editable_page_theme_config']=json_encode($editable_page_theme_config);
+        $data['editable_page_edit_time']=TIMESTAMP;
+        $editable_page_config_model = model('editable_page_config');
+        $editable_page_config_model->delEditablePageConfig(array(array('editable_page_id', '=', $editable_page_id)));
+        if(!empty($new_data)){
+            $editable_page_config_model->addEditablePageConfigAll($new_data);
+        }
+        $result = $editable_page_model->editEditablePage(array('editable_page_id' => $editable_page_id), $data);
+                if (!$result) {
+                    throw new \think\Exception(lang('ds_common_op_fail'), 10006);
+                }
+            }catch(\Exception $e){
+                ds_json_encode(10001, $e->getMessage());
+              }       
+              $this->log(lang('ds_edit') . ($editable_page_info['editable_page_client'] == 'h5' ? lang('editable_page_h5') : lang('editable_page_pc')) . '[' . $editable_page_info['editable_page_name'] . ']', null);
+                    ds_json_encode(10000, lang('ds_common_op_succ')); 
+    }
+
+    /**
+     * 菜单列表
+     */
+    protected function getAdminItemList() {
+        if ($this->type == 'pc') {
+            $menu_array = array(
+                array(
+                    'name' => 'pc_page_list',
+                    'text' => lang('ds_list'),
+                    'url' => (string)url('EditablePage/page_list'),
+                ),
+                array(
+                    'name' => 'page_add',
+                    'text' => lang('ds_new'),
+                    'url' => "javascript:dsLayerOpen('" . (string)url('EditablePage/page_add') . "','" . lang('ds_new') . "')",
+                ),
+            );
+        } else {
+            $menu_array = array(
+                array(
+                    'name' => 'h5_page_list',
+                    'text' => lang('ds_list'),
+                    'url' => (string)url('EditablePage/page_list', array('type' => 'h5')),
+                ),
+                array(
+                    'name' => 'page_add',
+                    'text' => lang('ds_new'),
+                    'url' => "javascript:dsLayerOpen('" . (string)url('EditablePage/page_add', array('type' => 'h5')) . "','" . lang('ds_new') . "')",
+                ),
+            );
+        }
+        return $menu_array;
+    }
+
+}
+
+?>

+ 143 - 0
app/admin/controller/Evaluate.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Evaluate extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/evaluate.lang.php');
+    }
+
+    /**
+     * 商品来自买家的评价列表
+     */
+    public function evalgoods_list() {
+        $evaluategoods_model = model('evaluategoods');
+
+        $condition = array();
+        //商品名称
+        if (input('param.goods_name')) {
+            $condition[]=array('geval_goodsname','like', '%'.input('param.goods_name').'%');
+        }
+        //店铺名称
+        if (input('param.store_name')) {
+            $condition[]=array('geval_storename','like', '%'.input('param.store_name').'%');
+        }
+        if(input('param.stime')) {
+            $stime = strtotime(input('param.stime'));
+            $condition[]=array('geval_addtime','>=', $stime);
+        }
+        if(input('param.etime')) {
+            $etime = strtotime(input('param.etime'))+86399;
+            $condition[]=array('geval_addtime','<=', $etime);
+        }
+        $evalgoods_list	= $evaluategoods_model->getEvaluategoodsList($condition, 10);
+
+        View::assign('show_page',$evaluategoods_model->page_info->render());
+        View::assign('evalgoods_list',$evalgoods_list);
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('evalgoods_list');
+        return View::fetch('index');
+    }
+
+    /**
+     * 删除商品评价
+     */
+    public function evalgoods_del() {
+        $geval_id = intval(input('param.geval_id'));
+        if ($geval_id <= 0) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $evaluategoods_model = model('evaluategoods');
+        $result = $evaluategoods_model->delEvaluategoods(array('geval_id'=>$geval_id));
+        if ($result) {
+            $this->log(lang('del_evaluategoods').$geval_id);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 店铺动态评价列表
+     */
+    public function evalstore_list() {
+        $evaluatestore_model = model('evaluatestore');
+
+        $condition = array();
+        //评价人
+        if (input('param.from_name')) {
+            $condition[]=array('seval_membername','like', '%'.input('param.from_name').'%');
+        }
+        //店铺名称
+        if (input('param.store_name')) {
+            $condition[]=array('seval_storename','like', '%'.input('param.store_name').'%');
+        }
+        if(input('param.stime')) {
+            $stime = strtotime(input('param.stime'));
+            $condition[]=array('seval_addtime','>=', $stime);
+        }
+        if(input('param.etime')) {
+            $etime = strtotime(input('param.etime'));
+            $condition[]=array('seval_addtime','<=', $etime);
+        }
+
+        $evalstore_list	= $evaluatestore_model->getEvaluatestoreList($condition, 10);
+        View::assign('show_page',$evaluatestore_model->page_info->render());
+        View::assign('evalstore_list',$evalstore_list);
+        $this->setAdminCurItem('evalstore_list');
+        return View::fetch();
+    }
+
+    /**
+     * 删除店铺评价
+     */
+    public function evalstore_del() {
+        $seval_id = intval(input('param.seval_id'));
+        if ($seval_id <= 0) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $evaluatestore_model = model('evaluatestore');
+        $result = $evaluatestore_model->delEvaluatestore(array('seval_id'=>$seval_id));
+        if ($result) {
+            $this->log(lang('del_evaluatestore').$seval_id);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'evalgoods_list',
+                'text' => lang('admin_evaluate_list'),
+                'url' => (string)url('Evaluate/evalgoods_list')
+            ),
+            array(
+                'name' => 'evalstore_list',
+                'text' => lang('admin_evalstore_list'),
+                'url' => (string)url('Evaluate/evalstore_list')
+            )
+        );
+        return $menu_array;
+    }
+}

+ 254 - 0
app/admin/controller/Exppoints.php

@@ -0,0 +1,254 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ *  经验值管理 控制器
+ */
+class Exppoints extends AdminControl
+{
+    const EXPORT_SIZE = 5000;
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/membergrade.lang.php');
+    }
+    /**
+     * 设置经验值获取规则
+     */
+    public function expsetting() {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $exp_arr = array();
+            $exp_arr['exp_login'] = intval(input('post.exp_login'));
+            $exp_arr['exp_comments'] = intval(input('post.exp_comments'));
+            $exp_arr['exp_orderrate'] = intval(input('post.exp_orderrate'));
+            $exp_arr['exp_ordermax'] = intval(input('post.exp_ordermax'));
+            $result = $config_model->editConfig(array('exppoints_rule' => serialize($exp_arr)));
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('ds_exppoints_manage') . lang('ds_exppoints_setting'), 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = $config_model->getOneConfigByCode('exppoints_rule');
+            $list_setting = unserialize($list_setting['value']);
+            View::assign('list_setting', $list_setting);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 经验值日志列表
+     */
+    public function index(){
+        $where = array();
+        $search_mname = trim(input('param.mname'));
+        if(!empty($search_mname)){
+            $where[]=array('explog_membername','like',"%{$search_mname}%");
+        }
+        if (input('param.stage')){
+            $where[]=array('explog_stage','=',trim(input('param.stage')));
+        }
+        $stime = input('param.stime')?strtotime(input('param.stime')):0;
+        $etime = input('param.etime')?strtotime(input('param.etime')):0;
+        if ($stime > 0){
+            $where[]=array('explog_addtime','>=',$stime);
+        }
+        if ($etime > 0){
+            $etime=$etime+86399;
+            $where[]=array('explog_addtime','<=',$etime);
+        }
+        $search_desc = trim(input('param.description'));
+        if(!empty($search_desc)){
+            $where[]=array('explog_desc','like',"%".$search_desc."%");
+        }
+        
+
+        //查询经验值日志列表
+        $exppoints_model = model('exppoints');
+        $list_log = $exppoints_model->getExppointslogList($where, '*', 20, 'explog_id desc');
+        //信息输出
+        
+        View::assign('stage_arr',$exppoints_model->getExppointsStage());
+        View::assign('show_page',$exppoints_model->page_info->render());
+        View::assign('list_log',$list_log);
+        $this->setAdminCurItem('explog');
+        return View::fetch();
+    }
+    
+    /**
+     * 经验值调整
+     */
+    public function edit()
+    {
+         if (!request()->isPost()) {
+            return View::fetch();
+        } else {
+            $data = [
+                'member_name' => input('post.member_name'),
+                'exppoints_type' => input('post.exppoints_type'),
+                'exppoints_num' => intval(input('post.exppoints_num')),
+                'exppoints_desc' => input('post.exppoints_desc'),
+            ];
+            
+            if(empty($data['member_name']) || intval($data['exppoints_type'])<=0){
+                $this->error(lang('param_error'));
+            }
+            
+
+            $member_name = $data['member_name'];
+            $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
+            if (!is_array($member_info) || count($member_info) <= 0) {
+                $this->error(lang('admin_exppoints_userrecord_error'));
+            }
+            if ($data['exppoints_type'] == 2 && $data['exppoints_num'] > $member_info['member_exppoints']) {
+                $this->error(lang('admin_exppoints_short_error') . $member_info['member_exppoints']);
+            }
+            //积分数据记录
+            $insert_arr['explog_memberid'] = $member_info['member_id'];
+            $insert_arr['explog_membername'] = $member_info['member_name'];
+            if ($data['exppoints_type'] == 2) {
+                $insert_arr['explog_points'] = -$data['exppoints_num'];
+            } else {
+                $insert_arr['explog_points'] = $data['exppoints_num'];
+            }
+            $insert_arr['explog_desc'] = $data['exppoints_desc'];
+
+            $result = model('exppoints')->saveExppointslog('system', $insert_arr);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('error'), 'Exppoints/index');
+            }
+        }
+    }
+
+    public function checkmember() {
+        $member_name = trim(input('param.member_name'));
+        if (!$member_name) {
+            exit(json_encode(array('member_id' => 0)));
+        }
+        $obj_member = model('member');
+        $member_info = $obj_member->getMemberInfo(array('member_name' => $member_name));
+        if (is_array($member_info) && count($member_info) > 0) {
+            echo json_encode(array('member_id' => $member_info['member_id'], 'member_name' => $member_info['member_name'], 'member_exppoints' => $member_info['member_exppoints']));
+        } else {
+            exit(json_encode(array('member_id' => 0)));
+            die;
+        }
+    }
+
+    /**
+     * 经验值日志列表导出
+     */
+    public function export_step1(){
+        $where = array();
+        $search_mname = trim(input('param.mname'));
+        $where[]=array('explog_membername','like',"%{$search_mname}%");
+        if (input('param.stage')){
+            $where[]=array('explog_stage','=',trim(input('param.stage')));
+        }
+        $stime = input('param.stime')?strtotime(input('param.stime')):0;
+        $etime = input('param.etime')?strtotime(input('param.etime')):0;
+        if ($stime > 0 && $etime>0){
+            $where[]=array('explog_addtime','between',array($stime,$etime));
+        }elseif ($stime > 0){
+            $where[]=array('explog_addtime','>=',$stime);
+        }elseif ($etime > 0){
+            $where[]=array('explog_addtime','<=',$etime);
+        }
+        $search_desc = trim(input('param.description'));
+        $where[]=array('explog_desc','like',"%$search_desc%");
+
+        //查询经验值日志列表
+        $exppoints_model = model('exppoints');
+        $list_log = $exppoints_model->getExppointslogList($where, '*', self::EXPORT_SIZE,  'explog_id desc');
+        if (!is_numeric(input('param.page'))){
+            $count = $exppoints_model->getExppointslogCount($where);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE ){	//显示下载链接
+                $page = ceil($count/self::EXPORT_SIZE);
+                for ($i=1;$i<=$page;$i++){
+                    $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
+                    $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1.' ~ '.$limit2 ;
+                }
+                View::assign('export_list',$export_list);
+                return View::fetch('/public/excel');
+            }else{	//如果数量小,直接下载
+                $this->createExcel($list_log);
+            }
+        }else{	//下载
+            $this->createExcel($list_log);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()){
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+        //header
+        $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_member_name'));
+        $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('exp_value'));
+        $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_addtime'));
+        $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_stage'));
+        $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_desc'));
+        $stage_arr = model('exppoints')->getExppointsStage();
+        foreach ((array)$data as $k=>$v){
+            $tmp = array();
+            $tmp[] = array('data'=>$v['explog_membername']);
+            $tmp[] = array('format'=>'Number','data'=>ds_price_format($v['explog_points']));
+            $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['explog_addtime']));
+            $tmp[] = array('data'=>$stage_arr[$v['explog_stage']]);
+            $tmp[] = array('data'=>$v['explog_desc']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data,CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('membergrade_exppoints_list'),CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('membergrade_exppoints_list'),CHARSET).input('param.page').'-'.date('Y-m-d-H',TIMESTAMP));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'explog',
+                'text' => lang('ds_exppoints_manage'),
+                'url' =>  (string)url('Exppoints/index')
+            ),
+            array(
+                'name' => 'expset',
+                'text' => lang('ds_exppoints_setting'),
+                'url' =>  "javascript:dsLayerOpen('".(string)url('Exppoints/expsetting')."','".lang('ds_exppoints_setting')."')"
+            ),
+            array(
+                'name' => 'edit',
+                'text' => lang('ds_exppoints_edit'),
+                'url' =>  "javascript:dsLayerOpen('".(string)url('Exppoints/edit')."','".lang('ds_exppoints_edit')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 206 - 0
app/admin/controller/Express.php

@@ -0,0 +1,206 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Express extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/express.lang.php');
+    }
+
+    public function index() {
+        $express_letter = input('get.express_letter');
+        $condition = array();
+        if (preg_match('/^[A-Z]$/', $express_letter)) {
+            $condition[]=array('express_letter','=',$express_letter);
+        }
+        
+        $express_name = input('get.express_name');
+        if(!empty($express_name)){
+            $condition[]=array('express_name','like', "%" . $express_name . "%");
+        }
+        
+        $express_model = model('express');
+        $express_list = $express_model->getAllExpresslist($condition, 10);
+        View::assign('show_page', $express_model->page_info->render());
+        View::assign('express_list', $express_list);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 添加品牌
+     */
+    public function add() {
+        $express_mod = model('express');
+        if (request()->isPost()) {
+            $insert_array['express_name'] = trim(input('post.express_name'));
+            $insert_array['express_code'] = input('post.express_code');
+            $insert_array['express_state'] = intval(input('post.express_state'));
+            $insert_array['express_letter'] = strtoupper(input('post.express_letter'));
+            $insert_array['express_order'] = intval(input('post.express_order'));
+            $insert_array['express_url'] = input('post.express_url');
+
+            $result = $express_mod->addExpress($insert_array);
+            if ($result) {
+                $this->log(lang('ds_add') . lang('express') . '[' . input('post.express_name') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $express = [
+                'express_order' => 1,
+                'express_state' => 1,
+            ];
+            View::assign('express', $express);
+            return View::fetch('form');
+        }
+    }
+
+    public function edit() {
+        $express_model = model('express');
+        $express_id = input('param.express_id');
+        $condition = array();
+        if (request()->isPost()) {
+            $condition[] = array('express_id','=',$express_id);
+
+            $data['express_name'] = trim(input('post.express_name'));
+            $data['express_code'] = input('post.express_code');
+            $data['express_state'] = intval(input('post.express_state'));
+            $data['express_letter'] = strtoupper(input('post.express_letter'));
+            $data['express_order'] = intval(input('post.express_order'));
+            $data['express_url'] = input('post.express_url');
+            $result = $express_model->editExpress($condition, $data);
+
+            if ($result) {
+                $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $express_id . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $express_id . ']', 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $condition[] = array('express_id','=',$express_id);
+            $express = $express_model->getOneExpress($condition);
+            if (empty($express)) {
+                $this->error(lang('param_error'));
+            }
+            View::assign('express', $express);
+            return View::fetch('form');
+        }
+    }
+
+    /**
+     * 删除品牌
+     */
+    public function del() {
+        $express_id = input('param.express_id');
+        $express_id_array = ds_delete_param($express_id);
+        if ($express_id_array == FALSE) {
+            $this->log(lang('ds_del') . lang('express') . '[ID:' . $express_id . ']', 0);
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $express_mod = model('express');
+        $express_mod->delExpress(array(array('express_id','in', implode(',', $express_id_array))));
+        $this->log(lang('ds_del') . lang('express') . '[ID:' . $express_id . ']', 1);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $branch = input('get.branch');
+        $column = input('get.column');
+        $value = trim(input('get.value'));
+        $id = intval(input('get.id'));
+        $condition = array();
+        switch ($branch) {
+            case 'state':
+                $express_model = model('express');
+                $update_array = array();
+                $condition[] = array('express_id','=',$id);
+                $update_array[$column] = $value;
+                $express_model->editExpress($condition, $update_array);
+                $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $id . ']', 1);
+                echo 'true';
+                exit;
+                break;
+            case 'order':
+                $express_model = model('express');
+                $update_array = array();
+                $condition[] = array('express_id','=',$id);
+                $update_array[$column] = $value;
+                $express_model->editExpress($condition, $update_array);
+                $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $id . ']', 1);
+                echo 'true';
+                exit;
+                break;
+        }
+    }
+
+    public function config(){
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            /* 设置卖家当前栏目 */
+            $this->setAdminCurItem('express_config');
+            return View::fetch();
+        } else {
+            $update_array = array();
+            $update_array['expresscf_kdn_type'] = input('post.expresscf_kdn_type');
+            $update_array['expresscf_kdn_id'] = input('post.expresscf_kdn_id');
+            $update_array['expresscf_kdn_key'] = input('post.expresscf_kdn_key');
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Express/index'),
+            ),
+            array(
+                'name' => 'express_config',
+                'text' => '快递查询设置',
+                'url' => (string)url('Express/config')
+            ),
+            array(
+                'name' => 'express_add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Express/add') . "','".lang('ds_add')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 61 - 0
app/admin/controller/Feedback.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Feedback extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/feedback.lang.php');
+    }
+    /**
+     * 意见反馈
+     */
+    public function flist(){
+        $feedback_model = model('feedback');
+        $feedback_list = $feedback_model->getFeedbackList(array(), 10);
+
+       View::assign('feedback_list', $feedback_list);
+       View::assign('show_page', $feedback_model->page_info->render());
+       $this->setAdminCurItem('index');
+       return View::fetch('index');
+    }
+
+    /**
+     * 删除
+     */
+    public function del(){
+        $feedback_model = model('feedback');
+        $feedback_id = input('param.feedback_id');
+        $feedback_id_array = ds_delete_param($feedback_id);
+        $condition = array(array('fb_id' ,'in', $feedback_id_array));
+        $result = $feedback_model->delFeedback($condition);
+        if ($result){
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+    protected function getAdminItemList() {
+        $menu = array(
+            array(
+                'text' => lang('ds_feedback'), 'name' => 'index', 'url' => ''
+            ),
+        );
+        return $menu;
+    }
+}

+ 138 - 0
app/admin/controller/Flea.php

@@ -0,0 +1,138 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Flea extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/flea.lang.php');
+        if (config('ds_config.flea_isuse') != 1 ){
+            $this->error(lang('flea_index_unable'),'dashboard/welcome');
+        }
+    }
+    /**
+     * 商品管理
+     */
+    public function flea(){
+        $flea_model = model('flea');
+        /**
+         * 排序
+         */
+        $special_condition = array();
+        $keyword = trim(input('param.search_goods_name'));
+        if($keyword){
+            $special_condition['keyword'] = $keyword;
+        }
+        $like_member_name = trim(input('param.search_store_name'));
+        if($like_member_name){
+            $special_condition['like_member_name'] = $like_member_name;//店铺名称
+        }
+        $search_brand_id = intval(input('param.search_brand_id'));
+        if($search_brand_id){
+            $special_condition['brand_id'] = $search_brand_id;
+        }
+        $cate_id = intval(input('param.cate_id'));
+        if($cate_id){
+            $special_condition['fleaclass_id'] = $cate_id;
+        }
+
+        /**
+         * 分页
+         */
+        $goods_list = $flea_model->getFleaList($special_condition,10);
+        if (is_array($goods_list) and !empty($goods_list)) {
+            foreach ($goods_list as $key => $val) {
+                $goods_list[$key]['goods_image'] = $goods_list[$key]['goods_image'] == '' ? '' : ds_get_pic(ATTACH_MFLEA . '/' . $val['member_id'] , str_replace('_1024', '_240', $val['goods_image']));
+            }
+        }
+        /**
+         * 商品类别
+         */
+        /**
+         * 商品分类
+         */
+        $fleaclass_model = model('fleaclass');
+        $goods_class = $fleaclass_model->getTreeClassList(1);
+
+        View::assign('goods_class',$goods_class);
+        View::assign('goods_list',$goods_list);
+        View::assign('show_page',$flea_model->page_info->render());
+        
+        View::assign('filtered', $special_condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('index');
+        return View::fetch('index');
+    }
+    
+    /**
+     * 闲置商品删除
+     */
+    public function del()
+    {
+        $del_id = input('param.del_id');
+        $del_id_array = ds_delete_param($del_id);
+        if ($del_id_array == FALSE) {
+            ds_json_encode('10001', lang('goods_index_argument_invalid'));
+        }
+        $flea_model = model('flea');
+        $result  = $flea_model->delFlea($del_id_array);
+        
+        if($result){
+            ds_json_encode('10000', lang('goods_index_del_succ'));
+        }else{
+            ds_json_encode('10001', lang('goods_index_choose_del'));
+        }
+    }
+
+
+
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $branch = input('get.branch');
+        $column = input('get.column');
+        $value = trim(input('get.value'));
+        $id = intval(input('get.id'));
+        switch ($branch) {
+            /**
+             * 商品名称
+             */
+            case 'goods_name':
+                $flea_model = model('flea');
+                $update_array = array();
+                $update_array[$column] = $value;
+                $flea_model->editFlea($update_array, array('goods_id'=>$id));
+                echo 'true';
+                exit;
+                break;
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('flea_all_ldle'), 'url' => (string)url('Flea/flea')
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 495 - 0
app/admin/controller/Fleaclass.php

@@ -0,0 +1,495 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Fleaclass extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/flea.lang.php');
+    }
+    
+    public function goods_class(){
+        $this->flea_class();
+    }
+    /**
+     * 分类管理
+     */
+    public function flea_class(){
+        $fleaclass_model = model('fleaclass');
+        /**
+         * 删除,编辑
+         */
+        if (request()->isPost()){
+            /**
+             * 删除
+             */
+            $check_fleaclass_id_array = input('post.check_fleaclass_id/a');#获取数组
+            if (input('post.submit_type') == 'del'){
+                if (!empty($check_fleaclass_id_array)){
+                    if (is_array($check_fleaclass_id_array)){
+                        $del_array = $fleaclass_model->getChildClass($check_fleaclass_id_array);
+                        if (is_array($del_array)){
+                            foreach ($del_array as $k => $v){
+                                $fleaclass_model->delFleaclass($v['fleaclass_id']);
+                            }
+                        }
+                    }
+                    $this->success(lang('goods_class_index_del_succ'));
+                }else {
+                   $this->error(lang('goods_class_index_choose_del'));
+                }
+            }
+            /**
+             * 编辑
+             */
+            if (input('post.submit_type') == 'brach_edit'){
+                if (!empty($check_fleaclass_id_array)){
+                    View::assign('id',implode(',',$check_fleaclass_id_array));
+                    $this->setAdminCurItem('brach_edit');
+                    return View::fetch('brach_edit');
+                }else {
+                   $this->error(lang('goods_class_index_choose_edit'));
+                }
+            }
+            /**
+             * 首页显示
+             */
+            if(input('post.submit_type') == 'index_show' or input('post.submit_type') == 'index_hide'){
+                if (!empty($check_fleaclass_id_array)){
+                    if (is_array($check_fleaclass_id_array)){
+                        $param	= array();
+                        $param['fleaclass_index_show']	= input('post.submit_type') == 'index_show'?'1':'0';
+                        foreach ($check_fleaclass_id_array as $k=>$v){
+                            $fleaclass_model->editFleaclass(array('fleaclass_id'=>$v),$param);
+                        }
+                    }
+                    $this->success(lang('goods_class_index_in_homepage').(input('post.submit_type') == 'index_show'?lang('goods_class_index_display'):lang('goods_class_index_hide')).lang('goods_class_index_succ'));
+                }else {
+                    $this->error(lang('goods_class_index_choose_in_homepage').(input('post.submit_type') == 'index_show'?lang('goods_class_index_display'):lang('goods_class_index_hide')).lang('goods_class_index_content'));
+                }
+            }
+        }
+        /**
+         * 父ID
+         */
+        $parent_id = input('fleaclass_parent_id')?input('fleaclass_parent_id'):0;
+        /**
+         * 列表
+         */
+        $tmp_list = $fleaclass_model->getTreeClassList(4);
+        $class_list=array();
+        if (is_array($tmp_list)){
+            foreach ($tmp_list as $k => $v){
+                if ($v['fleaclass_parent_id'] == $parent_id){
+                    /**
+                     * 判断是否有子类
+                     */
+                    if (isset($tmp_list[$k+1]) && ($tmp_list[$k+1]['deep'] > $v['deep'])){
+                        $v['have_child'] = 1;
+                    }else{
+                        $v['have_child'] = 0;
+                    }
+                    $class_list[] = $v;
+                }
+            }
+        }
+        if (input('ajax') == '1'){
+            $output = json_encode($class_list);
+            print_r($output);
+            exit;
+        }else {
+            View::assign('class_list',$class_list);
+            $this->setAdminCurItem('index');
+            return View::fetch('index');
+        }
+    }
+
+    /**
+     * 保存批量修改分类
+     */
+    public function brach_edit_save(){
+        if (input('post.fleaclass_show') == '-1'){
+            $this->success(lang('goods_class_batch_edit_succ'),'fleaclass/flea_class');
+        }
+        if (request()->isPost()){
+            $fleaclass_model = model('fleaclass');
+
+            $array = explode(',',input('post.id'));
+            if (is_array($array)){
+                foreach ($array as $k => $v){
+                    $update_array = array();
+                    $update_array['fleaclass_show'] = input('post.fleaclass_show');
+                    $fleaclass_model->editFleaclass(array('fleaclass_id'=>$v),$update_array);
+                }
+                $this->success(lang('goods_class_batch_edit_succ'));
+            }else {
+                $this->success(lang('goods_class_batch_edit_wrong_content'));
+            }
+        }else {
+            $this->success(lang('goods_class_batch_edit_wrong_content'));
+        }
+    }
+    /**
+     * 商品分类添加
+     */
+    public function goods_class_add(){
+        $fleaclass_model = model('fleaclass');
+        if (request()->isPost()){
+            /**
+             * 验证
+             */
+            $data=[
+                'fleaclass_name' =>input('post.fleaclass_name'),
+                'fleaclass_sort'  =>input('post.fleaclass_sort')
+            ];
+            $fleaclass_validate = ds_validate('fleaclass');
+            if (!$fleaclass_validate->scene('goods_class_add')->check($data)){
+                $this->error($fleaclass_validate->getError());
+            }else {
+
+                $insert_array = array();
+                $insert_array['fleaclass_name'] = input('post.fleaclass_name');
+                $insert_array['fleaclass_parent_id'] = input('post.fleaclass_parent_id');
+                $insert_array['fleaclass_sort'] = input('post.fleaclass_sort');
+                $insert_array['fleaclass_show'] = input('post.fleaclass_show');
+                $insert_array['fleaclass_index_show'] = input('post.fleaclass_index_show');
+
+                $result = $fleaclass_model->addFleaclass($insert_array);
+                if ($result){
+                    dsLayerOpenSuccess(lang('goods_class_add_succ'));
+                }else {
+                   $this->error(lang('goods_class_add_fail'));
+                }
+            }
+        }
+        /**
+         * 父类列表,只取到第三级
+         */
+        $parent_list = $fleaclass_model->getTreeClassList(3);
+        if (is_array($parent_list)){
+            foreach ($parent_list as $k => $v){
+                $parent_list[$k]['fleaclass_name'] = str_repeat("&nbsp;",$v['deep']*2).$v['fleaclass_name'];
+            }
+        }
+
+        View::assign('fleaclass_parent_id',input('fleaclass_parent_id'));
+        View::assign('parent_list',$parent_list);
+        $this->setAdminCurItem('add');
+        return View::fetch('add');
+    }
+
+    /**
+     * 编辑
+     */
+    public function goods_class_edit() {
+
+        $fleaclass_model = model('fleaclass');
+        if (request()->isPost()) {
+                /**
+                 * 验证
+                 */
+                $data = [
+                    'fleaclass_name' => input('post.fleaclass_name'),
+                    'fleaclass_sort' => input('post.fleaclass_sort')
+                ];
+
+                $fleaclass_validate = ds_validate('fleaclass');
+                 if (!$fleaclass_validate->scene('goods_class_edit')->check($data)){
+                    $this->error($fleaclass_validate->getError());
+                } else {
+
+                    $update_array = array();
+                    $update_array['fleaclass_name'] = input('post.fleaclass_name');
+
+                    $fleaclass_parent_id = intval(input('post.fleaclass_parent_id'));
+                    if ($fleaclass_parent_id) {
+                        $update_array['fleaclass_parent_id'] = $fleaclass_parent_id;
+                    }
+                    $update_array['fleaclass_sort'] = input('post.fleaclass_sort');
+                    $update_array['fleaclass_show'] = input('post.fleaclass_show');
+                    $update_array['fleaclass_index_show'] = input('post.fleaclass_index_show');
+
+                    $result = $fleaclass_model->editFleaclass(array('fleaclass_id'=>input('post.fleaclass_id')),$update_array);
+                    if ($result) {
+                        dsLayerOpenSuccess(lang('goods_class_batch_edit_ok'));
+                    } else {
+                        $this->error(lang('goods_class_batch_edit_fail'));
+                    }
+                }
+        } else {
+            $class_array = $fleaclass_model->getOneFleaclass(input('param.fleaclass_id'));
+            if (empty($class_array)) {
+                $this->error(lang('goods_class_batch_edit_paramerror'));
+            }
+
+            /**
+             * 父类列表,只取到第三级
+             */
+            $parent_list = $fleaclass_model->getTreeClassList(3);
+            if (is_array($parent_list)) {
+                $unset_sign = false;
+                foreach ($parent_list as $k => $v) {
+                    if ($v['fleaclass_id'] == $class_array['fleaclass_id']) {
+                        $deep = $v['deep'];
+                        $unset_sign = true;
+                    }
+                    if ($unset_sign == true) {
+                        if ($v['deep'] == $deep && $v['fleaclass_id'] != $class_array['fleaclass_id']) {
+                            $unset_sign = false;
+                        }
+                        if ($v['deep'] > $deep || $v['fleaclass_id'] == $class_array['fleaclass_id']) {
+                            unset($parent_list[$k]);
+                        }
+                    } else {
+                        $parent_list[$k]['fleaclass_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['fleaclass_name'];
+                    }
+                }
+            }
+
+            View::assign('parent_list', $parent_list);
+            View::assign('class_array', $class_array);
+            $this->setAdminCurItem('add');
+            return View::fetch('edit');
+        }
+    }
+
+    /**
+     * 分类导入
+     */
+    public function goods_class_import(){
+        /**
+         * 实例化模型
+         */
+        $fleaclass_model = model('fleaclass');
+        /**
+         * 导入
+         */
+        if (request()->isPost()){
+            /**
+             * 得到导入文件后缀名
+             */
+            $csv_name=explode('.',$_FILES['csv']['name']);
+            $file_type = end($csv_name);
+            if (!empty($_FILES['csv']) && !empty($_FILES['csv']['name']) && $file_type == 'csv'){
+                $fp = @fopen($_FILES['csv']['tmp_name'],'rb');
+                /**
+                 * 父ID
+                 */
+                $parent_id_1 = 0;
+
+                while (!feof($fp)) {
+                    $data = fgets($fp, 4096);
+                    switch (strtoupper(input('post.charset'))){
+                        case 'UTF-8':
+                            if (strtoupper(CHARSET) !== 'UTF-8'){
+                                $data = iconv('UTF-8',strtoupper(CHARSET),$data);
+                            }
+                            break;
+                        case 'GBK':
+                            if (strtoupper(CHARSET) !== 'GBK'){
+                                $data = iconv('GBK',strtoupper(CHARSET),$data);
+                            }
+                            break;
+                    }
+
+                    if (!empty($data)){
+                        $data	= str_replace('"','',$data);
+                        /**
+                         * 逗号去除
+                         */
+                        $tmp_array = array();
+                        $tmp_array = explode(',',$data);
+                        if($tmp_array[0] == 'sort_order')continue;
+                        /**
+                         * 第一位是序号,后面的是内容,最后一位名称
+                         */
+                        $tmp_deep = 'parent_id_'.(count($tmp_array)-1);
+
+                        $insert_array = array();
+                        $insert_array['fleaclass_sort'] = $tmp_array[0];
+                        $insert_array['fleaclass_parent_id'] = $$tmp_deep;
+                        $insert_array['fleaclass_name'] = $tmp_array[count($tmp_array)-1];
+                        $fleaclass_id = $fleaclass_model->addFleaclass($insert_array);
+                        /**
+                         * 赋值这个深度父ID
+                         */
+                        $tmp = 'parent_id_'.count($tmp_array);
+                        $$tmp = $fleaclass_id;
+                    }
+                }
+                /**
+                 * 重新生成缓存
+                 */
+                $this->success(lang('goods_class_import_succ'),'fleaclass/flea_class');
+            }else {
+                $this->error(lang('goods_class_import_csv_null'));
+            }
+        }
+        $this->setAdminCurItem('import');
+        return View::fetch('import');
+    }
+
+    /**
+     * 分类导出
+     */
+    public function goods_class_export() {
+        /**
+         * 导出
+         */
+        if (request()->isPost()) {
+            /**
+             * 实例化模型
+             */
+            $fleaclass_model = model('fleaclass');
+            /**
+             * 分类信息
+             */
+            $class_list = $fleaclass_model->getTreeClassList();
+
+            @header("Content-type: application/unknown");
+            @header("Content-Disposition: attachment; filename=flea_class.csv");
+            if (is_array($class_list)) {
+                foreach ($class_list as $k => $v) {
+                    $tmp = array();
+                    /**
+                     * 序号
+                     */
+                    $tmp['fleaclass_sort'] = $v['fleaclass_sort'];
+                    /**
+                     * 深度
+                     */
+                    for ($i = 1; $i <= ($v['deep'] - 1); $i++) {
+                        $tmp[] = '';
+                    }
+                    /**
+                     * 分类名称
+                     */
+                    $tmp['fleaclass_name'] = $v['fleaclass_name'];
+                    /**
+                     * 转码 utf-gbk
+                     */
+                    if (strtoupper(CHARSET) == 'UTF-8') {
+                        switch (input('post.if_convert')) {
+                            case '1':
+                                $tmp_line = iconv('UTF-8', 'GB2312//IGNORE', join(',', $tmp));
+                                break;
+                            case '0':
+                                $tmp_line = join(',', $tmp);
+                                break;
+                        }
+                    } else {
+                        $tmp_line = join(',', $tmp);
+                    }
+                    $tmp_line = str_replace("\r\n", '', $tmp_line);
+                    echo $tmp_line . "\r\n";
+                }
+            }
+            exit;
+        } else {
+            $this->setAdminCurItem('export');
+            return View::fetch('export');
+        }
+    }
+
+    /**
+     * 删除分类
+     */
+    public function goods_class_del(){
+        $fleaclass_model = model('fleaclass');
+        $fleaclass_id = input('get.fleaclass_id');
+        if ($fleaclass_id > 0){
+            /* 删除分类 */
+            $fleaclass_model->delFleaclass($fleaclass_id);
+            ds_json_encode(10000, lang('goods_class_index_del_succ'));
+        }else {
+            ds_json_encode(10001, lang('goods_class_index_choose_del'));
+        }
+    }
+    /**
+     * ajax操作
+     */
+    public function ajax(){
+        switch (input('branch')){
+            /**
+             * 验证是否有重复的名称
+             */
+            case 'goods_class_name':
+                $fleaclass_model = model('fleaclass');
+                $class_array = $fleaclass_model->getOneFleaclass(input('id'));
+                $condition = array();
+                $condition[] = array('fleaclass_name','=',input('param.value'));
+                $condition[] = array('fleaclass_parent_id','=',$class_array['fleaclass_parent_id']);
+                $condition[] = array('fleaclass_id','not in',input('param.id'));
+                $class_list = $fleaclass_model->getFleaclassList($condition);
+                if (empty($class_list)){
+                    $update_array = array();
+                    $update_array['fleaclass_name'] = input('value');
+                    $fleaclass_model->editFleaclass(array('fleaclass_id'=> intval(input('param.id'))),$update_array);
+                    echo 'true';exit;
+                }else {
+                    echo 'false';exit;
+                }
+                break;
+            /**
+             * 分类 排序 显示 设置
+             */
+            case 'goods_class_sort':
+            case 'goods_class_show':
+            case 'goods_class_index_show':
+                $fleaclass_model = model('fleaclass');
+                $update_array = array();
+                $update_array[input('column')] = input('value');
+                $fleaclass_model->editFleaclass(array('fleaclass_id'=>intval(input('param.id'))),$update_array);
+                echo 'true';exit;
+                break;
+            /**
+             * 添加、修改操作中 检测类别名称是否有重复
+             */
+            case 'check_class_name':
+                $fleaclass_model = model('fleaclass');
+                $condition = array();
+                $condition[] = array('fleaclass_name','=',input('param.fleaclass_name'));
+                $condition[] = array('fleaclass_parent_id','=',input('param.fleaclass_parent_id'));
+                $condition[] = array('fleaclass_id','not in',input('param.fleaclass_id'));
+                $class_list = $fleaclass_model->getFleaclassList($condition);
+                if (empty($class_list)){
+                    echo 'true';exit;
+                }else {
+                    echo 'false';exit;
+                }
+                break;
+        }
+    }
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string)url('Fleaclass/flea_class')
+            ),
+            array(
+                'name' => 'add', 'text' => lang('ds_add'), 'url' => "javascript:dsLayerOpen('".(string)url('Fleaclass/goods_class_add')."','".lang('ds_add')."')"
+            ),
+            array(
+                'name' => 'export', 'text' => lang('ds_export'), 'url' => (string)url('Fleaclass/goods_class_export')
+            ),
+            array(
+                'name' => 'import', 'text' => lang('ds_import'), 'url' => (string)url('Fleaclass/goods_class_import')
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 80 - 0
app/admin/controller/Fleaclassindex.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Fleaclassindex extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/flea.lang.php');
+    }
+    /**
+     * 设置
+     */
+    public function flea_class_index() {
+
+
+        /**
+         * 实例化商品分类模型
+         */
+        $fleaclass_model = model('fleaclass');
+        $goods_class = $fleaclass_model->getTreeClassList(1);
+        View::assign('goods_class', $goods_class);
+        /**
+         * 获取设置信息
+         */
+        $fc_index = $fleaclass_model->getFleaclassindex(array());
+        if (is_array($fc_index) && !empty($fc_index)) {
+            foreach ($fc_index as $value) {
+                View::assign($value['fcindex_code'], $value);
+            }
+        }
+        if (request()->isPost()) {
+            $a = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'shuma', 'fcindex_id1' => input('post.shuma_cid1'), 'fcindex_id2' => input('post.shuma_cid2'), 'fcindex_id3' => input('post.shuma_cid3'), 'fcindex_id4' => input('post.shuma_cid4')));
+            $b = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'zhuangban', 'fcindex_id1' => input('post.zhuangban_cid1'), 'fcindex_id2' => input('post.zhuangban_cid2'), '' => input('post.fcindex_id3'), 'fcindex_id4' => input('post.zhuangban_cid4')));
+            $c = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'jujia', 'fcindex_id1' => input('post.jujia_cid1'), 'fcindex_id2' => input('post.jujia_cid2'), 'fcindex_id3' => input('post.jujia_cid3'), 'fcindex_id4' => input('post.jujia_cid4')));
+            $d = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'xingqu', 'fcindex_id1' => input('post.xingqu_cid1'), 'fcindex_id2' => input('post.xingqu_cid2'), 'fcindex_id3' => input('post.xingqu_cid3'), 'fcindex_id4' => input('post.xingqu_cid4')));
+            $e = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'muying', 'fcindex_id1' => input('post.muying_cid1'), 'fcindex_id2' => input('post.muying_cid2'), 'fcindex_id3' => input('post.muying_cid3'), 'fcindex_id4' => input('post.muying_cid4')));
+            if ($a && $b && $c && $d && $e) {
+                $a = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'shuma', 'fcindex_name1' => input('post.shuma_cname1'), 'fcindex_name2' => input('post.shuma_cname2'), 'fcindex_name3' => input('post.shuma_cname3'), 'fcindex_name4' => input('post.shuma_cname4')));
+                $b = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'zhuangban', 'fcindex_name1' => input('post.zhuangban_cname1'), 'fcindex_name2' => input('post.zhuangban_cname2'), 'fcindex_name3' => input('post.zhuangban_cname3'), 'fcindex_name4' => input('post.zhuangban_cname4')));
+                $c = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'jujia', 'fcindex_name1' => input('post.jujia_cname1'), 'fcindex_name2' => input('post.jujia_cname2'), 'fcindex_name3' => input('post.jujia_cname3'), 'fcindex_name4' => input('post.jujia_cname4')));
+                $d = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'xingqu', 'fcindex_name1' => input('post.xingqu_cname1'), 'fcindex_name2' => input('post.xingqu_cname2'), 'fcindex_name3' => input('post.xingqu_cname3'), 'fcindex_name4' => input('post.xingqu_cname4')));
+                $e = $fleaclass_model->setFleaclassindex(array('fcindex_code' => 'muying', 'fcindex_name1' => input('post.muying_cname1'), 'fcindex_name2' => input('post.muying_cname2'), 'fcindex_name3' => input('post.muying_cname3'), 'fcindex_name4' => input('post.muying_cname4')));
+                if ($a && $b && $c && $d && $e) {
+                    $this->success(lang('flea_class_setting_ok'));
+                }
+            } else {
+                $this->error(lang('flea_class_setting_error'));
+            }
+        } else {
+            $this->setAdminCurItem('flea_class_index');
+            return View::fetch('flea_class_index');
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'flea_class_index', 'text' => lang('flea_index_class_setting_info'), 'url' => (string)url('Fleaclassindex/flea_class_index')
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 237 - 0
app/admin/controller/Flearegion.php

@@ -0,0 +1,237 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Flearegion extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/region.lang.php');
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/flea.lang.php');
+    }
+    /**
+     * 地区列表
+     *
+     * @param
+     * @return
+     */
+    public function flea_region() {
+        /**
+         * 实例化模型
+         */
+        $fleaarea_model = model('fleaarea');
+        /**
+         * 增加 修改 地区信息
+         */
+        if (request()->isPost()) {
+            /**
+             * 是否生成缓存的标识
+             */
+            $new_cache = true;
+            /**
+             * 新增地区
+             */
+            $new_area_name_array = input('post.new_area_name/a');#获取数组
+            if (is_array($new_area_name_array) && !empty($new_area_name_array)) {
+                foreach ($new_area_name_array as $k => $v) {
+                    if (!empty($v)) {
+                        $insert_array = array();
+                        $insert_array['fleaarea_name'] = $v;
+                        $insert_array['fleaarea_parent_id'] = input('post.fleaarea_parent_id');
+                        $insert_array['fleaarea_sort'] = intval($new_area_name_array[$k]);
+                        $insert_array['fleaarea_deep'] = input('post.child_area_deep');
+                        $fleaarea_model->addFleaarea($insert_array);
+                        $new_cache = true;
+                    }
+                }
+            }
+            /**
+             * 修改地区
+             */
+            $area_name_array = input('post.area_name/a');#获取数组
+            if (is_array($area_name_array) && !empty($area_name_array)) {
+                foreach ($area_name_array as $k => $v) {
+                    if (!empty($v)) {
+                        $insert_array = array();
+                        $insert_array['fleaarea_name'] = $v;
+                        $insert_array['fleaarea_sort'] = intval($area_name_array[$k]);
+                        $fleaarea_model->editFleaarea(array('fleaarea_id'=>$k),$insert_array);
+                        $new_cache = true;
+                    }
+                }
+            }
+            /**
+             * 删除地区
+             */
+            $hidden_del_id = input('post.hidden_del_id');
+            if (!empty($hidden_del_id)) {
+                $hidden_del_id = trim($hidden_del_id, '|');
+                $del_id = explode('|', $hidden_del_id);
+                $fleaarea_model->delFleaarea($del_id, input('post.child_area_deep'));
+                $new_cache = true;
+            }
+
+            /**
+             * 更新缓存
+             */
+            if ($new_cache === true) {
+                \fleacache::getCache('flea_area', array('deep' => input('post.child_area_deep'), 'new' => '1'));
+            }
+
+            $this->success(lang('region_index_modify_succ'));
+        } else {
+            /**
+             * 导航地区内容
+             */
+            /**
+             * 一级
+             */
+            $province_list = \fleacache::getCache('flea_area', array('deep' => '1'));
+            $child_area_deep = 1;
+            /**
+             * 二级
+             */
+            $city_list = array();
+            $district_list = array();
+            if (input('param.province')) {
+                $cache_data = \fleacache::getCache('flea_area', array('deep' => '2'));
+                if (is_array($cache_data)) {
+
+                    foreach ($cache_data as $k => $v) {
+                        if ($v['fleaarea_parent_id'] == intval(input('param.province'))) {
+                            $city_list[] = $v;
+                        }
+                    }
+                }
+                unset($cache_data);
+                $child_area_deep = 2;
+                /**
+                 * 三级
+                 */
+                if (input('param.city')) {
+                    $cache_data = \fleacache::getCache('flea_area', array('deep' => '3'));
+                    if (is_array($cache_data)) {
+
+                        foreach ($cache_data as $k => $v) {
+                            if ($v['fleaarea_parent_id'] == intval(input('param.city'))) {
+                                $district_list[] = $v;
+                            }
+                        }
+                    }
+                    unset($cache_data);
+                    $child_area_deep = 3;
+                    /**
+                     * 四级
+                     */
+                    if (input('param.district')) {
+                        $child_area_deep = 4;
+                    }
+                }
+            }
+            /**
+             * 地区列表
+             */
+            $condition = array();
+            $fleaarea_parent_id = input('param.fleaarea_parent_id') ? input('param.fleaarea_parent_id') : '0';
+            $condition[] = array('fleaarea_parent_id','=',$fleaarea_parent_id);
+            $area_list = $fleaarea_model->getFleaareaList($condition);
+            View::assign('province', input('param.province') ? input('param.province') : '');
+            View::assign('city', input('param.city'));
+            View::assign('district', input('param.district'));
+
+            View::assign('province_list', $province_list);
+            View::assign('city_list', $city_list);
+            View::assign('district_list', $district_list);
+            View::assign('fleaarea_parent_id', input('param.fleaarea_parent_id') ? input('param.fleaarea_parent_id') : '0');
+            View::assign('area_list', $area_list);
+            View::assign('child_area_deep', $child_area_deep);
+            $this->setAdminCurItem('index');
+            return View::fetch('index');
+        }
+    }
+
+
+    /**
+     * 导入默认地区
+     *
+     * @param
+     * @return
+     */
+    public function flea_import_default_area() {
+        $file = PUBLIC_PATH.'/examples/flea_area.sql';
+        if (!is_file($file)){
+            ds_json_encode(10001, lang('region_import_csv_null'));
+        }
+
+        $handle = @fopen($file, "r");
+        $tmp_sql = '';
+        if ($handle) {
+
+            Db::query("TRUNCATE TABLE `".config('database.connections.mysql.prefix')."fleaarea`");
+            while (!feof($handle)) {
+
+                $buffer = fgets($handle);
+                if (trim($buffer) != ''){
+                    $tmp_sql .= $buffer;
+                    if (substr(rtrim($buffer),-1) == ';'){
+                        if (preg_match('/^(INSERT)\s+(INTO)\s+/i', ltrim($tmp_sql)) && substr(rtrim($buffer),-2) == ');'){
+                            //标准的SQL语句,将被执行
+                        }else{
+                            //不能组成标准的SQL语句,继续向下一行取内容,直到组成合法的SQL为止
+                            continue;
+                        }
+                        if (!empty($tmp_sql)){
+                            if (strtoupper(CHARSET) == 'GBK'){
+                                $tmp_sql = iconv('UTF-8',strtoupper(CHARSET),$tmp_sql);
+                            }
+                            $tmp_sql = str_replace("`#__fleaarea`","`".config('database.connections.mysql.prefix')."fleaarea`",$tmp_sql);
+                            Db::query($tmp_sql);
+                            $tmp_sql = '';
+                        }
+                    }
+                }
+            }
+            @fclose($handle);
+            /**
+             * 重新生成缓存
+             */
+            for ($i=1;$i<=4;$i++){
+                $tmp = 'flea_area_parent_id_'.$i;
+                if (isset($$tmp) && intval($$tmp) >= 0){
+                    \fleacache::getCache('flea_area',array('deep'=>intval($i),'new'=>'1'));
+                }
+            }
+            ds_json_encode(10000, lang('region_import_succ'));
+        }else {
+            ds_json_encode(10001, lang('region_import_csv_null'));
+        }
+    }
+    
+    
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string)url('Flearegion/flea_region')
+            ),
+            array(
+                'name' => 'import', 'text' => lang('flea_region_import'), 'url' => "javascript:dsLayerConfirm('".(string)url('Flearegion/flea_import_default_area')."','".lang('import_confirm')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 178 - 0
app/admin/controller/Fleaseo.php

@@ -0,0 +1,178 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Fleaseo extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/flea.lang.php');
+        if (config('ds_config.flea_isuse') != '1') {
+            $this->error(lang('flea_isuse_off_tips'), 'dashboard/welcome');
+        }
+    }
+
+    function index() {
+        /**
+         * 实例化模型
+         */
+        $config_model = model('config');
+        /**
+         * 保存信息
+         */
+        if (request()->isPost()) {
+            $update_array = array();
+            $update_array['flea_site_title'] = trim(input('post.flea_site_title'));
+            $update_array['flea_site_description'] = trim(input('post.flea_site_description'));
+            $update_array['flea_site_keywords'] = trim(input('post.flea_site_keywords'));
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            /**
+             * 读取设置内容 $list_setting
+             */
+            $list_setting = rkcache('config', true);
+            /**
+             * 模板输出
+             */
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('index');
+            return View::fetch('index');
+        }
+    }
+
+    /**
+     * 闲置首页广告
+     */
+    public function adv_manage() {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $input = array();
+            //上传图片
+            $file_name = 'flea_1.jpg';
+            if (!empty($_FILES['adv_pic1']['name'])) {
+                $res=ds_upload_pic(ATTACH_PATH,'adv_pic1',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $input[1]['pic'] = $file_name;
+                    $input[1]['url'] = input('post.adv_url1');
+                }else{
+                    $this->error($res['msg']);
+                }
+            } elseif (input('post.old_adv_pic1') != '') {
+                $input[1]['pic'] = input('post.old_adv_pic1');
+                $input[1]['url'] = input('post.adv_url1');
+            }
+            if (!empty($_FILES['adv_pic2']['name'])) {
+                $file_name = 'flea_2.jpg';
+                $res=ds_upload_pic(ATTACH_PATH,'adv_pic2',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $input[2]['pic'] = $file_name;
+                    $input[2]['url'] = input('post.adv_url2');
+                }else{
+                    $this->error($res['msg']);
+                }
+            } elseif (input('post.old_adv_pic2') != '') {
+                $input[2]['pic'] = input('post.old_adv_pic2');
+                $input[2]['url'] = input('post.adv_url2');
+            }
+            if (!empty($_FILES['adv_pic3']['name'])) {
+                $file_name = 'flea_3.jpg';
+
+                $res=ds_upload_pic(ATTACH_PATH,'adv_pic3',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $input[3]['pic'] = $file_name;
+                    $input[3]['url'] = input('post.adv_url3');
+                }else{
+                    $this->error($res['msg']);
+                }
+            } elseif (input('post.old_adv_pic3') != '') {
+                $input[3]['pic'] = input('post.old_adv_pic3');
+                $input[3]['url'] = input('post.adv_url3');
+            }
+
+            if (!empty($_FILES['adv_pic4']['name'])) {
+                $file_name = 'flea_4.jpg';
+                $res=ds_upload_pic(ATTACH_PATH,'adv_pic4',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $input[4]['pic'] = $file_name;
+                    $input[4]['url'] = input('post.adv_url4');
+                }else{
+                    $this->error($res['msg']);
+                }
+            } elseif (input('post.old_adv_pic4') != '') {
+                $input[4]['pic'] = input('post.old_adv_pic4');
+                $input[4]['url'] = input('post.adv_url4');
+            }
+
+            if (!empty($_FILES['adv_pic5']['name'])) {
+                $file_name = 'flea_5.jpg';
+                $res=ds_upload_pic(ATTACH_PATH,'adv_pic5',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $input[5]['pic'] = $file_name;
+                    $input[5]['url'] = input('post.adv_url5');
+                }else{
+                    $this->error($res['msg']);
+                }
+            } elseif (input('post.old_adv_pic4') != '') {
+                $input[5]['pic'] = input('post.old_adv_pic5');
+                $input[5]['url'] = input('post.adv_url5');
+            }
+            $update_array = array();
+            if (count($input) > 0) {
+                $update_array['flea_loginpic'] = serialize($input);
+            }
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('loginSettings'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('loginSettings'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            if ($list_setting['flea_loginpic'] != '') {
+                $adv_list = unserialize($list_setting['flea_loginpic']);
+            } else {
+                $adv_list = '';
+            }
+            View::assign('adv_list', $adv_list);
+            return View::fetch('adv');
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('flea_seo'), 'url' => (string) url('Fleaseo/index')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 283 - 0
app/admin/controller/Goods.php

@@ -0,0 +1,283 @@
+<?php
+
+/**
+ * 商品管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Goods extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/goods.lang.php');
+    }
+
+    /**
+     * 商品管理
+     */
+    public function index() {
+        $goods_model = model('goods');
+        /**
+         * 处理商品分类
+         */
+        $choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
+        $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
+        View::assign('gc_json', json_encode($gccache_arr['showclass']));
+        View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
+
+        /**
+         * 查询条件
+         */
+        $where = array();
+        $search_goods_name = trim(input('param.search_goods_name'));
+        if ($search_goods_name != '') {
+            $where[]=array('goods_name','like', '%' . $search_goods_name . '%');
+        }
+        $search_commonid = intval(input('param.search_commonid'));
+        if ($search_commonid > 0) {
+            $where[]=array('goods_commonid','=',$search_commonid);
+        }
+        $search_store_name = trim(input('param.search_store_name'));
+        if ($search_store_name != '') {
+            $where[]=array('store_name','like', '%' .$search_store_name . '%');
+        }
+        $b_id = intval(input('param.b_id'));
+        if ($b_id > 0) {
+            $where[]=array('brand_id','=',$b_id);
+        }
+        if ($choose_gcid > 0) {
+            $where[] = array('gc_id_' . ($gccache_arr['showclass'][$choose_gcid]['depth']),'=',$choose_gcid);
+        }
+
+        $type = input('param.type');
+        switch ($type) {
+            // 禁售
+            case 'lockup':
+                $goods_list = $goods_model->getGoodsCommonLockUpList($where);
+                break;
+            // 等待审核
+            case 'waitverify':
+                $goods_list = $goods_model->getGoodsCommonWaitVerifyList($where, '*', 10, 'goods_verify desc, goods_commonid desc');
+                break;
+            // 全部商品
+            default:
+                //默认所有商品才有此参数
+                $goods_state = input('param.goods_state');
+                if (in_array($goods_state, array('0', '1', '10'))) {
+                    $where[]=array('goods_state','=',$goods_state);
+                }
+                $goods_verify = input('param.goods_verify');
+                if (in_array($goods_verify, array('0', '1', '10'))) {
+                    $where[]=array('goods_verify','=',$goods_verify);
+                }
+                $goods_list = $goods_model->getGoodsCommonList($where, '*', 10, 'mall_goods_commend desc,mall_goods_sort asc');
+                break;
+        }
+
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $goods_model->page_info->render());
+
+        $storage_array = $goods_model->calculateStorage($goods_list);
+        View::assign('storage_array', $storage_array);
+
+        // 品牌
+        $brand_list = model('brand')->getBrandPassedList(array());
+
+        View::assign('search', $where);
+        View::assign('brand_list', $brand_list);
+
+        View::assign('state', array('1' => lang('goods_state_1'), '0' => lang('goods_state_0'), '10' => lang('goods_state_10')));
+
+        View::assign('verify', array('1' => lang('goods_verify_1'), '0' => lang('goods_verify_0'), '10' => lang('goods_verify_10')));
+
+        View::assign('ownShopIds', array_fill_keys(model('store')->getOwnShopIds(), true));
+
+        $type = input('param.type');
+        if(!in_array($type, array('lockup','waitverify','allgoods'))){
+            $type = 'allgoods';
+        }
+        
+        View::assign('type', $type);
+        $this->setAdminCurItem($type);
+        return View::fetch();
+    }
+
+
+    /**
+     * 计算商品库存
+     */
+    public function goods_storage($goods_list) {
+        $goods_model = model('goods');
+        // 计算库存
+        $storage_array = array();
+        if (!empty($goods_list)) {
+            foreach ($goods_list as $value) {
+                $storage_array[$value['goods_commonid']]['goods_storage'] = $goods_model->getGoodsSum(array('goods_commonid'=>$value['goods_commonid']),'goods_storage');
+                $storage_array[$value['goods_commonid']][] = $goods_model->getGoodsInfo(array('goods_commonid'=>$value['goods_commonid']),'goods_id');
+            }
+            return $storage_array;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 违规下架
+     */
+    public function goods_lockup() {
+        if (request()->isPost()) {
+            $commonids = input('param.commonids');
+            $commonid_array = ds_delete_param($commonids);
+            if ($commonid_array == FALSE) {
+                $this->error(lang('ds_common_op_fail'));
+            }
+            
+            $update = array();
+            $update['goods_stateremark'] = trim(input('post.close_reason'));
+
+            $where = array();
+            $where[]=array('goods_commonid','in', $commonid_array);
+
+            model('goods')->editProducesLockUp($update, $where);
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        } else {
+            View::assign('commonids', input('param.commonid'));
+            echo View::fetch('close_remark');
+        }
+    }
+
+    /**
+     * 删除商品
+     */
+    public function goods_del() {
+        $common_id = input('param.common_id');
+        $common_id_array = ds_delete_param($common_id);
+        if ($common_id_array == FALSE) {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+        $condition = array();
+        $condition[]=array('goods_commonid','in',$common_id_array);
+        model('goods')->delGoodsAll($condition);
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 审核商品
+     */
+    public function goods_verify() {
+        if (request()->isPost()) {
+            $commonids = input('param.commonids');
+            $commonid_array = ds_delete_param($commonids);
+            if ($commonid_array == FALSE) {
+                $this->error(lang('ds_common_op_fail'));
+            }
+
+            $update2 = array();
+            $update2['goods_verify'] = intval(input('param.verify_state'));
+
+            $update1 = array();
+            $update1['goods_verifyremark'] = trim(input('param.verify_reason'));
+            $update1 = array_merge($update1, $update2);
+            $where = array();
+            $where[]=array('goods_commonid','in', $commonid_array);
+
+            $goods_model = model('goods');
+            if (intval(input('param.verify_state')) == 0) {
+                $goods_model->editProducesVerifyFail($where, $update1, $update2);
+            } else {
+                $goods_model->editProduces($where, $update1, $update2);
+            }
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        } else {
+            View::assign('commonids', input('param.commonid'));
+            echo View::fetch('verify_remark');
+        }
+    }
+
+    //ajax获取同一个commonid下面的商品信息
+    public function get_goods_list_ajax() {
+        $common_id = input('param.commonid');
+        if (empty($common_id)) {
+            $this->error(lang('param_error'));
+        }
+        $map['goods_commonid'] = $common_id;
+        $goods_model = model('goods');
+        $common_info = $goods_model->getGoodsCommonInfo($map,'spec_name');
+        $goods_list = $goods_model->getGoodsList($map);
+        //halt($goods_list);
+        $spec_name = array_values((array) unserialize($common_info['spec_name']));
+        foreach ($goods_list as $key => $val) {
+            $goods_spec = array_values((array) unserialize($val['goods_spec']));
+            $spec_array = array();
+            foreach ($goods_spec as $k => $v) {
+                $spec_array[] = '<div class="goods_spec">' . $spec_name[$k] . ':' . '<em title="' . $v . '">' . $v . '</em>' . '</div>';
+            }
+            $goods_list[$key]['goods_image'] = goods_cthumb($val['goods_image']);
+            $goods_list[$key]['goods_spec'] = implode('', $spec_array);
+            $goods_list[$key]['url'] = (string)url('home/Goods/index', array('goods_id' => $val['goods_id']));
+        }
+        return json_encode($goods_list);
+    }
+    
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $goods_model = model('goods');
+        switch (input('param.branch')) {
+            case 'mall_goods_commend':
+            case 'mall_goods_sort':
+                if (empty($result)) {
+                    $goods_model->editGoodsCommonById(array(trim(input('param.branch')) => trim(input('param.value'))),array(intval(input('param.id'))));
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'allgoods',
+                'text' => lang('goods_index_all_goods'),
+                'url' => (string)url('Goods/index')
+            ),
+            array(
+                'name' => 'lockup',
+                'text' => lang('goods_index_lock_goods'),
+                'url' => (string)url('Goods/index', ['type' => 'lockup'])
+            ),
+            array(
+                'name' => 'waitverify',
+                'text' => lang('goods_index_waitverify_goods'),
+                'url' => (string)url('Goods/index', ['type' => 'waitverify'])
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 169 - 0
app/admin/controller/Goodsalbum.php

@@ -0,0 +1,169 @@
+<?php
+
+/*
+ * 空间管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Goodsalbum extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/goodsalbum.lang.php');
+    }
+
+    /**
+     * 相册列表
+     */
+    public function index() {
+        $condition = array();
+        $store_name = '';
+        if (is_numeric(input('param.keyword'))) {
+            $store_id = intval(input('param.keyword'));
+            $condition[] = array('s.store_id','=',$store_id);
+            $store_name = ds_getvalue_byname('store', 'store_id', $store_id, 'store_name');
+        } elseif (!empty(input('param.keyword'))) {
+            $store_name = input('param.keyword');
+            $store_id = ds_getvalue_byname('store', 'store_name', $store_name, 'store_id');
+            if (is_numeric($store_id)) {
+                $condition[] = array('s.store_id','=',$store_id);
+            } else {
+                $condition[] = array('s.store_id','=',0);
+            }
+        }
+        $goodsalbum_model = model('album');
+        $albumclass_list = $goodsalbum_model->getGoodsalbumList($condition,10,'a.*,s.store_name');
+        View::assign('show_page', $goodsalbum_model->page_info->render());
+
+        if (is_array($albumclass_list) && !empty($albumclass_list)) {
+            foreach ($albumclass_list as $v) {
+                $class[] = $v['aclass_id'];
+            }
+            $where=array();
+            $where[]=array('aclass_id','in',$class);
+        } else {
+            $where = '1=1';
+        }
+        $count = $goodsalbum_model->getAlbumpicCountlist($where,'aclass_id,count(*) as pcount','aclass_id');
+
+        $pic_count = array();
+        if (is_array($count)) {
+            foreach ($count as $v) {
+                $pic_count[$v['aclass_id']] = $v['pcount'];
+            }
+        }
+        View::assign('pic_count', $pic_count);
+        View::assign('albumclass_list', $albumclass_list);
+        View::assign('store_name', $store_name);
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 图片列表
+     */
+    public function pic_list() {
+        $condition = array();
+        $store_name = '';
+        if (is_numeric(input('param.keyword'))) {
+            $store_id = intval(input('param.keyword'));
+            $condition[] = array('store_id','=',$store_id);
+            $store_name = ds_getvalue_byname('store','store_id',$store_id,'store_name');
+        } elseif ((input('param.keyword'))) {
+            $store_name = input('param.keyword');
+            $store_id = ds_getvalue_byname('store','store_name',$store_name,'store_id');
+            if (is_numeric($store_id)) {
+                $condition[] = array('store_id','=',$store_id);
+            } else {
+                $condition[] = array('store_id','=',0);
+            }
+        } elseif (is_numeric(input('param.aclass_id'))) {
+            $condition[] = array('aclass_id','=',input('param.aclass_id'));
+        }
+        $albumpic_model = model('album');
+        $albumpic_list = $albumpic_model->getAlbumpicList($condition,34,'','apic_id desc');
+        //halt($albumpic_list);
+        $show_page = $albumpic_model->page_info->render();
+        View::assign('show_page', $show_page);
+        View::assign('albumpic_list', $albumpic_list);
+        View::assign('store_name', $store_name);
+        $this->setAdminCurItem('pic_list');
+        return View::fetch();
+    }
+
+    /**
+     * 删除相册
+     */
+    public function aclass_del() {
+        $aclass_id = input('param.aclass_id');
+        $aclass_id_array = ds_delete_param($aclass_id);
+        if ($aclass_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition=array();
+        $condition[]=array('aclass_id','in',$aclass_id_array);
+        $albumpic_model = model('album');
+        //批量删除相册图片
+        $albumpic_model->delAlbumpic($condition);
+        $albumpic_model->delAlbumclass($condition);
+        $this->log(lang('ds_del') . lang('g_album_one') . '[ID:' . intval(input('param.aclass_id')) . ']', 1);
+        ds_json_encode('10000', lang('ds_common_del_succ'));
+    }
+
+    /**
+     * 删除一张图片及其对应记录
+     *
+     */
+    public function del_album_pic() {
+        $apic_id = input('param.apic_id');
+        $apic_id_array = ds_delete_param($apic_id);
+        if ($apic_id_array === FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition=array();
+        $condition[]=array('apic_id','in',$apic_id_array);
+        $albumpic_model = model('album');
+        //批量删除相册图片
+        $albumpic_model->delAlbumpic($condition);
+        $this->log(lang('ds_del') . lang('g_album_pic_one') . '[ID:' . $apic_id . ']', 1);
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('g_album_list'),
+                'url' => (string)url('Goodsalbum/index')
+            ),
+            array(
+                'name' => 'pic_list',
+                'text' => lang('g_album_pic_list'),
+                'url' => (string)url('Goodsalbum/pic_list')
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 688 - 0
app/admin/controller/Goodsclass.php

@@ -0,0 +1,688 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Goodsclass extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/goodsclass.lang.php');
+    }
+
+    /**
+     * 分类管理
+     */
+    public function goods_class() {
+        $goodsclass_model = model('goodsclass');
+        //父ID
+        $parent_id = input('param.gc_parent_id') ? intval(input('param.gc_parent_id')) : 0;
+
+        //列表
+        $tmp_list = $goodsclass_model->getTreeClassList(3);
+        $class_list = array();
+        if (is_array($tmp_list)) {
+            foreach ($tmp_list as $k => $v) {
+                if ($v['gc_parent_id'] == $parent_id) {
+                    //判断是否有子类
+                    if (isset($tmp_list[$k + 1]['deep']) && $tmp_list[$k + 1]['deep'] > $v['deep']) {
+                        $v['have_child'] = 1;
+                    }
+                    $class_list[] = $v;
+                }
+            }
+        }
+
+        if (input('param.ajax') == '1') {
+            $output = json_encode($class_list);
+            echo $output;
+            exit;
+        } else {
+            View::assign('class_list', $class_list);
+            $this->setAdminCurItem('goods_class');
+            return View::fetch('goods_class');
+        }
+    }
+
+    /**
+     * 商品分类添加
+     */
+    public function goods_class_add() {
+        $goodsclass_model = model('goodsclass');
+        if (!request()->isPost()) {
+            //父类列表,只取到第二级
+            $parent_list = $goodsclass_model->getTreeClassList(2);
+            $gc_list = array();
+            if (is_array($parent_list)) {
+                foreach ($parent_list as $k => $v) {
+                    $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
+                    if ($v['deep'] == 1)
+                        $gc_list[$k] = $v;
+                }
+            }
+            View::assign('gc_list', $gc_list);
+            //类型列表
+            $type_model = model('type');
+            $type_list = $type_model->getTypeList(array(), '', 'type_id,type_name,class_id,class_name');
+            $t_list = array();
+            if (is_array($type_list) && !empty($type_list)) {
+                foreach ($type_list as $k => $val) {
+                    $t_list[$val['class_id']]['type'][$k] = $val;
+                    $t_list[$val['class_id']]['name'] = $val['class_name'] == '' ? lang('ds_default') : $val['class_name'];
+                }
+            }
+
+            ksort($t_list);
+
+            View::assign('type_list', $t_list);
+            View::assign('gc_parent_id', input('get.gc_parent_id'));
+            View::assign('parent_list', $parent_list);
+            $this->setAdminCurItem('goods_class_add');
+            return View::fetch('goods_class_add');
+        } else {
+
+            $insert_array = array();
+            $insert_array['gc_name'] = input('post.gc_name');
+            $insert_array['type_id'] = intval(input('post.t_id'));
+            $insert_array['type_name'] = trim(input('post.t_name'));
+            $insert_array['gc_parent_id'] = intval(input('post.gc_parent_id'));
+            $insert_array['commis_rate'] = intval(input('post.commis_rate'));
+            $insert_array['gc_sort'] = intval(input('post.gc_sort'));
+            $insert_array['gc_virtual'] = intval(input('post.gc_virtual'));
+            if (!empty($_FILES['pic']['name'])) {//上传图片
+                $res = ds_upload_pic(ATTACH_COMMON, 'pic');
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $insert_array['gc_image'] = $file_name;
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+            $goods_validate = ds_validate('goods');
+            if (!$goods_validate->scene('goods_class_add')->check($insert_array)) {
+                $this->error($goods_validate->getError());
+            }
+
+            $result = $goodsclass_model->addGoodsclass($insert_array);
+            if ($result) {
+                $this->log(lang('ds_add') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 1);
+                $this->success(lang('ds_common_save_succ'), (string) url('Goodsclass/goods_class'));
+            } else {
+                $this->log(lang('ds_add') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑
+     */
+    public function goods_class_edit() {
+        $goodsclass_model = model('goodsclass');
+        $gc_id = intval(input('param.gc_id'));
+
+        if (!request()->isPost()) {
+            $class_array = $goodsclass_model->getGoodsclassInfoById($gc_id);
+
+            if (empty($class_array)) {
+                $this->error(lang('goods_class_batch_edit_paramerror'));
+            }
+
+            //类型列表
+            $type_model = model('type');
+            $type_list = $type_model->getTypeList(array(), '', 'type_id,type_name,class_id,class_name');
+            $t_list = array();
+            if (is_array($type_list) && !empty($type_list)) {
+                foreach ($type_list as $k => $val) {
+                    $t_list[$val['class_id']]['type'][$k] = $val;
+                    $t_list[$val['class_id']]['name'] = $val['class_name'] == '' ? lang('ds_default') : $val['class_name'];
+                }
+            }
+            ksort($t_list);
+            //父类列表,只取到第二级
+            $parent_list = $goodsclass_model->getTreeClassList(2);
+            if (is_array($parent_list)) {
+                foreach ($parent_list as $k => $v) {
+                    $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
+                }
+            }
+            View::assign('parent_list', $parent_list);
+            // 一级分类列表
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+
+
+            $class_array['pic'] = ds_get_pic(ATTACH_COMMON, $class_array['gc_image']);
+
+
+            View::assign('type_list', $t_list);
+            View::assign('class_array', $class_array);
+            $this->setAdminCurItem('goods_class_edit');
+            return View::fetch('goods_class_edit');
+        } else {
+
+
+            $update_array = array();
+            $update_array['gc_name'] = input('post.gc_name');
+            $update_array['type_id'] = intval(input('post.t_id'));
+            $update_array['type_name'] = trim(input('post.t_name'));
+            $update_array['commis_rate'] = intval(input('post.commis_rate'));
+            $update_array['gc_sort'] = intval(input('post.gc_sort'));
+            $update_array['gc_virtual'] = intval(input('post.gc_virtual'));
+            $update_array['gc_parent_id'] = intval(input('post.gc_parent_id'));
+
+            if (!empty($_FILES['pic']['name'])) {//上传图片
+                $res = ds_upload_pic(ATTACH_COMMON, 'pic');
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $update_array['gc_image'] = $file_name;
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+
+            $goods_validate = ds_validate('goods');
+            if (!$goods_validate->scene('goods_class_edit')->check($update_array)) {
+                $this->error($goods_validate->getError());
+            }
+
+            $parent_class = $goodsclass_model->getGoodsclassInfoById($update_array['gc_parent_id']);
+            if ($parent_class) {
+                if ($parent_class['gc_parent_id'] == $gc_id) {
+                    $this->error(lang('parent_parent_goods_class_equal_self_error'));
+                }
+            }
+            if ($update_array['gc_parent_id'] == $gc_id) {
+                $this->error(lang('parent_goods_class_equal_self_error'));
+            }
+            // 更新分类信息
+            $condition = array();
+            $condition[] = array('gc_id', '=', $gc_id);
+            $result = $goodsclass_model->editGoodsclass($update_array, $condition);
+            if ($result < 0) {
+                $this->log(lang('ds_edit') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 0);
+                $this->error(lang('goods_class_batch_edit_fail'));
+            }
+
+
+            // 检测是否需要关联自己操作,统一查询子分类
+            if (input('post.t_commis_rate') == '1' || input('post.t_associated') == '1' || input('post.t_gc_virtual') == '1') {
+                $gc_id_list = $goodsclass_model->getChildClass($gc_id);
+                $gc_ids = array();
+                if (is_array($gc_id_list) && !empty($gc_id_list)) {
+                    foreach ($gc_id_list as $val) {
+                        $gc_ids[] = $val['gc_id'];
+                    }
+                }
+            }
+
+            // 更新该分类下子分类的所有分佣比例
+            if (input('post.t_commis_rate') == '1' && !empty($gc_ids)) {
+                $goodsclass_model->editGoodsclass(array('commis_rate' => $update_array['commis_rate']), array(array('gc_id', 'in', $gc_ids)));
+            }
+
+
+            // 更新该分类下子分类的所有类型
+            if (input('post.t_associated') == '1' && !empty($gc_ids)) {
+                $where = array();
+                $where[] = array('gc_id', 'in', $gc_ids);
+                $update = array();
+                $update['type_id'] = intval(input('post.t_id'));
+                $update['type_name'] = trim(input('post.t_name'));
+                $goodsclass_model->editGoodsclass($update, $where);
+            }
+
+            // 虚拟商品
+            if (input('post.t_gc_virtual') == '1' && !empty($gc_ids)) {
+                $goodsclass_model->editGoodsclass(array('gc_virtual' => $update_array['gc_virtual']), array(array('gc_id', 'in', $gc_ids)));
+            }
+
+
+            $this->log(lang('ds_edit') . lang('goods_class_index_class') . '[' . input('post.gc_name') . ']', 1);
+            $this->success(lang('goods_class_batch_edit_ok'), (string) url('Goodsclass/goods_class'));
+        }
+    }
+
+    /**
+     * 删除分类
+     */
+    public function goods_class_del() {
+        $gc_id = input('param.gc_id');
+        $gc_id_array = ds_delete_param($gc_id);
+        if ($gc_id_array === FALSE) {
+            $this->log(lang('ds_del') . lang('goods_class_index_class') . '[ID:' . $gc_id . ']', 0);
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $goodsclass_model = model('goodsclass');
+        //删除分类
+        $goodsclass_model->delGoodsclassByGcIdString($gc_id);
+        $this->log(lang('ds_del') . lang('goods_class_index_class') . '[ID:' . $gc_id . ']', 1);
+        ds_json_encode('10000', lang('ds_common_del_succ'));
+    }
+
+    /**
+     * tag列表
+     */
+    public function tag() {
+
+        /**
+         * 处理商品分类
+         */
+        $choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
+        $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
+        View::assign('gc_json', json_encode($gccache_arr['showclass']));
+        View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
+
+        $classtag_model = model('goodsclasstag');
+
+        if (!request()->isPost()) {
+            $condition = array();
+            if ($choose_gcid > 0) {
+                $condition[] = array('gc_id_' . ($gccache_arr['showclass'][$choose_gcid]['depth']), '=', $choose_gcid);
+            }
+            $tag_list = $classtag_model->getGoodsclasstagList($condition, 10);
+            View::assign('tag_list', $tag_list);
+            View::assign('show_page', $classtag_model->page_info->render());
+            $this->setAdminCurItem('tag');
+            return View::fetch('goods_class_tag');
+        } else {
+            //删除
+            if (input('post.submit_type') == 'del') {
+                $tag_id_array = input('post.tag_id/a');
+                if (is_array($tag_id_array) && !empty($tag_id_array)) {
+                    //删除TAG
+                    $classtag_model->delGoodsclasstagByIds(implode(',', $tag_id_array));
+                    $this->log(lang('ds_del') . 'tag[ID:' . implode(',', $tag_id_array) . ']', 1);
+                    $this->success(lang('ds_common_del_succ'));
+                } else {
+                    $this->log(lang('ds_del') . 'tag', 0);
+                    $this->error(lang('ds_common_del_fail'));
+                }
+            }
+        }
+    }
+
+    /**
+     * 重置TAG
+     */
+    public function tag_reset() {
+        //实例化模型
+        $goodsclass_model = model('goodsclass');
+        $classtag_model = model('goodsclasstag');
+
+        //清空TAG
+        $return = $classtag_model->clearGoodsclasstag();
+        // if (!$return) {
+        // $this->error(lang('goods_class_reset_tag_fail_no_class'), (string)url('Goodsclass/tag'));
+        // }
+        //商品分类
+        $goods_class = $goodsclass_model->getTreeClassList(3);
+        //格式化分类。组成三维数组
+        if (is_array($goods_class) and ! empty($goods_class)) {
+            $goods_class_array = array();
+            foreach ($goods_class as $val) {
+                //一级分类
+                if ($val['gc_parent_id'] == 0) {
+                    $goods_class_array[$val['gc_id']]['gc_name'] = $val['gc_name'];
+                    $goods_class_array[$val['gc_id']]['gc_id'] = $val['gc_id'];
+                    $goods_class_array[$val['gc_id']]['type_id'] = $val['type_id'];
+                } else {
+                    //二级分类
+                    if (isset($goods_class_array[$val['gc_parent_id']])) {
+                        $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_name'] = $val['gc_name'];
+                        $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_id'] = $val['gc_id'];
+                        $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_parent_id'] = $val['gc_parent_id'];
+                        $goods_class_array[$val['gc_parent_id']]['sub_class'][$val['gc_id']]['type_id'] = $val['type_id'];
+                    } else {
+                        foreach ($goods_class_array as $v) {
+                            //三级分类
+                            if (isset($v['sub_class'][$val['gc_parent_id']])) {
+                                $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_name'] = $val['gc_name'];
+                                $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['gc_id'] = $val['gc_id'];
+                                $goods_class_array[$v['sub_class'][$val['gc_parent_id']]['gc_parent_id']]['sub_class'][$val['gc_parent_id']]['sub_class'][$val['gc_id']]['type_id'] = $val['type_id'];
+                            }
+                        }
+                    }
+                }
+            }
+
+            $return = $classtag_model->addGoodsclasstag($goods_class_array);
+
+            // if ($return) {
+            $this->log(lang('ds_reset') . 'tag', 1);
+            $this->success(lang('ds_common_op_succ'), (string) url('Goodsclass/tag'));
+            // } else {
+            // $this->log(lang('ds_reset') . 'tag', 0);
+            // $this->error(lang('ds_common_op_fail'), (string)url('Goodsclass/tag'));
+            // }
+        } else {
+            $this->log(lang('ds_reset') . 'tag', 0);
+            $this->error(lang('goods_class_reset_tag_fail_no_class'), (string) url('Goodsclass/tag'));
+        }
+    }
+
+    /**
+     * 更新TAG名称
+     */
+    public function tag_update() {
+        $goodsclass_model = model('goodsclass');
+        $classtag_model = model('goodsclasstag');
+
+        //需要更新的TAG列表
+        $tag_list = $classtag_model->getGoodsclasstagList(array(), '', 'gctag_id,gc_id_1,gc_id_2,gc_id_3');
+        if (is_array($tag_list) && !empty($tag_list)) {
+            foreach ($tag_list as $val) {
+                //查询分类信息
+                $in_gc_id = array();
+                if ($val['gc_id_1'] != '0') {
+                    $in_gc_id[] = $val['gc_id_1'];
+                }
+                if ($val['gc_id_2'] != '0') {
+                    $in_gc_id[] = $val['gc_id_2'];
+                }
+                if ($val['gc_id_3'] != '0') {
+                    $in_gc_id[] = $val['gc_id_3'];
+                }
+                $gc_list = $goodsclass_model->getGoodsclassListByIds($in_gc_id);
+
+                //更新TAG信息
+                $update_tag = array();
+                if (isset($gc_list['0']['gc_id']) && $gc_list['0']['gc_id'] != '0') {
+                    $update_tag['gc_id_1'] = $gc_list['0']['gc_id'];
+                    if (!isset($update_tag['gctag_name'])) {
+                        $update_tag['gctag_name'] = '';
+                    }
+                    $update_tag['gctag_name'] .= $gc_list['0']['gc_name'];
+                }
+                if (isset($gc_list['1']['gc_id']) && $gc_list['1']['gc_id'] != '0') {
+                    $update_tag['gc_id_2'] = $gc_list['1']['gc_id'];
+                    if (!isset($update_tag['gctag_name'])) {
+                        $update_tag['gctag_name'] = '';
+                    }
+                    $update_tag['gctag_name'] .= "&nbsp;&gt;&nbsp;" . $gc_list['1']['gc_name'];
+                }
+                if (isset($gc_list['2']['gc_id']) && $gc_list['2']['gc_id'] != '0') {
+                    $update_tag['gc_id_3'] = $gc_list['2']['gc_id'];
+                    if (!isset($update_tag['gctag_name'])) {
+                        $update_tag['gctag_name'] = '';
+                    }
+                    $update_tag['gctag_name'] .= "&nbsp;&gt;&nbsp;" . $gc_list['2']['gc_name'];
+                }
+                unset($gc_list);
+                $return = $classtag_model->editGoodsclasstag($update_tag, $val['gctag_id']);
+                if (!$return) {
+                    $this->log(lang('ds_update') . 'tag', 0);
+                    $this->error(lang('ds_common_op_fail'), 'Goodsclass/tag');
+                }
+            }
+            $this->log(lang('ds_update') . 'tag', 1);
+            $this->success(lang('ds_common_op_succ'), 'Goodsclass/tag');
+        } else {
+            $this->log(lang('ds_update') . 'tag', 0);
+            $this->error(lang('goods_class_update_tag_fail_no_class'), 'Goodsclass/tag');
+        }
+    }
+
+    /**
+     * 删除TAG
+     */
+    public function tag_del() {
+        $id = intval(input('get.tag_id'));
+        $classtag_model = model('goodsclasstag');
+        if ($id > 0) {
+            //删除TAG
+            $classtag_model->delGoodsclasstagByIds($id);
+            $this->log(lang('ds_del') . 'tag[ID:' . $id . ']', 1);
+            ds_json_encode('10000', lang('ds_common_op_succ'));
+        } else {
+            $this->log(lang('ds_del') . 'tag[ID:' . $id . ']', 0);
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 分类导航
+     */
+    public function nav_edit() {
+        $gc_id = input('param.gc_id');
+        $goodsclass_model = model('goodsclass');
+        $class_info = $goodsclass_model->getGoodsclassInfoById($gc_id);
+        $goodsclassnav_model = model('goodsclassnav');
+        $nav_info = $goodsclassnav_model->getGoodsclassnavInfoByGcId($gc_id);
+
+        if (request()->isPost()) {
+            $update = array();
+            $update['gc_id'] = $gc_id;
+            $update['goodscn_alias'] = input('post.goodscn_alias');
+            $class_id_array = input('post.class_id/a');
+            if(empty($class_id_array)){
+            	$update['goodscn_classids'] = '';
+            }else if (is_array($class_id_array) && !empty($class_id_array)) {
+                $update['goodscn_classids'] = implode(',', $class_id_array);
+            }
+            $brand_id_array = input('post.brand_id/a');
+            if(empty($brand_id_array)){
+            	$update['goodscn_brandids'] = '';
+            }else if (is_array($brand_id_array) && !empty($brand_id_array)) {
+                $update['goodscn_brandids'] = implode(',', $brand_id_array);
+            }
+            $update['goodscn_adv1_link'] = input('post.goodscn_adv1_link');
+            $update['goodscn_adv2_link'] = input('post.goodscn_adv2_link');
+            if (!empty($_FILES['pic']['name'])) {//上传图片
+                @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_pic']);
+                $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
+
+                $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'pic', $file_name);
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $update['goodscn_pic'] = $file_name;
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+            if (!empty($_FILES['adv1']['name'])) {//上传广告图片
+                @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_adv1']);
+                $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
+
+                $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'adv1', $file_name);
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $update['goodscn_adv1'] = $file_name;
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+            if (!empty($_FILES['adv2']['name'])) {//上传广告图片
+                @unlink(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_CLASS . '/' . $nav_info['goodscn_adv2']);
+                $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
+
+                $res = ds_upload_pic(ATTACH_GOODS_CLASS, 'adv2', $file_name);
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $update['goodscn_adv2'] = $file_name;
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+            if (empty($nav_info)) {
+                $result = $goodsclassnav_model->addGoodsclassnav($update);
+            } else {
+                $result = $goodsclassnav_model->editGoodsclassnav($update, $gc_id);
+            }
+            if ($result) {
+                $this->log('编辑分类导航,' . $class_info['gc_name'], 1);
+                $this->success(lang('ds_common_op_succ'));
+            } else {
+                $this->log('编辑分类导航,' . $class_info['gc_name'], 0);
+                $this->success(lang('ds_common_op_succ'));
+            }
+        } else {
+            if (isset($nav_info)) {
+                $nav_info['goodscn_pic'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_pic']);
+                $nav_info['goodscn_adv1'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_adv1']);
+                $nav_info['goodscn_adv2'] = ds_get_pic(ATTACH_GOODS_CLASS, $nav_info['goodscn_adv2']);
+            }
+
+            $nav_info['goodscn_classids'] = isset($nav_info['goodscn_classids']) ? explode(',', $nav_info['goodscn_classids']) : array();
+            $nav_info['goodscn_brandids'] = isset($nav_info['goodscn_brandids']) ? explode(',', $nav_info['goodscn_brandids']) : array();
+
+            View::assign('nav_info', $nav_info);
+            View::assign('class_info', $class_info);
+            // 一级分类列表
+            $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+
+            // 全部三级分类
+            $third_class = $goodsclass_model->getChildClassByFirstId($gc_id);
+            View::assign('third_class', $third_class);
+
+            // 品牌列表
+            $brand_model = model('brand');
+            $brand_list = $brand_model->getBrandPassedList(array());
+
+            $b_list = array();
+            if (is_array($brand_list) && !empty($brand_list)) {
+                foreach ($brand_list as $k => $val) {
+                    $b_list[$val['gc_id']]['brand'][$k] = $val;
+                    $b_list[$val['gc_id']]['name'] = $val['brand_class'] == '' ? lang('ds_default') : $val['brand_class'];
+                }
+            }
+            ksort($b_list);
+            View::assign('brand_list', $b_list);
+
+            return View::fetch('nav_edit');
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $branch = input('param.branch');
+        $condition = array();
+        switch ($branch) {
+            /**
+             * 更新分类
+             */
+            case 'goods_class_name':
+                $goodsclass_model = model('goodsclass');
+                $class_array = $goodsclass_model->getGoodsclassInfoById(intval(input('param.id')));
+
+                $condition[] = array('gc_name', '=', trim(input('param.value')));
+                $condition[] = array('gc_parent_id', '=', $class_array['gc_parent_id']);
+                $condition[] = array('gc_id', '<>', intval(input('param.id')));
+                $class_list = $goodsclass_model->getGoodsclassList($condition);
+
+                if (empty($class_list)) {
+                    $condition = array();
+                    $condition[] = array('gc_id', '=', intval(input('param.id')));
+                    $update_array = array();
+                    $update_array['gc_name'] = trim(input('param.value'));
+                    $goodsclass_model->editGoodsclass($update_array, $condition);
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+            /**
+             * 分类 排序 显示 设置
+             */
+            case 'goods_class_sort':
+            case 'goods_class_show':
+            case 'goods_class_index_show':
+                $goodsclass_model = model('goodsclass');
+                $condition = array();
+                $condition[] = array('gc_id', '=', intval(input('param.id')));
+                $update_array = array();
+                $update_array[input('param.column')] = input('param.value');
+                $goodsclass_model->editGoodsclass($update_array, $condition);
+                echo 'true';
+                exit;
+                break;
+            /**
+             * 添加、修改操作中 检测类别名称是否有重复
+             */
+            case 'check_class_name':
+                $goodsclass_model = model('goodsclass');
+                $condition[] = array('gc_name', '=', trim(input('get.gc_name')));
+                $condition[] = array('gc_parent_id', '=', intval(input('get.gc_parent_id')));
+                $condition[] = array('gc_id', '<>', intval(input('get.gc_id')));
+                $class_list = $goodsclass_model->getGoodsclassList($condition);
+                if (empty($class_list)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+            /**
+             * TAG值编辑
+             */
+            case 'goods_class_tag_value':
+                $classtag_model = model('goodsclasstag');
+                $update_array = array();
+                /**
+                 * 转码  防止GBK下用中文逗号截取不正确
+                 */
+                $comma = ',';
+                $update_array[input('param.column')] = trim(str_replace($comma, ',', input('param.value')));
+                $classtag_model->editGoodsclasstag($update_array, intval(input('param.id')));
+                echo 'true';
+                exit;
+                break;
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'goods_class',
+                'text' => lang('ds_manage'),
+                'url' => (string) url('Goodsclass/goods_class')
+            ),
+        );
+        if (request()->action() == 'goods_class_add' || request()->action() == 'goods_class') {
+            $menu_array[] = array(
+                'name' => 'goods_class_add',
+                'text' => lang('ds_add'),
+                'url' => (string) url('Goodsclass/goods_class_add')
+            );
+        }
+        if (request()->action() == 'goods_class_edit') {
+            $menu_array[] = array(
+                'name' => 'goods_class_edit',
+                'text' => lang('ds_edit'),
+                'url' => 'javascript:void(0)'
+            );
+        }
+        $menu_array[] = array(
+            'name' => 'tag',
+            'text' => lang('ds_tag'),
+            'url' => (string) url('Goodsclass/tag')
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 78 - 0
app/admin/controller/Goodsvideo.php

@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * 空间管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Goodsvideo extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/goodsvideo.lang.php');
+    }
+
+    /**
+     * 视频列表
+     */
+    public function index() {
+        $goods_model=model('goods');
+        $video_list=$goods_model->getGoodsVideoList(array(),'*','goodsvideo_id desc',0,16);
+        foreach($video_list as $key => $val){
+            $video_list[$key]['goodsvideo_url']=goods_video($val['goodsvideo_name']);
+        }
+        View::assign('video_list', $video_list);
+        View::assign('show_page', $goods_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 删除视频
+     *
+     */
+    public function del_video() {
+        $goodsvideo_id = input('param.goodsvideo_id');
+        $goodsvideo_id_array = ds_delete_param($goodsvideo_id);
+        if ($goodsvideo_id_array === FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition=array();
+        $condition[]=array('goodsvideo_id','in',$goodsvideo_id_array);
+        $goods_model = model('goods');
+        //批量删除视频
+        $goods_model->delGoodsVideo($condition);
+        $this->log(lang('ds_del') . lang('goodsvideo') . '[ID:' . $goodsvideo_id . ']', 1);
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_list'),
+                'url' => (string)url('Goodsvideo/index')
+            )
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 588 - 0
app/admin/controller/Groupbuy.php

@@ -0,0 +1,588 @@
+<?php
+
+/**
+ * 抢购管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Groupbuy extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/groupbuy.lang.php');
+    }
+
+    /**
+     * 进行中抢购列表,只可推荐
+     *
+     */
+    public function index() {
+        $groupbuy_model = model('groupbuy');
+
+        $condition = array();
+        if (!empty(input('param.groupbuy_name'))) {
+            $condition[]=array('groupbuy_name','like', '%' . input('param.groupbuy_name') . '%');
+        }
+        if ((input('param.store_name'))) {
+            $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if ((input('param.groupbuy_state'))) {
+            $condition[]=array('groupbuy_state','=',input('param.groupbuy_state'));
+        }
+        $groupbuy_list = $groupbuy_model->getGroupbuyExtendList($condition, 10);
+        View::assign('groupbuy_list', $groupbuy_list);
+        View::assign('show_page', $groupbuy_model->page_info->render());
+        View::assign('groupbuy_state_array', $groupbuy_model->getGroupbuyStateArray());
+
+        $this->setAdminCurItem('index');
+
+        // 输出自营店铺IDS
+        View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        View::assign('flippedOwnShopIds', '');
+        return View::fetch();
+    }
+
+    /**
+     * 审核通过
+     */
+    public function groupbuy_review_pass() {
+        $groupbuy_id = intval(input('post.groupbuy_id'));
+
+        if($groupbuy_id<=0){
+            $this->error(lang('param_error'));
+        }
+        
+        $groupbuy_model = model('groupbuy');
+        $result = $groupbuy_model->reviewPassGroupbuy($groupbuy_id);
+        if ($result) {
+            $this->log('通过抢购活动申请,抢购编号' . $groupbuy_id, null);
+            // 添加队列
+            $groupbuy_info = $groupbuy_model->getGroupbuyInfo(array('groupbuy_id' => $groupbuy_id));
+            $this->addcron(array(
+                'cron_exetime' => $groupbuy_info['groupbuy_starttime'], 'cron_value' => serialize(intval($groupbuy_info['goods_commonid'])),
+                'cron_type' => 'editGoodsGroupbuyPrice'
+            ));
+            $this->addcron(array(
+                'cron_exetime' => $groupbuy_info['groupbuy_endtime'], 'cron_value' => serialize(intval($groupbuy_info['goods_commonid'])),
+                'cron_type' => 'editExpireGroupbuy'
+            ));
+            $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 审核失败
+     */
+    public function groupbuy_review_fail() {
+        $groupbuy_id = intval(input('post.groupbuy_id'));
+
+        $groupbuy_model = model('groupbuy');
+        $result = $groupbuy_model->reviewFailGroupbuy($groupbuy_id);
+        if ($result) {
+            $this->log('拒绝抢购活动申请,抢购编号' . $groupbuy_id, null);
+            $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 取消
+     */
+    public function groupbuy_cancel() {
+        $groupbuy_id = intval(input('post.groupbuy_id'));
+
+        $groupbuy_model = model('groupbuy');
+        $result = $groupbuy_model->cancelGroupbuy($groupbuy_id);
+        if ($result) {
+            $this->log('取消抢购活动,抢购编号' . $groupbuy_id, null);
+            $this->success(lang('ds_common_op_succ'), 'Groupbuy/index');
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 删除
+     */
+    public function groupbuy_del() {
+        $groupbuy_id = intval(input('param.groupbuy_id'));
+        $groupbuy_model = model('groupbuy');
+        $result = $groupbuy_model->delGroupbuy(array('groupbuy_id' => $groupbuy_id));
+        if ($result) {
+            $this->log('删除抢购活动,抢购编号' . $groupbuy_id, null);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * ajax修改抢购信息
+     */
+    public function ajax() {
+
+        $result = true;
+        $update_array = array();
+        $condition = array();
+
+        switch (input('param.branch')) {
+            case 'gclass_sort':
+                $groupbuyclass_model = model('groupbuyclass');
+                $update_array['gclass_sort'] = input('param.value');
+                $condition[] = array('gclass_id','=',input('param.id'));
+                $result = $groupbuyclass_model->editGroupbuyclass($update_array, $condition);
+                // 删除抢购分类缓存
+                model('groupbuy')->dropCachedData('groupbuy_classes');
+                break;
+            case 'gclass_name':
+                $groupbuyclass_model = model('groupbuyclass');
+                $update_array['gclass_name'] = input('param.value');
+                $condition[] = array('gclass_id','=',input('param.id'));
+                $result = $groupbuyclass_model->editGroupbuyclass($update_array, $condition);
+                // 删除抢购分类缓存
+                model('groupbuy')->dropCachedData('groupbuy_classes');
+                $this->log(lang('groupbuy_class_edit_success') . '[ID:' . input('param.id') . ']', null);
+                break;
+            case 'recommended':
+                $groupbuy_model = model('groupbuy');
+                $update_array['groupbuy_recommended'] = input('param.value');
+                $condition[] = array('groupbuy_id','=',input('param.id'));
+                $result = $groupbuy_model->editGroupbuy($update_array, $condition);
+                break;
+        }
+		echo 'true';
+		exit;
+
+    }
+
+    /**
+     * 套餐管理
+     * */
+    public function groupbuy_quota() {
+        $groupbuyquota_model = model('groupbuyquota');
+
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $groupbuyquota_list = $groupbuyquota_model->getGroupbuyquotaList($condition, 10, 'groupbuyquota_endtime desc');
+        View::assign('groupbuyquota_list', $groupbuyquota_list);
+        View::assign('show_page', $groupbuyquota_model->page_info->render());
+
+        $this->setAdminCurItem('groupbuy_quota');
+        return View::fetch();
+    }
+
+    /**
+     * 抢购类别列表
+     */
+    public function class_list() {
+
+        $groupbuyclass_model = model('groupbuyclass');
+        $groupbuyclass_list = $groupbuyclass_model->getTreeList();
+        $this->setAdminCurItem('class_list');
+        View::assign('groupbuyclass_list', $groupbuyclass_list);
+        return View::fetch();
+    }
+
+    /**
+     * 添加抢购分类页面
+     */
+    public function class_add() {
+
+        $groupbuyclass_model = model('groupbuyclass');
+        $param = array();
+        $param['gclass_parent_id'] = 0;
+        $groupbuyclass_list = $groupbuyclass_model->getGroupbuyclassList($param);
+        View::assign('groupbuyclass_list', $groupbuyclass_list);
+
+        $this->setAdminCurItem('class_add');
+        View::assign('parent_id', input('param.parent_id'));
+        return View::fetch();
+    }
+
+    /**
+     * 保存添加的抢购类别
+     */
+    public function class_save() {
+
+        $gclass_id = intval(input('post.gclass_id'));
+        $param = array();
+        $param['gclass_name'] = trim(input('post.input_gclass_name'));
+        if (empty($param['gclass_name'])) {
+            $this->error(lang('class_name_error'), '');
+        }
+        $param['gclass_sort'] = intval(input('post.input_sort'));
+        $param['gclass_parent_id'] = intval(input('post.input_parent_id'));
+
+        $groupbuyclass_model = model('groupbuyclass');
+
+        // 删除抢购分类缓存
+        model('groupbuy')->dropCachedData('groupbuy_classes');
+
+        if (empty($gclass_id)) {
+            //新增
+            if ($groupbuyclass_model->addGroupbuyclass($param)) {
+                $this->log(lang('groupbuy_class_add_success') . '[ID:' . $gclass_id . ']', null);
+                dsLayerOpenSuccess(lang('groupbuy_class_add_success'));
+            } else {
+                $this->error(lang('groupbuy_class_add_fail'));
+            }
+        } else {
+            //编辑
+            if ($groupbuyclass_model->editGroupbuyclass($param, array('gclass_id' => $gclass_id))) {
+                $this->log(lang('groupbuy_class_edit_success') . '[ID:' . $gclass_id . ']', null);
+                dsLayerOpenSuccess(lang('groupbuy_class_edit_success'));
+            } else {
+                $this->error(lang('groupbuy_class_edit_fail'));
+            }
+        }
+    }
+
+    /**
+     * 删除抢购类别
+     */
+    public function class_drop() {
+
+        $gclass_id = trim(input('param.gclass_id'));
+        if (empty($gclass_id)) {
+            $this->error(lang('param_error'), '');
+        }
+
+        $groupbuyclass_model = model('groupbuyclass');
+        //获得所有下级类别编号
+        $all_gclass_id = $groupbuyclass_model->getAllClassId(explode(',', $gclass_id));
+        $condition = array();
+        $condition[]=array('gclass_id','in',implode(',', $all_gclass_id));
+        if ($groupbuyclass_model->delGroupbuyclass($condition)) {
+            // 删除抢购分类缓存
+            model('groupbuy')->dropCachedData('groupbuy_classes');
+            $this->log(lang('groupbuy_class_drop_success') . '[ID:' . implode(',', $all_gclass_id) . ']', null);
+            ds_json_encode(10000, lang('groupbuy_class_drop_success'));
+        } else {
+            ds_json_encode(10001, lang('groupbuy_class_drop_fail'));
+        }
+    }
+
+    /**
+     * 抢购价格区间列表
+     */
+    public function price_list() {
+
+        $groupbuypricerange_model = model('groupbuypricerange');
+        $groupbuypricerange_list = $groupbuypricerange_model->getGroupbuypricerangeList();
+        View::assign('groupbuypricerange_list', $groupbuypricerange_list);
+
+        $this->setAdminCurItem('price_list');
+        return View::fetch();
+    }
+
+    /**
+     * 添加抢购价格区间页面
+     */
+    public function price_add() {
+        $price_info = [
+            'gprange_id' => '', 'gprange_name' => '', 'gprange_start' => '', 'gprange_end' => '',
+        ];
+        View::assign('price_info', $price_info);
+        $this->setAdminCurItem('price_add');
+        return View::fetch();
+    }
+
+    /**
+     * 编辑抢购价格区间页面
+     */
+    public function price_edit() {
+
+        $gprange_id = intval(input('param.gprange_id'));
+        if (empty($gprange_id)) {
+            $this->error(lang('param_error'), '');
+        }
+
+        $groupbuypricerange_model = model('groupbuypricerange');
+
+        $price_info = $groupbuypricerange_model->getOneGroupbuypricerange($gprange_id);
+        if (empty($price_info)) {
+            $this->error(lang('param_error'), '');
+        }
+        View::assign('price_info', $price_info);
+
+        $this->setAdminCurItem('price_edit');
+        return View::fetch('price_add');
+    }
+
+    /**
+     * 保存添加的抢购价格区间
+     */
+    public function price_save() {
+
+        $gprange_id = intval(input('post.gprange_id'));
+        $param = array();
+        $param['gprange_name'] = trim(input('post.gprange_name'));
+        if (empty($param['gprange_name'])) {
+            $this->error(lang('range_name_error'), '');
+        }
+        $param['gprange_start'] = intval(input('post.gprange_start'));
+        $param['gprange_end'] = intval(input('post.gprange_end'));
+
+        $groupbuypricerange_model = model('groupbuypricerange');
+
+        if (empty($gprange_id)) {
+            //新增
+            if ($groupbuypricerange_model->addGroupbuypricerange($param)) {
+                dkcache('groupbuy_price');
+                $this->log(lang('groupbuy_price_range_add_success') . '[' . input('post.gprange_name') . ']', null);
+                dsLayerOpenSuccess(lang('groupbuy_price_range_add_success'));
+            } else {
+                $this->error(lang('groupbuy_price_range_add_fail'));
+            }
+        } else {
+            //编辑
+            if ($groupbuypricerange_model->editGroupbuypricerange($param, array('gprange_id' => $gprange_id))) {
+                dkcache('groupbuy_price');
+                $this->log(lang('groupbuy_price_range_edit_success') . '[' . input('post.gprange_name') . ']', null);
+                dsLayerOpenSuccess(lang('groupbuy_price_range_edit_success'));
+            } else {
+//                $this->error(lang('groupbuy_price_range_edit_fail'), (string)url('Groupbuy/price_list'));
+                $this->error(lang('groupbuy_price_range_edit_fail'));
+            }
+        }
+    }
+
+    /**
+     * 删除抢购价格区间
+     */
+    public function price_drop() {
+        
+        
+        $gprange_id = input('param.gprange_id');
+        $gprange_id_array = ds_delete_param($gprange_id);
+        if ($gprange_id_array === FALSE) {
+            $this->error(lang('param_error'));
+        }
+        
+        $condition = array();
+        $condition[]=array('gprange_id','in',$gprange_id_array);
+        $groupbuypricerange_model = model('groupbuypricerange');
+        if ($groupbuypricerange_model->delGroupbuypricerange($condition)) {
+            dkcache('groupbuy_price');
+            $this->log(lang('groupbuy_price_range_drop_success') . '[ID:' . $gprange_id . ']', null);
+            ds_json_encode(10000, lang('groupbuy_price_range_drop_success'));
+        } else {
+            ds_json_encode(10001, lang('groupbuy_price_range_drop_fail'));
+        }
+    }
+
+    /**
+     * 设置
+     * */
+    public function groupbuy_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $groupbuy_price = intval(input('post.groupbuy_price'));
+            if ($groupbuy_price < 0) {
+                $groupbuy_price = 0;
+            }
+
+            $groupbuy_review_day = intval(input('post.groupbuy_review_day'));
+            if ($groupbuy_review_day < 0) {
+                $groupbuy_review_day = 0;
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['groupbuy_price'] = $groupbuy_price;
+            $update_array['groupbuy_review_day'] = $groupbuy_review_day;
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改抢购套餐价格为' . $groupbuy_price . '元');
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    /**
+     * 幻灯片设置
+     */
+    public function slider() {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $update = array();
+            $fprefix = 'home/groupbuy/slider';
+            $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fprefix;
+            if (!empty($_FILES['live_pic1']['name'])) {
+                $res=ds_upload_pic($fprefix,'live_pic1');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $update['live_pic1'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            if (!empty(input('post.live_link1'))) {
+                $update['live_link1'] = input('post.live_link1');
+            }
+
+            if (!empty($_FILES['live_pic2']['name'])) {
+                $res=ds_upload_pic($fprefix,'live_pic2');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $update['live_pic2'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            if (!empty(input('post.live_link2'))) {
+                $update['live_link2'] = input('post.live_link2');
+            }
+
+            if (!empty($_FILES['live_pic3']['name'])) {
+                $res=ds_upload_pic($fprefix,'live_pic3');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $update['live_pic3'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            if (!empty(input('post.live_link3'))) {
+                $update['live_link3'] = input('post.live_link3');
+            }
+
+            if (!empty($_FILES['live_pic4']['name'])) {
+                $res=ds_upload_pic($fprefix,'live_pic4');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $update['live_pic4'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            if (!empty(input('post.live_link4'))) {
+                $update['live_link4'] = input('post.live_link4');
+            }
+
+            $list_setting = rkcache('config', true);
+            $result = $config_model->editConfig($update);
+            if ($result) {
+                if ($list_setting['live_pic1'] != '' && isset($update['live_pic1'])) {
+                    @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic1']);
+                }
+
+                if ($list_setting['live_pic2'] != '' && isset($update['live_pic2'])) {
+                    @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic2']);
+                }
+
+                if ($list_setting['live_pic3'] != '' && isset($update['live_pic3'])) {
+                    @unlink($upload_file . DIRECTORY_SEPARATOR . $list_setting['live_pic3']);
+                }
+
+                if ($list_setting['live_pic4'] != '' && isset($update['live_pic4'])) {
+                    @unlink($upload_file . $list_setting['live_pic4']);
+                }
+                $this->log('修改抢购幻灯片设置', 1);
+                $this->success(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+
+
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('slider');
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 幻灯片清空
+     */
+    public function slider_clear() {
+        $config_model = model('config');
+        $update = array();
+        $update['live_pic1'] = '';
+        $update['live_link1'] = '';
+        $update['live_pic2'] = '';
+        $update['live_link2'] = '';
+        $update['live_pic3'] = '';
+        $update['live_link3'] = '';
+        $update['live_pic4'] = '';
+        $update['live_link4'] = '';
+        $res = $config_model->editConfig($update);
+        if ($res) {
+            $this->log('清空抢购幻灯片设置', 1);
+            echo json_encode(array('result' => 'true'));
+        } else {
+            echo json_encode(array('result' => 'false'));
+        }
+        exit;
+    }
+
+    /**
+     * 页面内导航菜单
+     *
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList() {
+
+        $menu_array = array(
+            array(
+                'name' => 'index', 
+                'text' => lang('ds_groupbuy'),
+                'url' => (string)url('Groupbuy/index')
+            ), array(
+                'name' => 'groupbuy_quota', 
+                'text' => lang('groupbuy_quota'), 
+                'url' => (string)url('Groupbuy/groupbuy_quota')
+            ), array(
+                'name' => 'class_list',
+                'text' => lang('groupbuy_class_list'),
+                'url' => (string)url('Groupbuy/class_list')
+            ), array(
+                'name' => 'price_list', 
+                'text' => lang('groupbuy_price_list'),
+                'url' => (string)url('Groupbuy/price_list')
+            ), array(
+                'name' => 'groupbuy_setting',
+                'text' => lang('ds_set'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Groupbuy/groupbuy_setting')."','".lang('ds_set')."')"
+            ), array(
+                'name' => 'slider',
+                'text' => lang('groupbuy_slider'),
+                'url' => (string)url('Groupbuy/slider')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 110 - 0
app/admin/controller/Index.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Cache;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Index extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/index.lang.php');
+    }
+
+    public function index() {
+        View::assign('admin_info', $this->getAdminInfo());
+        return View::fetch();
+    }
+
+    /**
+     * 修改密码
+     */
+    public function modifypw() {
+        if (request()->isPost()) {
+            $new_pw = trim(input('post.new_pw'));
+            $new_pw2 = trim(input('post.new_pw2'));
+            $old_pw = trim(input('post.old_pw'));
+            if ($new_pw !== $new_pw2) {
+                $this->error(lang('index_modifypw_repeat_error'));
+            }
+            $admininfo = $this->getAdminInfo();
+            //查询管理员信息
+            $admin_model = model('admin');
+            $admininfo = $admin_model->getOneAdmin(array('admin_id'=>$admininfo['admin_id']));
+            if (!is_array($admininfo) || count($admininfo) <= 0) {
+                $this->error(lang('index_modifypw_admin_error'));
+            }
+            //旧密码是否正确
+            if ($admininfo['admin_password'] != md5($old_pw)) {
+               $this->error(lang('index_modifypw_oldpw_error'));
+            }
+            $new_pw = md5($new_pw);
+            $result = $admin_model->editAdmin(array('admin_password' => $new_pw),$admininfo['admin_id']);
+            if ($result) {
+                session(null);
+                echo "<script>parent.location.href='".(string)url('Login/index')."'</script>";
+            } else {
+                $this->error(lang('index_modifypw_fail'));
+            }
+        } else {
+            return View::fetch();
+        }
+    }
+    
+    /**
+     * 删除缓存
+     */
+    function clear() {
+        $this->delCacheFile('admin/temp');
+        $this->delCacheFile('admin/cache');
+        $this->delCacheFile('home/temp');
+        $this->delCacheFile('home/cache');
+        $this->delCacheFile('api/temp');
+        $this->delCacheFile('api/cache');
+        Cache::clear();
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+        exit();
+    }
+    
+    /**
+     * 删除缓存目录下的文件或子目录文件
+     *
+     * @param string $dir 目录名或文件名
+     * @return boolean
+     */
+    function delCacheFile($dir) {
+        //防止删除cache以外的文件
+        if (strpos($dir, '..') !== false)
+            return false;
+        $path = root_path() . 'runtime/' . $dir;
+        if (is_dir($path)) {
+            $file_list = array();
+            read_file_list($path, $file_list);
+            if (!empty($file_list)) {
+                foreach ($file_list as $v) {
+                    if (basename($v) != 'index.html')
+                        @unlink($v);
+                }
+            }
+        }
+        else {
+            if (basename($path) != 'index.html')
+                @unlink($path);
+        }
+        return true;
+    }
+
+}

+ 446 - 0
app/admin/controller/Inform.php

@@ -0,0 +1,446 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Inform extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/inform.lang.php');
+    }
+
+    /*
+     * 未处理的举报列表
+     */
+
+    public function inform_list() {
+
+        $this->get_inform_list(1, 'inform_list');
+        return View::fetch();
+    }
+
+    /*
+     * 已处理的举报列表
+     */
+
+    public function inform_handled_list() {
+
+        $this->get_inform_list(2, 'inform_handled_list');
+        return View::fetch();
+    }
+
+    /*
+     * 获取举报列表
+     */
+
+    private function get_inform_list($type, $action) {
+
+        //获得举报列表
+        $inform_model = model('inform');
+        //搜索条件
+        $condition = array();
+        if ((input('param.input_inform_goods_name'))) {
+            $condition[] = array('inform.inform_goods_name', 'like', "%" . input('param.input_inform_goods_name') . "%");
+        }
+        if ((input('param.input_inform_member_name'))) {
+            $condition[] = array('inform.inform_member_name', 'like', "%" . input('param.input_inform_member_name') . "%");
+        }
+        if ((input('param.input_inform_type'))) {
+            $condition[] = array('inform_subject.informsubject_type_name', 'like', "%" . input('param.input_inform_type') . "%");
+        }
+        if ((input('param.input_inform_subject'))) {
+            $condition[] = array('inform_subject.informsubject_content', 'like', "%" . input('param.input_inform_subject') . "%");
+        }
+        $stime = input('param.input_inform_datetime_start') ? strtotime(input('param.input_inform_datetime_start')) : 0;
+        $etime = input('param.input_inform_datetime_end') ? strtotime(input('param.input_inform_datetime_end')) : 0;
+        if ($stime > 0) {
+            $condition[] = array('inform.inform_datetime', '>=', $stime);
+        }
+        if ($etime > 0) {
+            $etime=$etime+86399;
+            $condition[] = array('inform.inform_datetime', '<=', $etime);
+        }
+        if ($type === 1) {
+            $order = 'inform_id asc';
+        } else {
+            $order = 'inform_id desc';
+        }
+        $condition[] = array('inform.inform_state', '=', $type);
+        $inform_list = $inform_model->getInformList($condition, 10, $order);
+
+        $this->setAdminCurItem($action);
+        View::assign('inform_list', $inform_list);
+        View::assign('show_page', $inform_model->page_info->render());
+    }
+
+    /*
+     * 举报类型列表
+     */
+
+    public function inform_subject_type_list() {
+
+        //获得有效举报类型列表
+        $informsubjecttype_model = model('informsubjecttype');
+        $informsubjecttype_list = $informsubjecttype_model->getActiveInformsubjecttypeList(10);
+
+        $this->setAdminCurItem('inform_subject_type_list');
+        View::assign('informsubjecttype_list', $informsubjecttype_list);
+        View::assign('show_page', $informsubjecttype_model->page_info->render());
+        return View::fetch();
+    }
+
+    /*
+     * 举报主题列表
+     */
+
+    public function inform_subject_list() {
+
+        //获得举报主题列表
+        $informsubject_model = model('informsubject');
+
+        //搜索条件
+        $condition = array();
+        $informsubject_type_id = intval(input('param.informsubject_type_id'));
+        if ($informsubject_type_id > 0) {
+            $condition[] = array('informsubject_type_id', '=', $informsubject_type_id);
+        }
+        $condition[] = array('informsubject_state', '=', 1);
+        $informsubject_list = $informsubject_model->getInformsubjectList($condition, 10);
+
+        //获取有效举报类型
+        $informsubjecttype_model = model('informsubjecttype');
+        $type_list = $informsubjecttype_model->getActiveInformsubjecttypeList();
+
+        $this->setAdminCurItem('inform_subject_list');
+        View::assign('informsubject_list', $informsubject_list);
+        View::assign('type_list', $type_list);
+        View::assign('show_page', $informsubject_model->page_info->render());
+        return View::fetch();
+    }
+
+    /*
+     * 添加举报类型页面
+     */
+
+    public function inform_subject_type_add() {
+        if (!request()->isPost()) {
+            return View::fetch();
+        } else {
+
+            //获取提交的内容
+            $input['informtype_name'] = trim(input('post.informtype_name'));
+            $input['informtype_desc'] = trim(input('post.informtype_desc'));
+
+            //验证提交的内容
+            $data = [
+                'informtype_name' => $input['informtype_name'],
+                'informtype_desc' => $input['informtype_desc'],
+            ];
+            $inform_validate = ds_validate('inform');
+            if (!$inform_validate->scene('inform_subject_type_save')->check($data)) {
+                $this->error($inform_validate->getError());
+            } else {
+                //验证成功保存
+                $input['informtype_state'] = 1;
+                $informsubjecttype_model = model('informsubjecttype');
+                $informsubjecttype_model->addInformsubjecttype($input);
+                $this->log(lang('ds_add') . lang('inform_type') . '[' . input('post.informtype_name') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+        }
+    }
+
+    /*
+     * 添加举报类型页面
+     */
+
+    public function inform_subject_type_edit() {
+        $informtype_id = input('param.informtype_id');
+        if (!request()->isPost()) {
+            $informsubjecttype_model = model('informsubjecttype');
+            $condition = array();
+            $condition[] = ['informtype_id','=',$informtype_id];
+            $informsubjecttype_info = $informsubjecttype_model->getInformsubjecttypeInfo($condition);
+            View::assign('informsubjecttype_info', $informsubjecttype_info);
+            return View::fetch();
+        } else {
+
+            //获取提交的内容
+            $condition = array();
+            $condition[] = ['informtype_id','=',$informtype_id];
+            $input['informtype_name'] = trim(input('post.informtype_name'));
+            $input['informtype_desc'] = trim(input('post.informtype_desc'));
+
+            //验证提交的内容
+            $data = [
+                'informtype_name' => $input['informtype_name'],
+                'informtype_desc' => $input['informtype_desc'],
+            ];
+            $inform_validate = ds_validate('inform');
+            if (!$inform_validate->scene('inform_subject_type_save')->check($data)) {
+                $this->error($inform_validate->getError());
+            } else {
+                //验证成功保存
+                $input['informtype_state'] = 1;
+                $informsubjecttype_model = model('informsubjecttype');
+                $informsubjecttype_model->editInformsubjecttype($input,$condition);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+        }
+    }
+
+    /*
+     * 删除举报类型,伪删除只是修改标记
+     */
+
+    public function inform_subject_type_drop() {
+
+        $informtype_id = trim(input('param.informtype_id'));
+        $informrtype_id_array = ds_delete_param($informtype_id);
+        if ($informrtype_id_array == FALSE) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+
+        //删除分类
+        $informsubjecttype_model = model('informsubjecttype');
+        $update_array = array();
+        $update_array['informtype_state'] = 2;
+        $where_array = array();
+        $where_array[] = array('informtype_id', 'in', $informrtype_id_array);
+        $informsubjecttype_model->editInformsubjecttype($update_array, $where_array);
+
+        //删除分类下边的主题
+        $informsubject_model = model('informsubject');
+        $update_subject_array = array();
+        $update_subject_array['informsubject_state'] = 2;
+        $where_subject_array = array();
+        $where_subject_array[] = array('informsubject_type_id', 'in', $informrtype_id_array);
+        $informsubject_model->editInformsubject($update_subject_array, $where_subject_array);
+        $this->log(lang('ds_del') . lang('inform_type') . '[ID:' . input('post.informtype_id') . ']', 1);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+    /*
+     * 添加举报主题页面
+     */
+
+    public function inform_subject_add() {
+        if (!request()->isPost()) {
+            //获得可用举报类型列表
+            $informsubjecttype_model = model('informsubjecttype');
+            $informsubjecttype_list = $informsubjecttype_model->getActiveInformsubjecttypeList();
+
+            if (empty($informsubjecttype_list)) {
+                $this->error(lang('inform_type_error'));
+            }
+            View::assign('informsubjecttype_list', $informsubjecttype_list);
+            return View::fetch();
+        } else {
+            //获取提交的内容
+            list($input['informsubject_type_id'], $input['informsubject_type_name']) = explode(',', trim(input('post.inform_subject_type')));
+            $input['informsubject_content'] = trim(input('post.informsubject_content'));
+
+            //验证提交的内容
+            $data = [
+                'informsubject_type_name' => $input['informsubject_type_name'],
+                'informsubject_content' => $input['informsubject_content'],
+                'informsubject_type_id' => $input['informsubject_type_id']
+            ];
+            $inform_validate = ds_validate('inform');
+            if (!$inform_validate->scene('inform_subject_save')->check($data)) {
+                $this->error($inform_validate->getError());
+            } else {
+                //验证成功保存
+                $input['informsubject_state'] = 1;
+                $informsubject_model = model('informsubject');
+                $informsubject_model->addInformsubject($input);
+                $this->log('添加' . lang('inform_subject') . '[' . $input['informsubject_type_name'] . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+        }
+    }
+
+    /*
+     * 删除举报主题,伪删除只是修改标记
+     */
+
+    public function inform_subject_drop() {
+        $informsubject_id = trim(input('param.informsubject_id'));
+
+        $informsubject_id_array = ds_delete_param($informsubject_id);
+        if ($informsubject_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $informsubject_model = model('informsubject');
+        $update_array = array();
+        $update_array['informsubject_state'] = 2;
+        $where_array = array();
+        $where_array[] = array('informsubject_id', 'in', $informsubject_id_array);
+        $informsubject_model->editInformsubject($update_array, $where_array);
+        $this->log(lang('ds_del') . lang('inform_subject') . '[' . input('post.informsubject_id') . ']', 1);
+        ds_json_encode(10000, lang('ds_common_del_succ'));
+    }
+
+    /*
+     * 显示处理举报
+     */
+
+    public function show_handle_page() {
+        $inform_id = intval(input('param.inform_id'));
+        $inform_goods_name = urldecode(input('param.inform_goods_name'));
+
+        View::assign('inform_id', $inform_id);
+        View::assign('inform_goods_name', $inform_goods_name);
+        return View::fetch('inform_handle');
+    }
+
+    /*
+     * 处理举报
+     */
+
+    public function inform_handle() {
+
+        $inform_id = intval(input('post.inform_id'));
+        $inform_handle_type = intval(input('post.inform_handle_type'));
+        $inform_handle_message = trim(input('post.inform_handle_message'));
+
+        if (empty($inform_id) || empty($inform_handle_type)) {
+            $this->error(lang('param_error'));
+        }
+
+        //验证输入的数据
+        $data = [
+            "inform_handle_message" => $inform_handle_message,
+        ];
+        $inform_validate = ds_validate('inform');
+        if (!$inform_validate->scene('inform_handle')->check($data)) {
+            $this->error($inform_validate->getError());
+        }
+
+
+        $inform_model = model('inform');
+        $inform_info = $inform_model->getOneInform(array('inform_id' => $inform_id));
+        if (empty($inform_info) || intval($inform_info['inform_state']) === 2) {
+            $this->error(lang('param_error'));
+        }
+
+        $update_array = array();
+        $where_array = array();
+
+        //根据选择处理
+        switch ($inform_handle_type) {
+
+            case 1:
+                $where_array[] = array('inform_id', '=', $inform_id);
+                break;
+            case 2:
+                //恶意举报,清理所有该用户的举报,设置该用户禁止举报
+                $where_array[] = array('inform_member_id', '=', $inform_info['inform_member_id']);
+                $this->denyMemberInform($inform_info['inform_member_id']);
+                break;
+            case 3:
+                //有效举报,商品禁售
+                $where_array[] = array('inform_id', '=', $inform_id);
+                $this->denyGoods($inform_info['inform_goods_id']);
+                break;
+            default:
+                $this->error(lang('param_error'));
+        }
+
+        $update_array['inform_state'] = 2;
+        $update_array['inform_handle_type'] = $inform_handle_type;
+        $update_array['inform_handle_message'] = $inform_handle_message;
+        $update_array['inform_handle_datetime'] = TIMESTAMP;
+        $admin_info = $this->getAdminInfo();
+        $update_array['inform_handle_member_id'] = $admin_info['admin_id'];
+        $where_array[] = array('inform_state', '=', 1);
+
+        if ($inform_model->editInform($update_array, $where_array)) {
+            $this->log(lang('inform_text_handle') . lang('inform') . '[ID:' . $inform_id . ']', 1);
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /*
+     * 禁止该用户举报
+     */
+
+    private function denyMemberInform($member_id) {
+
+        $member_model = model('member');
+        $param = array();
+        $param['inform_allow'] = 2;
+        return $member_model->editMember(array('member_id' => $member_id), $param, $member_id);
+    }
+
+    /*
+     * 禁止商品销售
+     */
+
+    private function denyGoods($goods_id) {
+        //修改商品状态
+        $goods_model = model('goods');
+        $goods_info = $goods_model->getGoodsInfoByID($goods_id);
+        if (empty($goods_info)) {
+            return true;
+        }
+        return $goods_model->editProducesLockUp(array('goods_stateremark' => lang('goods_be_informed')), array('goods_commonid' => $goods_info['goods_commonid']));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'inform_list',
+                'text' => lang('inform_state_unhandle'),
+                'url' => (string) url('Inform/inform_list')
+            ),
+            array(
+                'name' => 'inform_handled_list',
+                'text' => lang('inform_state_handled'),
+                'url' => (string) url('Inform/inform_handled_list')
+            ),
+            array(
+                'name' => 'inform_subject_type_list',
+                'text' => lang('inform_type'),
+                'url' => (string) url('Inform/inform_subject_type_list')
+            ),
+            array(
+                'name' => 'inform_subject_type_add',
+                'text' => lang('inform_type_add'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Inform/inform_subject_type_add') . "','" . lang('inform_type_add') . "')"
+            ),
+            array(
+                'name' => 'inform_subject_list',
+                'text' => lang('inform_subject'),
+                'url' => (string) url('Inform/inform_subject_list')
+            ),
+            array(
+                'name' => 'inform_subject_add',
+                'text' => lang('inform_subject_add'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Inform/inform_subject_add') . "','" . lang('inform_subject_add') . "')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 138 - 0
app/admin/controller/InstantMessage.php

@@ -0,0 +1,138 @@
+<?php
+
+/**
+ * 商品管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+use GatewayClient\Gateway;
+/**
+ * ============================================================================
+ * DSKMS多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class InstantMessage extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/instant_message.lang.php');
+    }
+
+    /**
+     * 商品管理
+     */
+    public function index() {
+        $instant_message_model = model('instant_message');
+        $f_name = trim(input('param.f_name'));
+        $t_name = trim(input('param.t_name'));
+        $time_add_from = input('param.add_time_from')?strtotime(input('param.add_time_from')):'';
+        $time_add_to = input('param.add_time_to')?strtotime(input('param.add_time_to')):'';
+        /**
+         * 查询条件
+         */
+        $condition = array();
+        if($f_name){
+            $condition[]=array('instant_message_from_name','like','%'.$f_name.'%');
+        }
+        if($t_name){
+            $condition[]=array('instant_message_to_name','like','%'.$t_name.'%');
+        }
+        if($time_add_from){
+            $condition[]=array('instant_message_add_time','>=',$time_add_from);
+        }
+        if($time_add_to){
+            $condition[]=array('instant_message_add_time','>=',$time_add_to);
+        }
+        $instant_message_open = input('param.instant_message_open');
+        if (in_array($instant_message_open, array('0', '1', '2'))) {
+            $condition[]=array('instant_message_open','=',$instant_message_open);
+        }
+
+        $instant_message_list = $instant_message_model->getInstantMessageList($condition, 10);
+        foreach($instant_message_list as $key => $val){
+            $instant_message_list[$key]=$instant_message_model->formatInstantMessage($val);
+        }
+        View::assign('instant_message_list', $instant_message_list);
+        View::assign('show_page', $instant_message_model->page_info->render());
+
+
+
+        View::assign('search', $condition);
+
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 删除商品
+     */
+    public function del() {
+        $instant_message_id = input('param.instant_message_id');
+        $instant_message_id_array = ds_delete_param($instant_message_id);
+        if ($instant_message_id_array == FALSE) {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+        $condition = array();
+        $condition[] = array('instant_message_id','in', $instant_message_id_array);
+        model('instant_message')->delInstantMessage($condition);
+        $this->log(lang('ds_del') . lang('instant_message') . ' ID:' . implode('、', $instant_message_id_array), 1);
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+    /*
+     * 直播设置
+     */
+    public function setting() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            $this->setAdminCurItem('setting');
+            return View::fetch();
+        } else {
+            $update_array=array();
+            $update_array['instant_message_gateway_url'] = input('param.instant_message_gateway_url');
+            $update_array['instant_message_register_url'] = input('param.instant_message_register_url');
+            $update_array['instant_message_open'] = input('param.instant_message_open');
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                dkcache('config');
+                $this->log(lang('ds_setting') . lang('instant_message'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_setting') . lang('instant_message'), 0);
+            }
+        }
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_list'),
+                'url' => url('InstantMessage/index')
+            ),
+            array(
+                'name' => 'setting',
+                'text' => lang('ds_setting'),
+                'url' => url('InstantMessage/setting')
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 442 - 0
app/admin/controller/Inviter.php

@@ -0,0 +1,442 @@
+<?php
+/**
+ * 推荐人设置
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Inviter extends AdminControl
+{
+public function initialize()
+{
+    parent::initialize(); // TODO: Change the autogenerated stub
+    Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/inviter.lang.php');
+}
+
+    /**
+     * 基本设置
+     */
+    public function setting(){
+        $config_model = model('config');
+        if (request()->isPost()){
+            $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_COMMON;
+            if (!empty($_FILES['inviter_back']['name'])) {
+                $res=ds_upload_pic(ATTACH_COMMON,'inviter_back', 'inviter_back.png');
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $upload['inviter_back'] = $file_name;
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+            if (!empty($upload['inviter_back'])) {
+                $update_array['inviter_back'] = $upload['inviter_back'];
+            }
+            $update_array['inviter_ratio_1']=floatval(input('post.inviter_ratio_1'));
+            $update_array['inviter_ratio_2']=floatval(input('post.inviter_ratio_2'));
+            $update_array['inviter_ratio_3']=floatval(input('post.inviter_ratio_3'));
+            
+            $update_array['inviter_open']=intval(input('post.inviter_open'));
+            $update_array['inviter_level']=intval(input('post.inviter_level'));
+            $update_array['inviter_show']=floatval(input('post.inviter_show'));
+            $update_array['inviter_return']=floatval(input('post.inviter_return'));
+            $update_array['inviter_view']=floatval(input('post.inviter_view'));
+            $update_array['inviter_condition']=floatval(input('post.inviter_condition'));
+            $update_array['inviter_condition_amount']=floatval(input('post.inviter_condition_amount'));
+            
+            if($update_array['inviter_return']){
+                if(($update_array['inviter_ratio_1']*2+$update_array['inviter_ratio_2']+$update_array['inviter_ratio_3'])>100){
+                    $this->error(lang('inviter_ratio_error'));
+                }
+            }else{
+                if(($update_array['inviter_ratio_1']+$update_array['inviter_ratio_2']+$update_array['inviter_ratio_3'])>100){
+                    $this->error(lang('inviter_ratio_error'));
+                }
+            }
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log(lang('ds_inviter_set'),1);
+                $this->success(lang('ds_common_op_succ'), 'Inviter/setting');
+            }else{
+                $this->log(lang('ds_inviter_set'),0);
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('index');
+            return View::fetch('index');
+        }
+    }
+    
+    public function goods(){
+        $goods_model=model('goods');
+        $condition = array();
+        $condition[]=array('inviter_open','=',1);
+        if ((input('param.goods_name'))) {
+            $condition[]=array('goods_name','like', '%' . input('param.goods_name') . '%');
+        }
+  
+        $goods_list = $goods_model->getGoodsCommonList($condition, '*', 10);
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $goods_model->page_info->render());
+        
+        $this->setAdminCurItem('goods');
+        return View::fetch('goods');
+    }
+    
+    public function order(){
+        $search_field_value = input('param.search_field_value');
+        $search_field_name = input('param.search_field_name');
+        $condition = array();
+        if ($search_field_value != '') {
+            switch ($search_field_name) {
+                case 'orderinviter_member_name':
+                    $condition[] = array('orderinviter_member_name','=',$search_field_value);
+                    break;
+                case 'orderinviter_order_sn':
+                    $condition[] = array('orderinviter_order_sn','=',$search_field_value);
+                    break;
+                case 'orderinviter_store_name':
+                    $condition[] = array('orderinviter_store_name','=',$search_field_value);
+                    break;
+            }
+        }
+  
+        $orderinviter_list=Db::name('orderinviter')->where($condition)->order('orderinviter_addtime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
+        $order_list=$orderinviter_list->items();
+        foreach($order_list as $key => $val){
+            $order_list[$key]['orderinviter_valid_text']=lang('orderinviter_valid_array')[$val['orderinviter_valid']];
+        }
+        View::assign('orderinviter_list', $order_list);
+        View::assign('show_page', $orderinviter_list->render());
+        View::assign('search_field_name', trim($search_field_name));
+        View::assign('search_field_value', trim($search_field_value));
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('order');
+        return View::fetch();
+    }
+    
+    public function member(){
+        $inviter_model=model('inviter');
+        $search_field_value = input('search_field_value');
+        $search_field_name = input('search_field_name');
+        $condition = array();
+        if ($search_field_value != '') {
+            switch ($search_field_name) {
+                case 'member_name':
+                    $condition[]=array('member_name','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_email':
+                    $condition[]=array('member_email','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_mobile':
+                    $condition[]=array('member_mobile','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_truename':
+                    $condition[]=array('member_truename','like', '%' . trim($search_field_value) . '%');
+                    break;
+            }
+        }
+  
+        $member_list = $inviter_model->getInviterList($condition, 10,'','i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename');
+        $inviterclass_model=model('inviterclass');
+        foreach($member_list as $key => $item){
+            $member_list[$key]['inviter_parent_name']='';
+            $member_list[$key]['inviter_class']='';
+            $member_list[$key]['inviter_class']=$inviterclass_model->getInviterclass($item['inviter_total_amount']);
+            if($item['inviter_parent_id']){
+                $member_list[$key]['inviter_parent_name'] = Db::name('member')->where('member_id='.$item['inviter_parent_id'])->value('member_name');
+            }
+        }
+        View::assign('member_list', $member_list);
+        View::assign('show_page', $inviter_model->page_info->render());
+        View::assign('search_field_name', trim($search_field_name));
+        View::assign('search_field_value', trim($search_field_value));
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('member');
+        return View::fetch('member');
+    }
+    public function memberclass(){
+        $memberclass_list=Db::name('inviterclass')->order('inviterclass_amount asc')->select()->toArray();
+        View::assign('memberclass_list',$memberclass_list);
+        $this->setAdminCurItem('memberclass');
+        return View::fetch('memberclass');
+    }
+    
+    public function member_adjust(){
+        $member_id=intval(input('param.member_id'));
+        if(!$member_id){
+            $this->error(lang('param_error'));
+        }
+        $inviter_model=model('inviter');
+        $inviter_info=$inviter_model->getInviterInfo(array('m.member_id'=>$member_id),'m.member_id,m.inviter_id as inviter_parent_id,i.inviter_1_quantity,i.inviter_2_quantity,i.inviter_3_quantity');
+        if(!$inviter_info){
+            $this->error(lang('inviter_member_empty'));
+        }
+        if (request()->isPost()) {
+            $member_name=trim(input('param.member_name'));
+            if($member_name){
+                $inviter=$inviter_model->getInviterInfo(array('m.member_name'=>$member_name),'m.member_id');
+                $inviter_id=$inviter['member_id'];
+                if(!$inviter_id){
+                    $this->error(lang('inviter_member_empty'));
+                }
+                //上级不能是自己
+                if($inviter_id==$member_id){
+                    $this->error(lang('inviter_parent_error'));
+                }
+                //上级不能是自己下级中(3级内)的成员
+                if(Db::name('member')->where('inviter_id='.$member_id.' AND member_id='.$inviter_id)->value('member_id')){
+                    $this->error(lang('inviter_parent_error2'));
+                }
+                $subQuery=Db::name('member')->field('member_id')->where('inviter_id='.$member_id)->buildSql();
+                
+                if(Db::name('member')->where('member_id='.$inviter_id.' AND inviter_id IN'.$subQuery)->value('member_id')){
+                    $this->error(lang('inviter_parent_error2'));
+                }
+                $subQuery=Db::name('member')->field('member_id')->where('inviter_id IN'.$subQuery)->buildSql();
+                if(Db::name('member')->where('member_id='.$inviter_id.' AND inviter_id IN'.$subQuery)->value('member_id')){
+                    $this->error(lang('inviter_parent_error2'));
+                }
+            }else{
+                $inviter_id=0;
+            }
+            Db::name('member')->where('member_id='.$member_id)->update(array(
+                'inviter_id'=>$inviter_id
+            ));
+            //给旧的父级减去下线成员
+            if($inviter_info['inviter_parent_id']){
+                Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_1_quantity>=1')->dec('inviter_1_quantity')->update();
+                Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_2_quantity>='.$inviter_info['inviter_1_quantity'])->dec('inviter_2_quantity',$inviter_info['inviter_1_quantity'])->update();
+                Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_3_quantity>='.$inviter_info['inviter_2_quantity'])->dec('inviter_3_quantity',$inviter_info['inviter_2_quantity'])->update();
+                //父级的父级
+                $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$inviter_info['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
+                if($temp['inviter_parent_id']){
+                    Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_2_quantity>=1')->dec('inviter_2_quantity')->update();
+                    Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_3_quantity>='.$inviter_info['inviter_1_quantity'])->dec('inviter_3_quantity',$inviter_info['inviter_1_quantity'])->update();
+                    //父级的父级的父级
+                    $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$temp['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
+                    if($temp['inviter_parent_id']){
+                        Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_3_quantity>=1')->dec('inviter_3_quantity')->update();
+                    }
+                }
+            }
+            //给新的父级增加下线成员
+            if($inviter_id){
+                Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_1_quantity')->update();
+                Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_2_quantity',$inviter_info['inviter_1_quantity'])->update();
+                Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_3_quantity',$inviter_info['inviter_2_quantity'])->update();
+                //父级的父级
+                $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$inviter_id),'m.inviter_id as inviter_parent_id');
+                if($temp['inviter_parent_id']){
+                    Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_2_quantity')->update();
+                    Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_3_quantity',$inviter_info['inviter_1_quantity'])->update();
+                    //父级的父级的父级
+                    $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$temp['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
+                    if($temp['inviter_parent_id']){
+                        Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_3_quantity')->update();
+                    }
+                }
+            }
+            $this->log(lang('adjust_superior') .  '[ID:' . $member_id . ']', 1);
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }else{
+            return View::fetch();
+        }
+    }
+    
+    /**
+     * 添加标签
+     */
+    public function memberclass_add(){
+        if (request()->isPost()) {
+            $data=array(
+                'inviterclass_name'=>trim(input('post.inviterclass_name')),
+                'inviterclass_amount'=>abs(floatval(input('post.inviterclass_amount'))),
+            );
+            if(!$data['inviterclass_name']){
+                $this->error(lang('param_error'));
+            }
+            Db::name('inviterclass')->insert($data);
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }else{
+            return View::fetch('memberclass_form');
+        }
+    }
+
+    /**
+     * 编辑标签
+     */
+    public function memberclass_edit()
+    {
+        $id=intval(input('param.id'));
+        if(!$id){
+            $this->error(lang('param_error'));
+        }
+        $inviterclass_info=Db::name('inviterclass')->where('inviterclass_id',$id)->find();
+        if(!$inviterclass_info){
+            $this->error(lang('inviterclass_empty'));
+        }
+        // 实例化模型
+        if (request()->isPost()) {
+            $data=array(
+                'inviterclass_name'=>trim(input('post.inviterclass_name')),
+                'inviterclass_amount'=>abs(floatval(input('post.inviterclass_amount'))),
+            );
+            if(!$data['inviterclass_name']){
+                $this->error(lang('param_error'));
+            }
+            Db::name('inviterclass')->where('inviterclass_id',$id)->update($data);
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }  else {
+
+            View::assign('inviterclass_info', $inviterclass_info);
+            return View::fetch('memberclass_form');
+        }
+    }
+
+    /**
+     * 删除标签
+     */
+    public function memberclass_del()
+    {
+        $inviterclass_id = input('param.id');
+        $inviterclass_id_array = ds_delete_param($inviterclass_id);
+        if ($inviterclass_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+ 
+        $result=Db::name('inviterclass')->where(array(array('inviterclass_id','in',$inviterclass_id_array)))->delete();
+        if ($result) {
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        }
+        else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    
+    
+    public function memberstate(){
+        $member_id=input('param.member_id');
+        $member_id_array = ds_delete_param($member_id);
+        $member_state=input('param.member_state');
+        if(!$member_id_array || !in_array($member_state, array(1,2))){
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $inviter_model=model('inviter');
+        $inviter_info=$inviter_model->getInviterInfo(array(array('i.inviter_id','in',$member_id_array)));
+        if(!$inviter_info){
+            ds_json_encode('10001', lang('inviter_member_empty'));
+        }
+        $inviter_model->editInviter(array(array('inviter_id','in',$member_id_array)),array('inviter_state'=>$member_state));
+        $this->log(($member_state==1?lang('ds_enable'):lang('ds_disable')) .  '[ID:' . implode(',', $member_id_array) . ']', 1);
+        ds_json_encode('10000', ($member_state==1?lang('ds_enable'):lang('ds_disable')).lang('ds_succ'));
+    }
+
+    public function memberinfo(){
+        $member_id=input('param.member_id');
+        if(!$member_id){
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $inviter_model=model('inviter');
+        $inviter_info=$inviter_model->getInviterInfo(array('i.inviter_id'=>$member_id),'i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename');
+        if(!$inviter_info){
+            ds_json_encode('10001', lang('inviter_member_empty'));
+        }
+        $inviter_info['inviter_parent_name']='';
+        if($inviter_info['inviter_parent_id']){
+            $inviter_info['inviter_parent_name']= Db::name('member')->where('member_id='.$inviter_info['inviter_parent_id'])->value('member_name');
+        }
+        $inviterclass_model=model('inviterclass');
+        $inviter_info['inviter_class']=$inviterclass_model->getInviterclass($inviter_info['inviter_total_amount']);
+        View::assign('inviter_info',$inviter_info);
+        $this->setAdminCurItem('member');
+        return View::fetch('memberinfo');
+    }
+    
+    public function memberlist(){
+        $member_id=intval(input('param.member_id'));
+        $type=input('param.type');
+        if(!$member_id || !in_array($type, array(1,2,3))){
+            return;
+        }
+        $inviter_model=model('inviter');
+        if($type==1){
+            $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
+            $page_info=$res;
+            $member_list=$res->items();
+        }elseif($type==2){
+    
+            $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->buildSql();
+            $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
+            $page_info=$res;
+            $member_list=$res->items();
+        }elseif($type==3){
+            $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->buildSql();
+            $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->buildSql();
+            $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
+            $page_info=$res;
+            $member_list=$res->items();
+        }
+        $inviterclass_model=model('inviterclass');
+        foreach($member_list as $key => $item){
+            $member_list[$key]['inviter_parent_name']='';
+            $member_list[$key]['inviter_class']='';
+            $member_list[$key]['inviter_class']=$inviterclass_model->getInviterclass(floatval($item['inviter_total_amount']));
+            if($item['inviter_parent_id']){
+                $member_list[$key]['inviter_parent_name'] = Db::name('member')->where('member_id='.$item['inviter_parent_id'])->value('member_name');
+            }
+        }
+        View::assign('member_list',$member_list);
+        View::assign('show_page', $page_info->render());
+        echo View::fetch('memberlist');
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('inviter_setting'),
+                'url' => (string)url('Inviter/setting')
+            ),
+            array(
+                'name' => 'goods',
+                'text' => lang('inviter_goods'),
+                'url' => (string)url('Inviter/goods')
+            ),
+            array(
+                'name' => 'member',
+                'text' => lang('inviter_member'),
+                'url' => (string)url('Inviter/member')
+            ),
+            array(
+                'name' => 'memberclass',
+                'text' => lang('inviter_memberclass'),
+                'url' => (string)url('Inviter/memberclass')
+            ),
+            array(
+                'name' => 'order',
+                'text' => lang('inviter_order'),
+                'url' => (string)url('Inviter/order')
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 189 - 0
app/admin/controller/Link.php

@@ -0,0 +1,189 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Link extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/link.lang.php');
+    }
+
+    public function index() {
+        $condition = array();
+        $link_title = input('get.link_title');
+        if ($link_title) {
+            $condition[] = array('link_title', 'like', "%$link_title%");
+        }
+        $link_model = model('link');
+        $link_list = $link_model->getLinkList($condition, 10);
+
+        View::assign('link_list', $link_list);
+        View::assign('show_page', $link_model->page_info->render());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('index');
+        return View::fetch('');
+    }
+
+    /**
+     * 新增友情链接
+     * */
+    public function add() {
+        if (!(request()->isPost())) {
+            $link = [
+                'link_id' => '',
+                'link_title' => '',
+                'link_pic' => '',
+                'link_url' => '',
+                'link_sort' => 255,
+            ];
+            View::assign('link', $link);
+            return View::fetch('form');
+        } else {
+            //上传图片
+            $link_pic = '';
+            if ($_FILES['link_pic']['name'] != '') {
+                $file_name = date('YmdHis') . rand(10000, 99999).'.png';
+                $res=ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link','link_pic',$file_name);
+                if($res['code']){
+                    $link_pic=$res['data']['file_name'];
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            $data = array(
+                'link_title' => input('post.link_title'),
+                'link_pic' => $link_pic,
+                'link_url' => input('post.link_url'),
+                'link_sort' => input('post.link_sort'),
+            );
+            $link_validate = ds_validate('link');
+            if (!$link_validate->scene('add')->check($data)) {
+                $this->error($link_validate->getError());
+            }
+
+            $result = model('link')->addLink($data);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑友情链接
+     * */
+    public function edit() {
+        $link_id = input('param.link_id');
+        if (empty($link_id)) {
+            $this->error(lang('param_error'));
+        }
+        $link = model('link')->getOneLink($link_id);
+        if (!request()->isPost()) {
+            View::assign('link', $link);
+            return View::fetch('form');
+        } else {
+            $data = array(
+                'link_title' => input('post.link_title'),
+                'link_sort' => input('post.link_sort'),
+                'link_url' => input('post.link_url'),
+            );
+            //上传图片
+            if ($_FILES['link_pic']['name'] != '') {
+                $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . DIR_ADMIN . DIRECTORY_SEPARATOR . 'link';
+                $file_name = date('YmdHis') . rand(10000, 99999).'.png';
+                $res=ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link','link_pic',$file_name);
+                if($res['code']){
+                    $file_name=$res['data']['file_name'];
+                    $data['link_pic'] = $file_name;
+                    //删除原有友情链接图片
+                    @unlink($upload_file . DIRECTORY_SEPARATOR . $link['link_pic']);
+                }else{
+                    $this->error($res['msg']);
+                }
+            }
+
+            $link_validate = ds_validate('link');
+            if (!$link_validate->scene('edit')->check($data)) {
+                $this->error($link_validate->getError());
+            }
+
+            $result = model('link')->editLink($data, $link_id);
+            if ($result >= 0) {
+                dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    public function drop() {
+        $link_id = intval(input('param.link_id'));
+        if (empty($link_id)) {
+            $this->error(lang('param_error'));
+        }
+        $result = model('link')->delLink($link_id);
+        if ($result) {
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $result = -1;
+        switch (input('get.branch')) {
+            case 'link':
+                $model_link = model('link');
+                $link_id = intval(input('get.id'));
+                $update_array = array();
+                $update_array[input('get.column')] = trim(input('get.value'));
+                $result = $model_link->editLink($update_array, $link_id);
+                break;
+        }
+        if ($result >= 0) {
+            echo 'true';
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string) url('Link/index')
+            ),
+            array(
+                'name' => 'add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Link/add') . "','" . lang('ds_add') . "')"
+            )
+        );
+        return $menu_array;
+    }
+
+}

+ 406 - 0
app/admin/controller/LiveApply.php

@@ -0,0 +1,406 @@
+<?php
+
+/**
+ * 商品管理
+ */
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+use TencentCloud\Common\Credential;
+use TencentCloud\Common\Profile\ClientProfile;
+use TencentCloud\Common\Profile\HttpProfile;
+use TencentCloud\Common\Exception\TencentCloudSDKException;
+use TencentCloud\Live\V20180801\LiveClient;
+use TencentCloud\Live\V20180801\Models\DropLiveStreamRequest;
+use TencentCloud\Live\V20180801\Models\DescribeLiveStreamStateRequest;
+use AlibabaCloud\Client\AlibabaCloud;
+
+/**
+ * ============================================================================
+ * DSKMS多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class LiveApply extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/live_apply.lang.php');
+    }
+
+    /**
+     * 商品管理
+     */
+    public function index() {
+        /**
+         * 查询条件
+         */
+        $condition = array();
+        $store_model = model('store');
+        if (config('ds_config.live_type') == 1) {
+            $minipro_live_model = model('minipro_live');
+            $minipro_live_list = $minipro_live_model->getMiniproLiveList($condition);
+            $store_list = array();
+            foreach ($minipro_live_list as $key => $val) {
+                $minipro_live_list[$key]['minipro_live_image_url'] = ds_get_pic( ATTACH_MINIPRO_LIVE , $val['minipro_live_image']);
+                if (!isset($store_list[$val['store_id']])) {
+                    $store_list[$val['store_id']] = $store_model->getStoreInfo(array('store_id' => $val['store_id']));
+                }
+                $minipro_live_list[$key]['store_name'] = $store_list[$val['store_id']]['store_name'] ? $store_list[$val['store_id']]['store_name'] : '';
+            }
+            View::assign('minipro_live_list', $minipro_live_list);
+            View::assign('show_page', $minipro_live_model->page_info->render());
+        } else {
+            $live_apply_model = model('live_apply');
+            $live_apply_state = input('param.live_apply_state');
+            if (in_array($live_apply_state, array('0', '1', '2'))) {
+                $condition[] = array('live_apply_state', '=', $live_apply_state);
+            }
+
+            $live_apply_list = $live_apply_model->getLiveApplyList($condition, '*', 10, 'live_apply_state asc,live_apply_id desc');
+
+            $store_list = array();
+            foreach ($live_apply_list as $key => $val) {
+                if ($val['live_apply_cover_video']) {
+                    $live_apply_list[$key]['live_apply_cover_video_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'] , $val['live_apply_cover_video']);
+                } elseif ($val['live_apply_cover_image']) {
+                    $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'] , $val['live_apply_cover_image']);
+                } else {
+                    $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
+                }
+                $live_apply_list[$key]['live_apply_user_name'] = '';
+                switch ($val['live_apply_user_type']) {
+                    case 2:
+                        if (!isset($store_list[$val['live_apply_user_id']])) {
+                            $store_list[$val['live_apply_user_id']] = $store_model->getStoreInfo(array('store_id' => $val['live_apply_user_id']));
+                        }
+                        $live_apply_list[$key]['live_apply_user_name'] = $store_list[$val['live_apply_user_id']]['store_name'] ? $store_list[$val['live_apply_user_id']]['store_name'] : '';
+                        break;
+                }
+            }
+            View::assign('live_apply_list', $live_apply_list);
+            View::assign('show_page', $live_apply_model->page_info->render());
+        }
+
+
+        View::assign('search', $condition);
+
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 删除商品
+     */
+    public function del() {
+        $live_apply_id = input('param.live_apply_id');
+        $live_apply_id_array = ds_delete_param($live_apply_id);
+        if ($live_apply_id_array == FALSE) {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+        $condition = array();
+        $condition[] = array('live_apply_id', 'in', $live_apply_id_array);
+        model('live_apply')->delLiveApply($condition);
+        $this->log(lang('ds_del') . lang('live_apply') . ' ID:' . implode('、', $live_apply_id_array), 1);
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 审核商品
+     */
+    public function view() {
+        if (config('ds_config.live_type') == 1) {
+            $minipro_live_id = input('param.minipro_live_id');
+            $minipro_live_model = model('minipro_live');
+            $minipro_live_info = $minipro_live_model->getMiniproLiveInfo(array(array('minipro_live_id', '=', $minipro_live_id)));
+            if (!$minipro_live_info) {
+                $this->error(lang('live_not_exist'));
+            }
+            $minipro_live_info['minipro_live_image_url'] = ds_get_pic( ATTACH_MINIPRO_LIVE , $minipro_live_info['minipro_live_image']);
+            $minipro_live_room_goods_model = model('minipro_live_room_goods');
+            $goods_list = $minipro_live_room_goods_model->getMiniproLiveRoomGoodsList(array(array('minipro_live_id', '=', $minipro_live_id)));
+            foreach ($goods_list as $k => $v) {
+                $goods_list[$k]['goods_image'] = goods_cthumb($v['goods_image']);
+            }
+
+            $minipro_live_info['goods_list'] = $goods_list;
+            View::assign('live_apply_info', $minipro_live_info);
+            echo View::fetch('view');
+        } else {
+            $live_apply_id = input('param.live_apply_id');
+            $live_apply_model = model('live_apply');
+            $live_apply_info = $live_apply_model->getLiveApplyInfo(array('live_apply_id' => $live_apply_id));
+            if (!$live_apply_info) {
+                $this->error(lang('live_not_exist'));
+            }
+            if (request()->isPost()) {
+                $live_apply_model = model('live_apply');
+                $data = array(
+                    'live_apply_end_time' => strtotime(input('param.live_apply_end_time')),
+                    'live_apply_video' => input('param.live_apply_video'),
+                );
+                if (!$data['live_apply_end_time']) {
+                    $this->error(lang('live_apply_end_time_empty'));
+                }
+
+                if ($live_apply_info['live_apply_state'] == 0) {
+                    if (intval(input('param.verify_state')) == 0) {
+                        $state = 2;
+                        $remark = input('param.verify_reason');
+                        if ($remark) {
+                            $store_ids = Db::name('live_apply')->where(array('live_apply_user_type' => 2, 'live_apply_id' => $live_apply_id))->column('live_apply_user_id');
+                            if ($store_ids) {
+                                $store_model = model('store');
+                                $store_list = $store_model->getStoreList(array(array('store_id', 'in', $store_ids)));
+                                if ($store_list) {
+                                    foreach ($store_list as $store) {
+                                        $param = array();
+                                        $param['code'] = 'live_apply_verify';
+                                        $param['store_id'] = $store['store_id'];
+                                        $param['ali_param'] = array(
+                                            'remark' => $remark,
+                                            'live_apply_id' => $live_apply_id
+                                        );
+                                        $param['ten_param'] = array(
+                                            $remark,
+                                            $live_apply_id
+                                        );
+                                        $param['param'] = $param['ali_param'];
+                                        $param['weixin_param'] = array(
+                                            'url' => config('ds_config.h5_site_url') . '/seller/live_apply_list',
+                                            'data' => array(
+                                                "keyword1" => array(
+                                                    "value" => $live_apply_info['live_apply_remark'],
+                                                    "color" => "#333"
+                                                ),
+                                                "keyword2" => array(
+                                                    "value" => $remark,
+                                                    "color" => "#333"
+                                                )
+                                            ),
+                                        );
+                                        model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize($param)));
+                                    }
+                                }
+                            }
+                        }
+                    } else {
+                        $state = 1;
+                        //生成小程序码
+                        $wechat_model = model('wechat');
+                        $wechat_model->getOneWxconfig();
+                        $a = $wechat_model->getMiniProCode($live_apply_id, 'pages/livepush/livepush');
+                        if (@imagecreatefromstring($a) == false) {
+                            $a = json_decode($a);
+                            $this->error(lang('live_minipro_code_fail') . lang('ds_colon') . $a->errmsg);
+                        } else {
+                            if (is_dir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY) || (!is_dir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY) && mkdir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY, 0755, true))) {
+                                file_put_contents(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY . DIRECTORY_SEPARATOR . $live_apply_id . '.png', $a);
+                            } else {
+                                $this->error(lang('live_minipro_code_fail') . lang('ds_colon') . lang('directory_no_right'));
+                            }
+                        }
+                    }
+                    $data['live_apply_state'] = $state;
+                }
+                $live_apply_model->editLiveApply($data, array('live_apply_id' => $live_apply_id));
+                $this->log(lang('ds_verify') . lang('live_apply') . ' ID:' . $live_apply_id, 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                //判断当前流状态
+                $live_apply_info['active'] = false;
+                if ($live_apply_info['live_apply_state'] == 1 && $live_apply_info['live_apply_end_time'] > TIMESTAMP) {
+                    if (config('ds_config.video_type') == 'aliyun') {
+                        if (!config('ds_config.aliyun_live_push_domain')) {
+                            ds_json_encode(10001, lang('aliyun_live_push_domain_empty'));
+                        }
+                        if (!config('ds_config.aliyun_live_push_key')) {
+                            ds_json_encode(10001, lang('aliyun_live_push_key_empty'));
+                        }
+                        if (!config('ds_config.aliyun_live_play_domain')) {
+                            ds_json_encode(10001, lang('aliyun_live_play_domain_empty'));
+                        }
+                        if (!config('ds_config.aliyun_live_play_key')) {
+                            ds_json_encode(10001, lang('aliyun_live_play_key_empty'));
+                        }
+                        $regionId = 'cn-shanghai';
+                        AlibabaCloud::accessKeyClient(config('ds_config.aliyun_access_key_id'), config('ds_config.aliyun_access_key_secret'))
+                                ->regionId($regionId)
+                                ->asDefaultClient();
+
+                        try {
+                            $result = AlibabaCloud::rpc()
+                                    ->product('live')
+                                    // ->scheme('https') // https | http
+                                    ->version('2016-11-01')
+                                    ->action('DescribeLiveStreamsOnlineList')
+                                    ->method('POST')
+                                    ->host('live.aliyuncs.com')
+                                    ->options([
+                                        'query' => [
+                                            'RegionId' => $regionId,
+                                            'DomainName' => config('ds_config.aliyun_live_push_domain'),
+                                            'AppName' => "live",
+                                            'StreamName' => 'live_apply_' . $live_apply_info['live_apply_id'],
+                                            'PageSize' => "1",
+                                            'PageNum' => "1",
+                                            'QueryType' => "strict",
+                                        ],
+                                    ])
+                                    ->request();
+                            if ($result->TotalNum) {
+                                $live_apply_info['active'] = true;
+                                //生成播放地址
+                                $live_apply_info['live_apply_play_url'] = model('live_apply')->getPlayUrl('live_apply_' . $live_apply_info['live_apply_id'], $live_apply_info['live_apply_end_time']);
+                            }
+                        } catch (\Exception $e) {
+                            
+                        }
+                    } else {
+                        if (!config('ds_config.live_push_domain')) {
+                            $this->error(lang('live_push_domain_empty'));
+                        }
+                        if (!config('ds_config.live_push_key')) {
+                            $this->error(lang('live_push_key_empty'));
+                        }
+                        if (!config('ds_config.live_play_domain')) {
+                            $this->error(lang('live_play_domain_empty'));
+                        }
+
+                        try {
+
+                            $cred = new Credential(config('ds_config.vod_tencent_secret_id'), config('ds_config.vod_tencent_secret_key'));
+                            $httpProfile = new HttpProfile();
+                            $httpProfile->setEndpoint("live.tencentcloudapi.com");
+
+                            $clientProfile = new ClientProfile();
+                            $clientProfile->setHttpProfile($httpProfile);
+                            $client = new LiveClient($cred, "", $clientProfile);
+
+                            $req = new DescribeLiveStreamStateRequest();
+
+                            $params = '{"AppName":"live","DomainName":"' . config('ds_config.live_push_domain') . '","StreamName":"' . 'live_apply_' . $live_apply_info['live_apply_id'] . '"}';
+                            $req->fromJsonString($params);
+
+
+                            $resp = $client->DescribeLiveStreamState($req);
+                        } catch (TencentCloudSDKException $e) {
+                            $this->error($e->getMessage());
+                        }
+                        if ($resp->StreamState == 'active') {
+                            $live_apply_info['active'] = true;
+                            //生成播放地址
+                            $live_apply_info['live_apply_play_url'] = model('live_apply')->getPlayUrl('live_apply_' . $live_apply_info['live_apply_id'], $live_apply_info['live_apply_end_time']);
+                        }
+                    }
+                }
+                if ($live_apply_info['live_apply_cover_video']) {
+                    $live_apply_info['live_apply_cover_video_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $live_apply_info['live_apply_user_id'] , $live_apply_info['live_apply_cover_video']);
+                } elseif ($live_apply_info['live_apply_cover_image']) {
+                    $live_apply_info['live_apply_cover_image_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $live_apply_info['live_apply_user_id'] , $live_apply_info['live_apply_cover_image']);
+                } else {
+                    $live_apply_info['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
+                }
+                $goods_commonid = Db::name('live_apply_goods')->where('live_apply_id', $live_apply_info['live_apply_id'])->column('goods_commonid');
+                $goods_model = model('goods');
+                if (!empty($goods_commonid)) {
+                    $goods_list = $goods_model->getGoodsUnionList(array(array('goodscommon.goods_commonid', 'in', $goods_commonid)), 'goods_id,goodscommon.goods_name,goodscommon.goods_image,goodscommon.goods_price');
+                    foreach ($goods_list as $k => $v) {
+                        $goods_list[$k]['goods_image'] = goods_cthumb($v['goods_image']);
+                    }
+                    $live_apply_info['goods_list'] = $goods_list;
+                } else {
+                    $live_apply_info['goods_list'] = array();
+                }
+                View::assign('live_apply_info', $live_apply_info);
+                echo View::fetch('view');
+            }
+        }
+    }
+
+    public function close() {
+        $live_apply_id = input('param.live_apply_id');
+        $live_apply_model = model('live_apply');
+        $live_apply = $live_apply_model->getLiveApplyInfo(array('live_apply_id' => $live_apply_id));
+        if (!$live_apply) {
+            ds_json_encode(10001, lang('live_not_exist'));
+        }
+        if (config('ds_config.video_type') == 'aliyun') {
+            $regionId = 'cn-shanghai';
+            AlibabaCloud::accessKeyClient(config('ds_config.aliyun_access_key_id'), config('ds_config.aliyun_access_key_secret'))
+                    ->regionId($regionId)
+                    ->asDefaultClient();
+
+            try {
+                $result = AlibabaCloud::rpc()
+                        ->product('live')
+                        // ->scheme('https') // https | http
+                        ->version('2016-11-01')
+                        ->action('ForbidLiveStream')
+                        ->method('POST')
+                        ->host('live.aliyuncs.com')
+                        ->options([
+                            'query' => [
+                                'RegionId' => $regionId,
+                                'AppName' => "live",
+                                'StreamName' => 'live_apply_' . $live_apply['live_apply_id'],
+                                'LiveStreamType' => "publisher",
+                                'DomainName' => config('ds_config.aliyun_live_push_domain'),
+                            ],
+                        ])
+                        ->request();
+            } catch (\Exception $e) {
+                ds_json_encode(10001, $e->getMessage());
+            }
+        } else {
+            try {
+
+                $cred = new Credential(config('ds_config.vod_tencent_secret_id'), config('ds_config.vod_tencent_secret_key'));
+                $httpProfile = new HttpProfile();
+                $httpProfile->setEndpoint("live.tencentcloudapi.com");
+
+                $clientProfile = new ClientProfile();
+                $clientProfile->setHttpProfile($httpProfile);
+                $client = new LiveClient($cred, "", $clientProfile);
+
+                $req = new DropLiveStreamRequest();
+
+                $params = '{"AppName":"live","DomainName":"' . config('ds_config.live_push_domain') . '","StreamName":"' . 'live_apply_' . $live_apply['live_apply_id'] . '"}';
+                $req->fromJsonString($params);
+
+
+                $resp = $client->DropLiveStream($req);
+            } catch (TencentCloudSDKException $e) {
+                ds_json_encode(10001, $e->getMessage());
+            }
+        }
+        $this->log(lang('live_cut_off') . ' ID:' . $live_apply_id, 1);
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_list'),
+                'url' => url('LiveApply/index')
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 125 - 0
app/admin/controller/LiveGoods.php

@@ -0,0 +1,125 @@
+<?php
+
+/**
+ * 推荐人设置
+ */
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class LiveGoods extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/live_goods.lang.php');
+    }
+
+    public function index() {
+        $condition = array();
+        if ((input('param.goods_name'))) {
+            $condition[] = array('goodscommon.goods_name', 'like', '%' . input('param.goods_name') . '%');
+        }
+
+        $fields = 'goods_id,goodscommon.gc_id,goodscommon.store_name,goodscommon.store_id,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_price,goodscommon.goods_addtime,goodscommon.goods_image,goodscommon.goods_state,goodscommon.goods_lock';
+        $goods_model = model('goods');
+        $goods_list = $goods_model->getGoodsUnionList($condition, $fields, 'goodscommon.goods_commonid desc', 'goodscommon.goods_commonid', 10);
+        $minipro_live_goods_model = model('minipro_live_goods');
+        foreach ($goods_list as $key => $val) {
+            $goods_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
+
+            $minipro_live_goods_info = $minipro_live_goods_model->getMiniproLiveGoodsInfo(array(array('goods_commonid', '=', $val['goods_commonid'])));
+            $goods_list[$key]['minipro_live_goods_info'] = $minipro_live_goods_info;
+        }
+
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $goods_model->page_info->render());
+
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function open() {
+        $goods_commonid = input('param.goods_commonid');
+        $minipro_live_goods_model = model('minipro_live_goods');
+        //删掉后会在定时任务中重新申请
+        $minipro_live_goods_model->delMiniproLiveGoods(array(array('goods_commonid', '=', $goods_commonid)));
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+    public function close() {
+        $goods_commonid = input('param.goods_commonid');
+        $minipro_live_goods_model = model('minipro_live_goods');
+        $minipro_live_goods_info = $minipro_live_goods_model->getMiniproLiveGoodsInfo(array(array('goods_commonid', '=', $goods_commonid)));
+        if ($minipro_live_goods_info) {
+            //删除小程序商品
+            $wechat_model = model('wechat');
+            $wechat_model->getOneWxconfig();
+            $accessToken = $wechat_model->getAccessToken('miniprogram', 0);
+            if ($wechat_model->error_code) {
+                ds_json_encode('10001', lang('get_minipro_access_token_fail') . $wechat_model->error_message);
+            }
+            $data = array(
+                'goodsId' => $minipro_live_goods_info['minipro_live_goods_result_id']
+            );
+            $res = http_request('https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=' . $accessToken, 'POST', $data);
+            $res = json_decode($res, true);
+            if (!$res || $res['errcode']) {
+                ds_json_encode('10001', isset($res['errmsg']) ? $res['errmsg'] : lang('del_goods_fail') . $res['errcode']);
+            }
+            $minipro_live_goods_model->editMiniproLiveGoods(array('minipro_live_goods_close' => 1), array(array('minipro_live_goods_id', '=', $minipro_live_goods_info['minipro_live_goods_id'])));
+        } else {
+            $goods_model = model('goods');
+            $goods_info = $goods_model->getGoodsCommonInfoByID($goods_commonid);
+            if (!$goods_info) {
+                ds_json_encode('10001', lang('goods_not_exist'));
+            }
+            $goods_id = Db::name('goods')->where(array(array('goods_commonid', '=', $goods_info['goods_commonid'])))->order('goods_id asc')->value('goods_id');
+            if (!$goods_id) {
+                ds_json_encode('10001', lang('goods_not_exist'));
+            }
+            $minipro_live_goods_model->addMiniproLiveGoods(array(
+                'store_id' => $goods_info['store_id'],
+                'store_name' => $goods_info['store_name'],
+                'goods_id' => $goods_id,
+                'goods_commonid' => $goods_info['goods_commonid'],
+                'goods_name' => $goods_info['goods_name'],
+                'goods_price' => $goods_info['goods_price'],
+                'goods_image' => $goods_info['goods_image'],
+                'minipro_live_goods_add_time' => TIMESTAMP,
+                'minipro_live_goods_close' => 1
+            ));
+        }
+
+        ds_json_encode('10000', lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_list'),
+                'url' => (string) url('LiveGoods/index')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 82 - 0
app/admin/controller/LiveSetting.php

@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * 商品管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSKMS多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class LiveSetting extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/live_setting.lang.php');
+    }
+
+    public function index() {
+        $config_model = model('config');
+        if (!request()->isPost()) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+            $this->setAdminCurItem('index');
+            return View::fetch();
+        } else {
+            $update_array=array();
+            $update_array['live_type'] = input('post.live_type');
+            $update_array['vod_tencent_play_key'] = input('post.vod_tencent_play_key');
+            $update_array['vod_tencent_appid'] = input('post.vod_tencent_appid');
+            $update_array['vod_tencent_play_domain'] = input('post.vod_tencent_play_domain');
+            $update_array['vod_tencent_secret_id'] = input('post.vod_tencent_secret_id');
+            $update_array['vod_tencent_secret_key'] = input('post.vod_tencent_secret_key');
+            $update_array['live_push_domain'] = input('param.live_push_domain');
+            $update_array['live_push_key'] = input('param.live_push_key');
+            $update_array['live_play_domain'] = input('param.live_play_domain');
+            $update_array['video_type'] = input('param.video_type');
+            $update_array['aliyun_user_id'] = input('param.aliyun_user_id');
+            $update_array['aliyun_access_key_id'] = input('param.aliyun_access_key_id');
+            $update_array['aliyun_access_key_secret'] = input('param.aliyun_access_key_secret');
+            $update_array['aliyun_live_push_domain'] = input('post.aliyun_live_push_domain');
+            $update_array['aliyun_live_push_key'] = input('post.aliyun_live_push_key');
+            $update_array['aliyun_live_play_domain'] = input('post.aliyun_live_play_domain');
+            $update_array['aliyun_live_play_key'] = input('post.aliyun_live_play_key');
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                dkcache('config');
+                $this->log(lang('ds_edit') . lang('live_setting'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('live_setting'), 0);
+            }
+        }
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_setting'),
+                'url' => url('live_setting/index')
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 105 - 0
app/admin/controller/Login.php

@@ -0,0 +1,105 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\captcha\facade\Captcha;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Login extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/login.lang.php');
+    }
+
+    public function index() {
+        if (session('admin_id')) {
+            $this->success(lang('already_logged'), 'Index/index');
+        }
+        if (request()->isPost()) {
+            $admin_name = input('post.admin_name');
+            $admin_password = input('post.admin_password');
+            $captcha = input('post.captcha');
+
+            $data = array(
+                'admin_name' => $admin_name,
+                'admin_password' => $admin_password,
+                'captcha' => $captcha,
+            );
+
+            $login_validate = ds_validate('admin');
+            if (!$login_validate->scene('index')->check($data)) {
+                ds_json_encode(10001,$login_validate->getError());
+            }
+
+            if (!captcha_check(input('post.captcha'))) {
+                //验证失败
+                ds_json_encode(10001,lang('wrong_checkcode'));
+            }
+            $condition = array();
+            $condition[] = array('admin_name','=',$admin_name);
+            $condition[] = array('admin_password','=',md5($admin_password));
+            $admin_mod=model('admin');
+            $admin_info = $admin_mod->getOneAdmin($condition);
+
+            if (is_array($admin_info) and !empty($admin_info)) {
+                //更新 admin 最新信息
+                $update_info = array(
+                    'admin_login_num' => ($admin_info['admin_login_num'] + 1),
+                    'admin_login_time' => TIMESTAMP
+                );
+                $admin_mod->editAdmin($update_info, $admin_info['admin_id']);
+
+                //设置 session
+                session('admin_id', $admin_info['admin_id']);
+                session('admin_name', $admin_info['admin_name']);
+                session('admin_gid', $admin_info['admin_gid']);
+                session('admin_is_super', $admin_info['admin_is_super']);
+                ds_json_encode(10000,lang('login_succ'), '','',false);
+            } else {
+                ds_json_encode(10001,lang('login_error'));
+            }
+        } else {
+            return View::fetch();
+        }
+    }
+
+    public function logout() {
+        //设置 session
+        session(null);
+        ds_json_encode(10000,lang('logout_succ'), '','',false);
+    }
+    
+    /**
+     *产生验证码
+     */
+    public function makecode()
+    {
+        $config = [
+            'fontSize' => 20, // // 验证码字体大小
+            'length' => 4, // 验证码位数
+            'useNoise' => false,//是否添加杂点
+            'useCurve' =>true,
+            'imageH' => 50,//高度
+            'imageW' => 150,
+        ];
+        config($config,'captcha');
+        $captcha = Captcha::create();
+        return $captcha;
+    }
+
+}
+
+?>

+ 265 - 0
app/admin/controller/Mallconsult.php

@@ -0,0 +1,265 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Mallconsult extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/mallconsult.lang.php');
+    }
+
+    /**
+     * 咨询管理
+     */
+    public function index() {
+        $condition = array();
+        $member_name = trim(input('param.member_name'));
+        if ($member_name != '') {
+            $condition[]=array('member_name','like', '%' . $member_name . '%');
+            View::assign('member_name', $member_name);
+        }
+        $mallconsulttype_id = intval(input('param.mctid'));
+        if ($mallconsulttype_id > 0) {
+            $condition[]=array('mallconsulttype_id','=',$mallconsulttype_id);
+            View::assign('mctid', $mallconsulttype_id);
+        }
+        $mallconsult_model = model('mallconsult');
+        $consult_list = $mallconsult_model->getMallconsultList($condition, '*', 10);
+        View::assign('show_page', $mallconsult_model->page_info->render());
+        View::assign('consult_list', $consult_list);
+
+
+        // 咨询类型列表
+        $type_list = model('mallconsulttype')->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name', 'mallconsulttype_id');
+        View::assign('type_list', $type_list);
+
+        // 回复状态
+        $state = array('0' => lang('state_0'), '1' => lang('state_1'));
+        View::assign('state', $state);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 回复咨询
+     */
+    public function consult_reply() {
+        $mallconsult_model = model('mallconsult');
+        if (request()->isPost()) {
+            $mallconsult_id = intval(input('post.mallconsult_id'));
+            $reply_content = trim(input('post.reply_content'));
+            if ($mallconsult_id <= 0 || $reply_content == '') {
+                $this->error(lang('param_error'));
+            }
+            $update['mallconsult_isreply'] = 1;
+            $update['mallconsult_reply_content'] = $reply_content;
+            $update['mallconsult_replytime'] = TIMESTAMP;
+            $update['admin_id'] = $this->admin_info['admin_id'];
+            $update['admin_name'] = $this->admin_info['admin_name'];
+            $result = $mallconsult_model->editMallconsult(array('mallconsult_id' => $mallconsult_id), $update);
+            if ($result) {
+                $consult_info = $mallconsult_model->getMallconsultInfo(array('mallconsult_id' => $mallconsult_id));
+                // 发送用户消息
+                $param = array();
+                $param['code'] = 'consult_mall_reply';
+                $param['member_id'] = $consult_info['member_id'];
+                //阿里短信参数
+                $param['ali_param'] = array();
+                $param['ten_param'] = array();
+                $param['param'] = array(
+                    'consult_url' => HOME_SITE_URL .'/Membermallconsult/mallconsult_info?id='.$mallconsult_id
+                );
+                //微信模板消息
+                $param['weixin_param'] = array(
+//                    'url' => config('ds_config.h5_site_url').'/member/consult_list',
+                    'data'=>array(
+                        "keyword1" => array(
+                            "value" => date('Y-m-d', $consult_info['mallconsult_addtime']),
+                            "color" => "#333"
+                        ),
+                        "keyword2" => array(
+                            "value" => $consult_info['mallconsult_content'],
+                            "color" => "#333"
+                        ),
+                        "keyword3" => array(
+                            "value" => $consult_info['mallconsult_reply_content'],
+                            "color" => "#333"
+                        )
+                    ),
+                );
+                model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
+
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+            $id = intval(input('param.id'));
+            if ($id <= 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $consult_info = $mallconsult_model->getMallconsultDetail($id);
+            View::assign('consult_info', $consult_info);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除平台客服咨询
+     */
+    public function del_consult() {
+        $mallconsult_id = input('param.mallconsult_id');
+        $mallconsult_id_array = ds_delete_param($mallconsult_id);
+        if ($mallconsult_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[]=array('mallconsult_id','in',$mallconsult_id_array);
+        
+        $result = model('mallconsult')->delMallconsult($condition);
+        if ($result) {
+            $this->log('删除平台客服咨询' . '[ID:' . $mallconsult_id . ']');
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+
+    /**
+     * 咨询类型列表
+     */
+    public function type_list() {
+        $mallconsulttype_model = model('mallconsulttype');
+        $type_list = $mallconsulttype_model->getMallconsulttypeList(array(), 'mallconsulttype_id,mallconsulttype_name,mallconsulttype_sort');
+        View::assign('type_list', $type_list);
+        $this->setAdminCurItem('type_list');
+        return View::fetch();
+    }
+
+    /**
+     * 新增咨询类型
+     */
+    public function type_add() {
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'mallconsulttype_name' => input('post.mallconsulttype_name'),
+                'mallconsulttype_sort' => input('post.mallconsulttype_sort')
+            ];
+            $mallconsult_validate = ds_validate('mallconsult');
+            if (!$mallconsult_validate->scene('type_add')->check($data)) {
+                $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
+            }
+
+            $insert = array();
+            $insert['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
+            $insert['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
+            $insert['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
+            $result = model('mallconsulttype')->addMallconsulttype($insert);
+            if ($result) {
+                $this->log('新增咨询类型', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->log('新增咨询类型', 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        return View::fetch();
+    }
+
+    /**
+     * 编辑咨询类型
+     */
+    public function type_edit() {
+        $mallconsulttype_id = intval(input('param.mallconsulttype_id'));
+        if ($mallconsulttype_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $mallconsulttype_model = model('mallconsulttype');
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'mallconsulttype_name' => input('post.mallconsulttype_name'),
+                'mallconsulttype_sort' => input('post.mallconsulttype_sort')
+            ];
+            $mallconsult_validate = ds_validate('mallconsult');
+            if (!$mallconsult_validate->scene('type_edit')->check($data)) {
+                $this->error(lang('ds_common_op_fail') . $mallconsult_validate->getError());
+            }
+            $condition = array();
+            $condition[] = array('mallconsulttype_id','=',$mallconsulttype_id);
+            $update = array();
+            $update['mallconsulttype_name'] = trim(input('post.mallconsulttype_name'));
+            $update['mallconsulttype_introduce'] = input('post.mallconsulttype_introduce');
+            $update['mallconsulttype_sort'] = intval(input('post.mallconsulttype_sort'));
+            $result = $mallconsulttype_model->editMallconsulttype($condition, $update);
+            if ($result>=0) {
+                $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->log('编辑平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+            $mallconsulttype_info = $mallconsulttype_model->getMallconsulttypeInfo(array('mallconsulttype_id' => $mallconsulttype_id));
+            View::assign('mallconsulttype_info', $mallconsulttype_info);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除咨询类型
+     */
+    public function type_del() {
+        $mallconsulttype_id = input('param.mallconsulttype_id');
+        $mallconsulttype_id_array = ds_delete_param($mallconsulttype_id);
+        if ($mallconsulttype_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[]=array('mallconsulttype_id','in',$mallconsulttype_id_array);
+        $result = model('mallconsulttype')->delMallconsulttype($condition);
+        if ($result) {
+            $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 1);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            $this->log('删除平台客服咨询类型 ID:' . $mallconsulttype_id, 0);
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('mallconsult_index'), 'url' => (string)url('Mallconsult/index')
+            ), array(
+                'name' => 'type_list', 'text' => lang('mallconsult_type_list'), 'url' => (string)url('Mallconsult/type_list')
+            ), array(
+                'name' => 'type_add', 'text' => lang('mallconsult_type_add'), 'url' =>"javascript:dsLayerOpen('".(string)url('Mallconsult/type_add')."','".lang('mallconsult_type_add')."')"
+            ),
+        );
+        if (request()->action() == 'type_edit')
+            $menu_array[] = array(
+                'name' => 'type_edit', 'text' => lang('mallconsult_type_edit'), 'url' => ''
+            );
+        return $menu_array;
+    }
+
+}

+ 276 - 0
app/admin/controller/Mallvouchertemplate.php

@@ -0,0 +1,276 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Mallvouchertemplate extends AdminControl {
+
+    private $quotastate_arr;
+    private $templatestate_arr;
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/mallvouchertemplate.lang.php');
+        if (config('ds_config.voucher_allow') != 1 || config('ds_config.points_isuse') != 1) {
+            $this->error(lang('admin_voucher_unavailable'), 'operation/setting');
+        }
+    }
+    /*
+     * 代金券面额列表
+     */
+
+    public function mallvouchertemplatelist() {
+        //获得代金券金额列表
+        $mallvouchertemplate_model = model('mallvouchertemplate');
+        $condition = array();
+        $mallvouchertemplate_list = $mallvouchertemplate_model->getMallvouchertemplateList($condition,10);
+        View::assign('mallvouchertemplate_list', $mallvouchertemplate_list);
+        View::assign('show_page', $mallvouchertemplate_model->page_info->render());
+        $this->setAdminCurItem('mallvouchertemplatelist');
+        return View::fetch();
+    }
+    
+
+    /*
+     * 添加代金券页面
+     */
+
+    public function mallvouchertemplateadd() {
+        if (request()->isPost()) {
+            $mallvouchertemplate_model = model('mallvouchertemplate');
+            $goodsclass_model = model('goodsclass');
+            
+            //获取代金券所属分类ID集
+            $gc_id = intval(input('post.mallvouchertemplate_gcid'));
+            if($gc_id == 0){
+                $this->error(lang('admin_mallvouchertemplate_gc_error'));
+            }
+            
+            $gc_ids = ',';
+            $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
+            foreach($goodsclasslist as $key => $val){
+               $gc_ids .= $val['gc_id'].',';
+            } 
+            
+            
+            $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
+            $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
+
+            $data = [
+                'mallvouchertemplate_price' => $price,
+                'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
+                'mallvouchertemplate_gcid' => $gc_id,
+                'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
+                'mallvouchertemplate_limit' => $limit,
+                'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
+                'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
+                'mallvouchertemplate_gcidarr' => $gc_ids,
+                'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
+                'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
+                'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
+            ];
+            if ($price >= $limit) {
+                $this->error(lang('admin_mallvouchertemplate_limit_error'));
+            }
+                $rs = $mallvouchertemplate_model->addmallvouchertemplate($data);
+                if ($rs) {
+                    $this->log(lang('ds_add') . lang('admin_mallvouchertemplate_add') . '[' . $data['mallvouchertemplate_title'] . ']');
+                    $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
+                } else {
+                    $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
+                }
+            }
+         else {
+            $mallvouchertemplate_info = array(
+                'mallvouchertemplate_startdate' => TIMESTAMP,
+                'mallvouchertemplate_enddate' => TIMESTAMP+3600*24*7,
+                'mallvouchertemplate_gcid' => '',
+                'mallvouchertemplate_quantity' => '',
+                'mallvouchertemplate_eachlimit'=>''
+            ); 
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            View::assign('info', $mallvouchertemplate_info);
+            View::assign('action', 'add');
+            $this->setAdminCurItem('mallvouchertemplateadd');
+            return View::fetch();
+        }
+    }
+    
+    /*
+     * 添加代金券页面
+     */
+    
+    public function mallvouchertemplateedit() {
+        $id = intval(input('param.mallvouchertemplate_id'));
+        if ($id <= 0) {
+            $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
+        }
+        
+        if (request()->isPost()) {
+            $mallvouchertemplate_model = model('mallvouchertemplate');
+            $goodsclass_model = model('goodsclass');
+            
+            //获取代金券所属分类ID集
+            $gc_id = intval(input('post.mallvouchertemplate_gcid'));
+            if($gc_id == 0){
+                $this->error(lang('admin_mallvouchertemplate_gc_error'));
+            }
+            
+            
+            $gc_ids = ',';
+            
+            if($gc_id > 0){
+               $goodsclasslist = $goodsclass_model->getChildClass($gc_id);
+               foreach($goodsclasslist as $key => $val){
+                   $gc_ids .= $val['gc_id'].',';
+               } 
+            }
+            
+            $limit = intval(input('post.mallvouchertemplate_limit')) > 0 ? intval(input('post.mallvouchertemplate_limit')) : 0;
+            $price = intval(input('post.mallvouchertemplate_price')) > 0 ? intval(input('post.mallvouchertemplate_price')) : 0;
+    
+            $updata = [
+                'mallvouchertemplate_price' => $price,
+                'mallvouchertemplate_title' => input('post.mallvouchertemplate_title'),
+                'mallvouchertemplate_gcid' => $gc_id,
+                'mallvouchertemplate_gcname' => input('post.mallvouchertemplate_gcname'),
+                'mallvouchertemplate_limit' => $limit,
+                'mallvouchertemplate_startdate' => strtotime(input('param.mallvouchertemplate_startdate')),
+                'mallvouchertemplate_enddate' => strtotime(input('param.mallvouchertemplate_enddate')),
+                'mallvouchertemplate_gcidarr' => $gc_ids,
+                'mallvouchertemplate_points' => input('post.mallvouchertemplate_points'),
+                'mallvouchertemplate_quantity' => intval(input('post.mallvouchertemplate_quantity')),
+                'mallvouchertemplate_eachlimit' => intval(input('post.mallvouchertemplate_eachlimit')),
+            ];
+            if ($price >= $limit) {
+                $this->error(lang('admin_mallvouchertemplate_limit_error'));
+            }
+            
+            $condition   = array();
+            $condition[] = array('mallvouchertemplate_id','=',$id);
+            $rs = $mallvouchertemplate_model->editMallvouchertemplate($condition,$updata);
+            
+            if ($rs) {
+                $this->log(lang('ds_edit') . lang('admin_mallvouchertemplate_edit') . '[' . $updata['mallvouchertemplate_title'] . ']');
+                $this->success(lang('ds_common_save_succ'), (string) url('mallvouchertemplate/mallvouchertemplatelist'));
+            } else {
+                $this->error(lang('ds_common_save_fail'), 'mallvouchertemplate/mallvouchertemplatelist');
+            }
+        }else {
+             
+            $mallvouchertemplate_model = model('mallvouchertemplate');
+            $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
+            if (empty($mallvouchertemplate_info)) {
+                $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
+            }
+            
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            View::assign('info', $mallvouchertemplate_info);
+            View::assign('action', 'edit');
+            $this->setAdminCurItem('mallvouchertemplateedit');
+            return View::fetch();
+        }
+    }
+    
+
+    /*
+     * 查看代金券面额
+     */
+
+    public function mallvouchertemplateview() {
+        $id = intval(input('param.mallvouchertemplate_id'));
+        if ($id <= 0) {
+            $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
+        }
+        $mallvouchertemplate_model = model('mallvouchertemplate');
+        $mallvouchertemplate_info = $mallvouchertemplate_model->getOneMallvouchertemplate(array('mallvouchertemplate_id' => $id));
+        if (empty($mallvouchertemplate_info)) {
+            $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
+        }
+        
+        $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+        View::assign('gc_list', $gc_list);
+        View::assign('info', $mallvouchertemplate_info);
+        View::assign('action', 'view');
+        $this->setAdminCurItem('mallvouchertemplateview');
+        return View::fetch('mallvouchertemplateview');
+    }
+
+    /*
+     * 删除代金券面额
+     */
+
+    public function drop() {
+        $mallvouchertemplate_id = trim(input('param.mallvouchertemplate_id'));
+        if (empty($mallvouchertemplate_id)) {
+            $this->error(lang('param_error'), 'Mallvouchertemplate/mallvouchertemplatelist');
+        }
+        $mallvouchertemplate_model = model('mallvouchertemplate');
+        $condition = array();
+        $condition[] = array('mallvouchertemplate_id','in', $mallvouchertemplate_id);
+        $rs = $mallvouchertemplate_model->delMallvouchertemplate($condition);
+        if ($rs) {
+            $this->log(lang('ds_del') . lang('admin_mallvouchertemplate_drop') . '[ID:' . $mallvouchertemplate_id . ']');
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+ 
+
+  
+
+    /**
+     * 页面内导航菜单
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'mallvouchertemplatelist',
+                'text' => lang('admin_mallvouchertemplate_manage'),
+                'url' => (string)url('Mallvouchertemplate/mallvouchertemplatelist')
+            )
+        );
+        if (request()->action() == 'mallvouchertemplateadd' || request()->action() == 'mallvouchertemplatelist') {
+            $menu_array[] = array(
+                'name' => 'mallvouchertemplateadd',
+                'text' => lang('admin_mallvouchertemplate_add'),
+                'url' => (string) url('Mallvouchertemplate/mallvouchertemplateadd')
+            );
+        }
+        if (request()->action() == 'mallvouchertemplateview') {
+            $menu_array[] = array(
+                'name' => 'mallvouchertemplateview',
+                'text' => lang('admin_mallvouchertemplate_view'),
+                'url' => ''
+            );
+        }
+        if (request()->action() == 'mallvouchertemplateedit') {
+            $menu_array[] = array(
+                'name' => 'mallvouchertemplateedit',
+                'text' => lang('admin_mallvouchertemplate_edit'),
+                'url' => ''
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 291 - 0
app/admin/controller/Marketmanage.php

@@ -0,0 +1,291 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 营销活动管理  包含刮刮卡\大转盘\砸金蛋\生肖翻翻看
+ */
+class Marketmanage extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/marketmanage.lang.php');
+        //营销活动类型
+        $this->marketmanage_type_list = model('marketmanage')->marketmanage_type_list();
+        View::assign('marketmanage_type_list', $this->marketmanage_type_list);
+        $this->marketmanage_type = intval(input('param.type'));
+        if (!array_key_exists($this->marketmanage_type, $this->marketmanage_type_list)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('marketmanage_type', $this->marketmanage_type);
+    }
+
+    public function index() {
+        $condition = array();
+        $marketmanage_name = input('param.marketmanage_name');
+        if (!empty($marketmanage_name)) {
+            $condition[]=array('marketmanage_name','like', '%' . $marketmanage_name . '%');
+        }
+        $condition[]=array('marketmanage_type','=',$this->marketmanage_type);
+        $marketmanage_model = model('marketmanage');
+        $marketmanage_list = $marketmanage_model->getMarketmanageList($condition, 10);
+        View::assign('marketmanage_list', $marketmanage_list);
+        View::assign('show_page', $marketmanage_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function add() {
+        if (!request()->isPost()) {
+            $marketmanage = array(
+                'marketmanage_jointype'=>0,
+                'marketmanage_point'=>0,
+                'marketmanage_begintime' => TIMESTAMP,
+                'marketmanage_endtime' => TIMESTAMP+3600*24*7,
+            );
+            View::assign('marketmanage', $marketmanage);
+
+            $marketmanageaward_list = array();
+            for ($i = 1; $i <= 4; $i++) {
+                $marketmanageaward_list[] = array(
+                    'marketmanageaward_level' => $i,
+                    'marketmanageaward_type' => 1,
+                    'marketmanageaward_count' => 0,
+                    'marketmanageaward_probability' => 0,
+                    'marketmanageaward_point' => 0,
+                    'bonus_id' => '',
+                    'vouchertemplate_id' => ''
+                );
+            }
+            View::assign('marketmanageaward_list', $marketmanageaward_list);
+
+            //获取正在进行中的奖品红包活动
+            $condition = array();
+            $condition[] = array('bonus_type','=',3);
+            $condition[] = array('bonus_state','=',1);
+            $bonus_model = model('bonus');
+            $bonus_list = $bonus_model->getBonusList($condition, '');
+            View::assign('bonus_list', $bonus_list);
+            //获取店铺的优惠券列表
+            $condition = array();
+            $condition[]=array('vouchertemplate_state','=',1);
+            $condition[]=array('vouchertemplate_enddate','>', TIMESTAMP);
+            $vouchertemplate_list = Db::name('vouchertemplate')->field('*')->where($condition)->limit(10)->select()->toArray();
+            View::assign('vouchertemplate_list', $vouchertemplate_list);
+            return View::fetch('form');
+        } else {
+            $data_marketmanageaward = array();
+            $total_marketmanageaward_probability = 0;
+            for ($i = 1; $i <= 4; $i++) {
+                $marketmanageaward_probability = intval($_POST['probability_' . $i]);
+                $total_marketmanageaward_probability +=$marketmanageaward_probability;
+                $data_marketmanageaward[] = array(
+                    'marketmanageaward_level' => $i,
+                    'marketmanageaward_type' => intval($_POST['type_' . $i]),
+                    'marketmanageaward_count' => intval($_POST['count_' . $i]),
+                    'marketmanageaward_probability' => $marketmanageaward_probability,//中奖概率
+                    'marketmanageaward_point'=>intval($_POST['point_' . $i]),
+                    'bonus_id'=>isset($_POST['bonus_id_' . $i]) ? intval($_POST['bonus_id_' . $i]) : 0,
+                    'vouchertemplate_id'=> isset($_POST['vouchertemplate_id_' . $i]) ? intval($_POST['vouchertemplate_id_' . $i]) : 0,
+                );
+            }
+            //中奖概率之和应小于 400%
+            if($total_marketmanageaward_probability>400){
+                $this->error(lang('marketmanageaward_probability_error'));
+            }
+            
+
+            $data_marketmanage = array(
+                'marketmanage_name' => input('param.marketmanage_name'),
+                'marketmanage_detail' => input('param.marketmanage_detail'),
+                'marketmanage_begintime' => strtotime(input('param.marketmanage_begintime')),
+                'marketmanage_endtime' => strtotime(input('param.marketmanage_endtime')),
+                'marketmanage_jointype' => intval(input('param.marketmanage_jointype')),
+                'marketmanage_joincount' => intval(input('param.marketmanage_joincount')),
+                'marketmanage_point' => intval(input('param.marketmanage_point_type')) == 0 ? 0 : intval(input('param.marketmanage_point')),
+                'marketmanage_addtime' => TIMESTAMP,
+                'marketmanage_failed' => input('param.marketmanage_failed'),
+                'marketmanage_type' => $this->marketmanage_type,
+            );
+            //添加营销活动
+            $marketmanage_id = model('marketmanage')->addMarketmanage($data_marketmanage);
+            //添加营销活动奖品记录
+            if ($marketmanage_id > 0) {
+                foreach ($data_marketmanageaward as $key => $marketmanageaward) {
+                    $data_marketmanageaward[$key]['marketmanage_id'] = $marketmanage_id;
+                }
+                Db::name('marketmanageaward')->insertAll($data_marketmanageaward);
+                $this->log(lang('ds_add') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    public function edit() {
+        $marketmanage_model = model('marketmanage');
+        $condition = array();
+        $marketmanage_id = intval(input('param.marketmanage_id'));
+        if ($marketmanage_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $condition[] = array('marketmanage_id','=',$marketmanage_id);
+        if (!request()->isPost()) {
+            $marketmanage = $marketmanage_model->getOneMarketmanage($condition);
+            View::assign('marketmanage', $marketmanage);
+            View::assign('marketmanageaward_list', $marketmanage_model->getMarketmanageAwardList($condition));
+
+            //获取正在进行中的奖品红包活动
+            $condition = array();
+            $condition[] = array('bonus_type','=',3);
+            $condition[] = array('bonus_state','=',1);
+            $bonus_model = model('bonus');
+            $bonus_list = $bonus_model->getBonusList($condition, '');
+            View::assign('bonus_list', $bonus_list);
+            //获取店铺的优惠券列表
+            $condition = array();
+            $condition[] = array('vouchertemplate_state','=',1);
+            $condition[]=array('vouchertemplate_enddate','>', TIMESTAMP);
+            $vouchertemplate_list = Db::name('vouchertemplate')->field('*')->where($condition)->limit(10)->select()->toArray();
+            View::assign('vouchertemplate_list', $vouchertemplate_list);
+            return View::fetch('form');
+        } else {
+            $data_marketmanageaward = array();
+            $total_marketmanageaward_probability = 0;
+            for ($i = 1; $i <= 4; $i++) {
+                $marketmanageaward_probability = intval($_POST['probability_' . $i]);
+                $total_marketmanageaward_probability +=$marketmanageaward_probability;
+                $data_marketmanageaward[] = array(
+                    'marketmanageaward_id' => intval($_POST['id_' . $i]), //主键ID 稍后用于修改数据
+                    'marketmanageaward_level' => $i,
+                    'marketmanageaward_type' => intval($_POST['type_' . $i]),
+                    'marketmanageaward_count' => intval($_POST['count_' . $i]),
+                    'marketmanageaward_probability' => $marketmanageaward_probability,//中奖概率
+                    'marketmanageaward_point' => intval($_POST['point_' . $i]),
+                    'bonus_id' => isset($_POST['bonus_id_' . $i]) ? intval($_POST['bonus_id_' . $i]) : 0,
+                    'vouchertemplate_id' => isset($_POST['vouchertemplate_id_' . $i]) ? intval($_POST['vouchertemplate_id_' . $i]) : 0,
+                );
+            }
+            //中奖概率应小于 400%
+            if($total_marketmanageaward_probability>400){
+                $this->error(lang('marketmanageaward_probability_error'));
+            }
+            $data_marketmanage = array(
+                'marketmanage_name' => input('param.marketmanage_name'),
+                'marketmanage_detail' => input('param.marketmanage_detail'),
+                'marketmanage_begintime' => strtotime(input('param.marketmanage_begintime')),
+                'marketmanage_endtime' => strtotime(input('param.marketmanage_endtime')),
+                'marketmanage_jointype' => intval(input('param.marketmanage_jointype')),
+                'marketmanage_joincount' => intval(input('param.marketmanage_joincount')),
+                'marketmanage_point' => intval(input('param.marketmanage_point_type')) == 0 ? 0 : intval(input('param.marketmanage_point')),
+                'marketmanage_failed' => input('param.marketmanage_failed'),
+            );
+            //编辑营销活动
+            model('marketmanage')->editMarketmanage(array('marketmanage_id' => $marketmanage_id), $data_marketmanage);
+            //编辑营销活动奖品记录
+            foreach ($data_marketmanageaward as $key => $marketmanageaward) {
+                $condition = array();
+                $condition[]=array('marketmanageaward_id','=',$marketmanageaward['marketmanageaward_id']);
+                $condition[]=array('marketmanage_id','=',$marketmanage_id);
+                Db::name('marketmanageaward')->where($condition)->update($marketmanageaward);
+            }
+            $this->log(lang('ds_edit') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
+            dsLayerOpenSuccess(lang('ds_common_save_succ'));
+        }
+    }
+    
+    //删除活动
+    public function del()
+    {
+        $marketmanage_id = intval(input('param.marketmanage_id'));
+        if ($marketmanage_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $marketmanage_model = model('marketmanage');
+        $marketmanage_model->delMarketmanage($marketmanage_id);
+        $this->log(lang('ds_edit') . $this->marketmanage_type_list[$this->marketmanage_type] . '[ID' . $marketmanage_id . ']', 1);
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+    
+    
+    //链接信息
+    public function link()
+    {
+        $condition = array();
+        $marketmanage_id = intval(input('param.marketmanage_id'));
+        if ($marketmanage_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $condition[] = array('marketmanage_id','=',$marketmanage_id);
+        $marketmanage_model = model('marketmanage');
+        $marketmanage = $marketmanage_model->getOneMarketmanage($condition);
+        View::assign('marketmanage', $marketmanage);
+        
+        $market_url = '';
+        //1刮刮卡2大转盘3砸金蛋4生肖翻翻看
+        switch ($marketmanage['marketmanage_type']) {
+            case 1:
+                $market_url = config('ds_config.h5_site_url')."/home/marketcard?marketmanage_id=".$marketmanage['marketmanage_id'];
+                break;
+            case 2:
+                $market_url = config('ds_config.h5_site_url')."/home/marketwheel?marketmanage_id=".$marketmanage['marketmanage_id'];
+                break;
+            case 3:
+                $market_url = config('ds_config.h5_site_url')."/home/marketegg?marketmanage_id=".$marketmanage['marketmanage_id'];
+                break;
+            case 4:
+                $market_url = config('ds_config.h5_site_url')."/home/marketzodiac?marketmanage_id=".$marketmanage['marketmanage_id'];
+                break;
+            default:
+                break;
+        }
+        View::assign('market_url', $market_url);
+        
+        return View::fetch();
+    }
+
+        //活动参与记录
+    public function detail() {
+        $condition = array();
+        $marketmanage_id = intval(input('param.marketmanage_id'));
+        if ($marketmanage_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $condition[] = array('marketmanage_id','=',$marketmanage_id);
+        $marketmanage_model = model('marketmanage');
+        $marketmanagelog_list = $marketmanage_model->getMarketmanageLogList($condition, 10);
+        View::assign('marketmanagelog_list', $marketmanagelog_list);
+        View::assign('show_page', $marketmanage_model->page_info->render());
+        return View::fetch();
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Marketmanage/index', ['type' => input('param.type')])
+            ),
+            array(
+                'name' => 'add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Marketmanage/add', ['type' => input('param.type')]) . "','".lang('ds_add')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 284 - 0
app/admin/controller/Member.php

@@ -0,0 +1,284 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Member extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/member.lang.php');
+    }
+
+    public function member() {
+        $member_model = model('member');
+
+
+        //会员级别
+        $member_grade = $member_model->getMemberGradeArr();
+        $search_field_value = input('search_field_value');
+        $search_field_name = input('search_field_name');
+        $condition = array();
+        if ($search_field_value != '') {
+            switch ($search_field_name) {
+                case 'member_name':
+                    $condition[]=array('member_name','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_email':
+                    $condition[]=array('member_email','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_mobile':
+                    $condition[]=array('member_mobile','like', '%' . trim($search_field_value) . '%');
+                    break;
+                case 'member_truename':
+                    $condition[]=array('member_truename','like', '%' . trim($search_field_value) . '%');
+                    break;
+            }
+        }
+        $search_state = input('search_state');
+        switch ($search_state) {
+            case 'no_informallow':
+                $condition[]=array('inform_allow','=','2');
+                break;
+            case 'no_isbuy':
+                $condition[]=array('is_buylimit','=','0');
+                break;
+            case 'no_isallowtalk':
+                $condition[]=array('is_allowtalk','=','0');
+                break;
+            case 'no_memberstate':
+                $condition[]=array('member_state','=','0');
+                break;
+        }
+        //会员等级
+        $search_grade = intval(input('get.search_grade'));
+        if ($search_grade>0 && $member_grade) {
+            if (isset($member_grade[$search_grade + 1]['exppoints'])) {
+                $condition[] = array('member_exppoints','between',array($member_grade[$search_grade]['exppoints'],$member_grade[$search_grade + 1]['exppoints']));
+            }else{
+                $condition[]=array('member_exppoints','>=', $member_grade[$search_grade]['exppoints']);
+            }
+        }
+
+        //排序
+        $order = trim(input('get.search_sort'));
+        if (!in_array($order,array('member_logintime desc','member_loginnum desc'))) {
+            $order = 'member_id desc';
+        }
+        $member_list = $member_model->getMemberList($condition, '*', 10, $order);
+        //整理会员信息
+        if (is_array($member_list) && !empty($member_list)) {
+            foreach ($member_list as $k => $v) {
+                $member_list[$k]['member_addtime'] = $v['member_addtime'] ? date('Y-m-d H:i:s', $v['member_addtime']) : '';
+                $member_list[$k]['member_logintime'] = $v['member_logintime'] ? date('Y-m-d H:i:s', $v['member_logintime']) : '';
+                $member_list[$k]['member_grade'] = ($t = $member_model->getOneMemberGrade($v['member_exppoints'], false, $member_grade)) ? $t['level_name'] : '';
+            }
+        }
+        View::assign('member_grade', $member_grade);
+        View::assign('search_sort', $order);
+        View::assign('search_field_name', trim($search_field_name));
+        View::assign('search_field_value', trim($search_field_value));
+        View::assign('member_list', $member_list);
+        View::assign('show_page', $member_model->page_info->render());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('member');
+        return View::fetch();
+    }
+
+    public function add() {
+        if (!request()->isPost()) {
+            return View::fetch();
+        } else {
+            //需要完善地方 1.对录入数据进行判断  2.对判断用户名是否存在
+            $member_model = model('member');
+            $data = array(
+                'member_name' => trim(input('post.member_name')),
+                'member_password' => input('post.member_password'),
+                'member_email' => input('post.member_email'),
+                'member_truename' => input('post.member_truename'),
+                'member_sex' => input('post.member_sex'),
+                'member_qq' => input('post.member_qq'),
+                'member_ww' => input('post.member_ww'),
+                'member_addtime' => TIMESTAMP,
+                'member_loginnum' => 0,
+                'inform_allow' => 1, //默认允许举报商品
+            );
+            $member_validate = ds_validate('member');
+            if (!$member_validate->scene('add')->check($data)){
+                $this->error($member_validate->getError());
+            }
+            $result = $member_model->addMember($data);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('member_add_fail'));
+            }
+        }
+    }
+
+    public function edit() {
+        //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
+        $member_id = intval(input('param.member_id'));
+        if (empty($member_id)) {
+            $this->error(lang('param_error'));
+        }
+        $member_model = model('member');
+            $condition = array();
+            $condition[] = array('member_id','=',$member_id);
+            $member_array = $member_model->getMemberInfo($condition);
+        if (!request()->isPost()) {
+            View::assign('member_array', $member_array);
+            return View::fetch();
+        } else {
+            $member_mobile=input('post.member_mobile');
+            if($member_mobile==encrypt_show($member_array['member_mobile'],4,4)){
+                $member_mobile=$member_array['member_mobile'];
+            }
+            $data = array(
+                'member_email' => input('post.member_email'),
+                'member_truename' => input('post.member_truename'),
+                'member_sex' => input('post.member_sex'),
+                'member_qq' => input('post.member_qq'),
+                'member_ww' => input('post.member_ww'),
+                'inform_allow' => input('post.inform_allow'),
+                'is_buylimit' => input('post.isbuy'),
+                'is_allowtalk' => input('post.allowtalk'),
+                'member_state' => input('post.member_state'),
+                'member_cityid' => input('post.city_id'),
+                'member_provinceid' => input('post.province_id'),
+                'member_areainfo' => input('post.region'),
+                'member_areaid' => input('post.area_id'),
+                'member_mobile' => $member_mobile,
+                'member_emailbind' => input('post.member_emailbind'),
+                'member_mobilebind' => input('post.member_mobilebind'),
+                'member_auth_state' => input('post.member_auth_state'),
+            );
+
+            if (input('post.member_password')) {
+                $data['member_password'] = md5(input('post.member_password'));
+            }
+            if (input('post.member_paypwd')) {
+                $data['member_paypwd'] = md5(input('post.member_paypwd'));
+            }
+
+            $member_validate = ds_validate('member');
+            if (!$member_validate->scene('edit')->check($data)){
+                $this->error($member_validate->getError());
+            }
+
+            $result = $member_model->editMember(array('member_id'=>$member_id),$data,$member_id);
+            if ($result>=0) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $branch = input('param.branch');
+        $condition=array();
+        switch ($branch) {
+            /**
+             * 验证会员是否重复
+             */
+            case 'check_user_name':
+                $member_model = model('member');
+                $condition[]=array('member_name','=',input('param.member_name'));
+                $condition[]=array('member_id','<>', intval(input('get.member_id')));
+                $list = $member_model->getMemberInfo($condition);
+                if (empty($list)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+            /**
+             * 验证邮件是否重复
+             */
+            case 'check_email':
+                $member_model = model('member');
+                $condition[]=array('member_email','=',input('param.member_email'));
+                $condition[]=array('member_id','<>', intval(input('param.member_id')));
+                $list = $member_model->getMemberInfo($condition);
+                if (empty($list)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    /**
+     * 设置会员状态
+     */
+    public function memberstate() {
+        $member_id = input('param.member_id');
+        $member_id_array = ds_delete_param($member_id);
+        if ($member_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $data['member_state'] = input('param.member_state') ? input('param.member_state') : 0;
+
+        $condition = array();
+        $condition[]=array('member_id','in', $member_id_array);
+        $result = Db::name('member')->where($condition)->update($data);
+        if ($result>=0) {
+            foreach ($member_id_array as $key => $member_id) {
+                dcache($member_id, 'member');
+            }
+            $this->log(lang('ds_edit') .  '[ID:' . implode(',', $member_id_array) . ']', 1);
+            ds_json_encode('10000', lang('ds_common_op_succ'));
+        }else{
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'member',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Member/member')
+            ),
+        );
+        if (request()->action() == 'add' || request()->action() == 'member') {
+            $menu_array[] = array(
+                'name' => 'add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Member/add')."','".lang('ds_add')."')"
+            );
+        }
+        return $menu_array;
+    }
+
+}
+
+?>

+ 140 - 0
app/admin/controller/MemberAuth.php

@@ -0,0 +1,140 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use PHPExcel;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class MemberAuth extends AdminControl {
+
+    const EXPORT_SIZE = 1000;
+    
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/member.lang.php');
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/member_auth.lang.php');
+    }
+
+    public function index() {
+        $member_model = model('member');
+        
+        $search_field_value = input('search_field_value');
+        $search_field_name = input('search_field_name');
+        $condition = '1=1';
+        $filtered=0;
+        $default_condition = array();
+        if ($search_field_value != '') {
+            switch ($search_field_name) {
+                case 'member_name':
+                    $condition.=' AND member_name LIKE "%' . trim($search_field_value) . '%"';
+                    $filtered=1;
+                    break;
+                case 'member_email':
+                    $condition.=' AND member_email LIKE "%' . trim($search_field_value) . '%"';
+                    $filtered=1;
+                    break;
+                case 'member_mobile':
+                    $condition.=' AND member_mobile LIKE "%' . trim($search_field_value) . '%"';
+                    $filtered=1;
+                    break;
+                case 'member_truename':
+                    $condition.=' AND member_truename LIKE "%' . trim($search_field_value) . '%"';
+                    $filtered=1;
+                    break;
+            }
+        }
+        $search_state = input('search_state');
+        switch ($search_state) {
+            case 'check':
+                $condition.=' AND member_auth_state=1';
+                $filtered=1;
+                break;
+            case 'pass':
+                $condition.=' AND member_auth_state=3';
+                $filtered=1;
+                break;
+            case 'fail':
+                $condition.=' AND member_auth_state=2';
+                $filtered=1;
+                break;
+            default:
+                $condition.=' AND member_auth_state IN (1,2,3)';
+        }
+        $member_list = $member_model->getMemberList($condition, '*', 10, 'member_id desc');
+        //整理会员信息
+        if (is_array($member_list) && !empty($member_list)) {
+            foreach ($member_list as $k => $v) {
+                $member_list[$k]['member_addtime'] = $v['member_addtime'] ? date('Y-m-d H:i:s', $v['member_addtime']) : '';
+            }
+        }
+        View::assign('search_field_name', trim($search_field_name));
+        View::assign('search_field_value', trim($search_field_value));
+        View::assign('member_list', $member_list);
+        View::assign('show_page', $member_model->page_info->render());
+
+        View::assign('filtered', $filtered); //是否有查询条件
+
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+    
+    public function verify(){
+        $member_id = input('param.member_id');
+        $state = input('param.state');
+        $message = input('param.message');
+        $member_id_array = ds_delete_param($member_id);
+        if ($member_id_array == FALSE || !in_array($state, array(1,2))) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        
+        if($state==1){
+            $update=array('member_auth_state'=>3);
+        }else{
+            $update=array('member_auth_state'=>2);
+        }
+        if(!model('member')->editMember(array(array('member_auth_state','=',1),array('member_id','in',$member_id_array)),$update)){
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+        if($message){
+            //添加短消息
+                $message_model = model('message');
+                $insert_arr = array();
+                $insert_arr['from_member_id'] = 0;
+                $insert_arr['member_id'] = "," . implode(',', $member_id_array) . ",";
+                $insert_arr['msg_content'] = lang('member_auth_fail').':'.$message;
+                $insert_arr['message_type'] = 1;
+                $insert_arr['message_ismore'] = 1;
+                $message_model->addMessage($insert_arr);
+        }
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_list'),
+                'url' => (string)url('MemberAuth/index')
+            ),
+        );
+
+        return $menu_array;
+    }
+
+}
+
+?>

+ 90 - 0
app/admin/controller/Membergrade.php

@@ -0,0 +1,90 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Membergrade extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/membergrade.lang.php');
+    }
+    public function index() {
+        if (request()->isPost()) {
+            $update_arr = array();
+            if (!empty(input('post.mg/a'))) {
+                $mg_arr = array();
+                $i = 1;
+                $max_exppoints = '-1';#用户判断 下级会员等级积分应大于上级等级积分
+                foreach (input('post.mg/a') as $k => $v) {
+                    $mg_arr[$i]['level'] = $i;
+                    $level_name = $v['level_name'];
+                    $exppoints  = intval($v['exppoints']);
+                    if(empty($level_name)){
+                        $this->error(lang('param_error'));
+                    }
+                    $mg_arr[$i]['level_name'] = $level_name;
+                    //所需经验值
+                    if($max_exppoints>=$exppoints){
+                        $this->error($level_name.lang('exppoints_greater_than').$max_exppoints);
+                    }else{
+                        $mg_arr[$i]['exppoints'] = $exppoints;
+                    }
+                    $max_exppoints = $exppoints;
+                    $i++;
+                }
+                $update_arr['member_grade'] = serialize($mg_arr);
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+            $result = true;
+            if ($update_arr) {
+                $config_model = model('config');
+                $result = $config_model->editConfig($update_arr);
+            }
+            if ($result) {
+                $this->log(lang('ds_edit') . lang('ds_member_grade'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('ds_member_grade'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_config = rkcache('config', true);
+            $membergrade_list = $list_config['member_grade'] ? unserialize($list_config['member_grade']) : array();
+            foreach ($membergrade_list as $key => $value) {
+                $maxlevel[]=$value['level'];
+            }
+            View::assign('maxlevel', max($maxlevel)+1);
+            View::assign('membergrade_list', $membergrade_list);
+            $this->setAdminCurItem('index');
+            return View::fetch();
+        }
+    }
+    
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Membergrade/index')
+            )
+        );
+        return $menu_array;
+    }
+}

+ 832 - 0
app/admin/controller/Message.php

@@ -0,0 +1,832 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use AlibabaCloud\Client\AlibabaCloud;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Message extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/message.lang.php');
+    }
+
+    /**
+     * 邮件设置
+     */
+    public function email() {
+        $config_model = model('config');
+        if (!(request()->isPost())) {
+            $list_config = rkcache('config', true);
+            View::assign('list_config', $list_config);
+
+            $this->setAdminCurItem('email');
+            return View::fetch('email');
+        } else {
+            $update_array = array();
+            $update_array['email_host'] = input('post.email_host');
+            $update_array['email_secure'] = input('post.email_secure');
+            $update_array['email_port'] = input('post.email_port');
+            $update_array['email_addr'] = input('post.email_addr');
+            $update_array['email_id'] = input('post.email_id');
+            $update_array['email_pass'] = input('post.email_pass');
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('email_set'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('email_set'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 短信平台设置
+     */
+    public function mobile() {
+        $config_model = model('config');
+        if (!(request()->isPost())) {
+            $list_config = rkcache('config', true);
+
+            $smscf_num = '';
+            if($list_config['smscf_type']=='wj' && !empty($list_config['smscf_wj_username'])&&!empty($list_config['smscf_wj_key'])){
+                //如果配置了信息,可以查看具体可用短信条数
+                $smscf_num = http_request('http://www.smschinese.cn/web_api/SMS/?Action=SMS_Num&Uid='.$list_config['smscf_wj_username'].'&Key='.$list_config['smscf_wj_key'],'get');
+            }
+            View::assign('smscf_num', $smscf_num);
+            View::assign('list_config', $list_config);
+
+            $this->setAdminCurItem('mobile');
+            return View::fetch('mobile');
+        } else {
+            $update_array = array();
+            $update_array['smscf_type'] = input('post.smscf_type');
+            $update_array['smscf_ali_id'] = input('post.smscf_ali_id');
+            $update_array['smscf_ali_secret'] = input('post.smscf_ali_secret');
+            $update_array['smscf_ten_id'] = input('post.smscf_ten_id');
+            $update_array['smscf_ten_secret'] = input('post.smscf_ten_secret');
+            $update_array['smscf_sign'] = input('post.smscf_sign');
+            $update_array['smscf_wj_username'] = input('post.smscf_wj_username');
+            $update_array['smscf_wj_key'] = input('post.smscf_wj_key');
+            $update_array['sms_register'] = input('post.sms_register');
+            $update_array['sms_login'] = input('post.sms_login');
+            $update_array['sms_password'] = input('post.sms_password');
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('message_mobile'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('message_mobile'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 短信发送日志
+     */
+    public function smslog()
+    {
+        $condition = array();
+
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[]=array('smslog_smstime','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to));
+            if ($add_time_to !== false) {
+                $add_time_to=$add_time_to+86399;
+                $condition[]=array('smslog_smstime','<=', $add_time_to);
+            }
+        }
+        $member_name = input('get.member_name');
+        if(!empty($member_name)){
+            $condition[]=array('member_name','like',"%" . $member_name . "%");
+        }
+        $smslog_phone = input('get.smslog_phone');
+        if(!empty($smslog_phone)){
+            $condition[]=array('smslog_phone','like',"%" . $smslog_phone . "%");
+        }
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $condition[]=array('smslog_state','<>',0);
+        $smslog_model = model('smslog');
+        $smslog_list = $smslog_model->getSmsList($condition,10);
+        View::assign('smslog_list', $smslog_list);
+        View::assign('show_page', $smslog_model->page_info->render());
+
+        
+
+        $this->setAdminCurItem('smslog');
+        return View::fetch();
+    }
+
+    /**
+     * 短信日志删除
+     */
+    public function smslog_del(){
+        $smslog_id = input('param.smslog_id');
+        $smslog_id_array = ds_delete_param($smslog_id);
+        if ($smslog_id_array === FALSE) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array();
+        $smslog_model = model('smslog');
+        $condition[]=array('smslog_id','in', $smslog_id_array);
+        $smslog_list = $smslog_model->delSmsLog($condition);
+        if ($smslog_list) {
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 邮件模板列表
+     */
+    public function email_tpl() {
+        $mailtemplates_model = model('mailtemplates');
+        $templates_list = $mailtemplates_model->getTplList();
+        View::assign('templates_list', $templates_list);
+        $this->setAdminCurItem('email_tpl');
+        return View::fetch('email_tpl');
+    }
+
+    /**
+     * 编辑邮件模板
+     */
+    public function email_tpl_edit() {
+        $mailtemplates_model = model('mailtemplates');
+        if (!request()->isPost()) {
+            if (!(input('param.code'))) {
+                $this->error(lang('mailtemplates_edit_code_null'));
+            }
+            $templates_array = $mailtemplates_model->getTplInfo(array('mailmt_code' => input('param.code')));
+            View::assign('templates_array', $templates_array);
+            $this->setAdminCurItem('email_tpl_edit');
+            return View::fetch('email_tpl_edit');
+        } else {
+            $data = array(
+                'code' => input('post.code'),
+                'title' => input('post.title'),
+                'content' => input('post.content'),
+            );
+            $mailtemplatese_validate = ds_validate('mailtemplates');
+            if (!$mailtemplatese_validate->scene('email_tpl_edit')->check($data)) {
+                $this->error($mailtemplatese_validate->getError());
+            } else {
+                $update_array = array();
+                $update_array['mailmt_code'] = input('post.code');
+                $update_array['mailmt_title'] = input('post.title');
+                $update_array['mailmt_content'] = input('post.content');
+                $result = $mailtemplates_model->editTpl($update_array, array('mailmt_code' => input('post.code')));
+                if ($result>=0) {
+                    $this->log(lang('ds_edit') . lang('email_tpl'), 1);
+                    $this->success(lang('mailtemplates_edit_succ'), 'admin/Message/email_tpl');
+                } else {
+                    $this->log(lang('ds_edit') . lang('email_tpl'), 0);
+                    $this->error(lang('mailtemplates_edit_fail'));
+                }
+            }
+        }
+    }
+
+    /**
+     * 测试邮件发送
+     *
+     * @param
+     * @return
+     */
+    public function email_testing() {
+        /**
+         * 读取语言包
+         */
+        $email_host = trim(input('post.email_host'));
+        $email_secure = trim(input('post.email_secure'));
+        $email_port = trim(input('post.email_port'));
+        $email_addr = trim(input('post.email_addr'));
+        $email_id = trim(input('post.email_id'));
+        $email_pass = trim(input('post.email_pass'));
+        $email_test = trim(input('post.email_test'));
+        $subject = lang('test_email');
+        $site_url = HOME_SITE_URL;
+
+        /**
+        //邮件发送测试
+        $email_host = 'smtp.126.com';
+        $email_secure = 'tls';//tls ssl
+        $email_port = '25';//465 25
+        $email_addr = '';
+        $email_id = '';
+        $email_pass = '';
+        $email_test = '181814630@qq.com';
+        */
+
+        $site_name = config('ds_config.site_name');
+        $message = '<p>' . lang('this_is_to') . "<a href='" . $site_url . "' target='_blank'>" . $site_name . '</a>' . lang('test_email_set_ok') . '</p>';
+
+        $obj_email = new \sendmsg\Email();
+        $obj_email->set('email_server', $email_host);
+        $obj_email->set('email_secure', $email_secure);
+        $obj_email->set('email_port', $email_port);
+        $obj_email->set('email_user', $email_id);
+        $obj_email->set('email_password', $email_pass);
+        $obj_email->set('email_from', $email_addr);
+        $obj_email->set('site_name', $site_name);
+        $result = $obj_email->send($email_test, $subject, $message);
+        if ($result === false) {
+            $data['msg'] = lang('test_email_send_fail');
+            echo json_encode($data);exit;
+        } else {
+            $data['msg'] = lang('test_email_send_ok');
+            echo json_encode($data);exit;
+        }
+    }
+
+    /**
+     * 测试手机短信发送
+     *
+     * @param
+     * @return
+     */
+    public function mobile_testing() {
+        $mobile = input('param.mobile_test');
+        $content = input('param.mobile_test_content');
+        $smscf_type = input('param.smscf_type');
+        $smscf_ali_id = input('param.smscf_ali_id');
+        $smscf_ali_secret = input('param.smscf_ali_secret');
+        $ali_template_param = input('param.ali_template_param');
+        $ali_template_code = input('param.ali_template_code');
+        $ali_template_content = input('param.ali_template_content');
+        $smscf_ten_id = input('param.smscf_ten_id');
+        $smscf_ten_secret = input('param.smscf_ten_secret');
+        $ten_template_param = input('param.ten_template_param');
+        $ten_template_code = input('param.ten_template_code');
+        $ten_template_content = input('param.ten_template_content');
+        $user_id = urlencode(input('param.smscf_wj_username')); // 这里填写用户名
+        $key = urlencode(input('param.smscf_wj_key')); // 这里填接口安全密钥
+        $smscf_sign = input('param.smscf_sign');
+        config('ds_config.smscf_type', $smscf_type);
+        config('ds_config.smscf_wj_username', $user_id);
+        config('ds_config.smscf_wj_key', $key);
+        config('ds_config.smscf_ali_id', $smscf_ali_id);
+        config('ds_config.smscf_ali_secret', $smscf_ali_secret);
+        config('ds_config.smscf_ten_id', $smscf_ten_id);
+        config('ds_config.smscf_ten_secret', $smscf_ten_secret);
+        config('ds_config.smscf_sign', $smscf_sign);
+        $smslog_param = array(
+            'ali_template_code' => $ali_template_code,
+            'ali_template_param' => array(),
+            'ten_template_code' => $ten_template_code,
+            'ten_template_param' => array(),
+        );
+        if ($smscf_type == 'wj') {
+            $smslog_param['message'] = $content;
+        } elseif ($smscf_type == 'ali') {
+            $param = json_decode(htmlspecialchars_decode($ali_template_param), true);
+            if (!$param) {
+                echo json_encode(array('msg' => lang('ali_template_param_error')));
+                exit;
+            }
+            $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ali_template_content), $param);
+            $smslog_param['ali_template_param'] = $param;
+        } elseif ($smscf_type == 'ten') {
+            $param = json_decode(htmlspecialchars_decode($ten_template_param), true);
+            if (!$param) {
+                echo json_encode(array('msg' => lang('ten_template_param_error')));
+                exit;
+            }
+            $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ten_template_content), $param);
+            $smslog_param['ten_template_param'] = $param;
+        } else {
+            echo json_encode(array('msg' => lang('param_error')));
+            exit;
+        }
+
+        $result = model('smslog')->sendSms($mobile, $smslog_param);
+
+        if ($result['code'] == 10000) {
+            $data['msg'] = '测试手机短信发送成功';
+        } else {
+            $data['msg'] = $result['message'];
+        }
+        echo json_encode($data);
+        exit;
+    }
+
+    /**
+     * 商家消息模板
+     */
+    public function seller_tpl()
+    {
+        $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
+        View::assign('mstpl_list', $mstpl_list);
+        $this->setAdminCurItem('seller_tpl');
+        return View::fetch('seller_tpl');
+    }
+
+    /**
+     * 商家消息模板编辑
+     */
+    public function seller_tpl_edit() {
+        if (!request()->isPost()) {
+            $code = trim(input('param.code'));
+            if (empty($code)) {
+                $this->error(lang('param_error'));
+            }
+            $condition = array();
+            $condition[] = array('storemt_code','=',$code);
+            $smtpl_info = model('storemsgtpl')->getStoremsgtplInfo($condition);
+            View::assign('smtpl_info', $smtpl_info);
+            $this->setAdminCurItem('seller_tpl_edit');
+            return View::fetch('seller_tpl_edit');
+        } else {
+            $code = trim(input('post.code'));
+            $type = trim(input('post.type'));
+            if (empty($code) || empty($type)) {
+                $this->error(lang('param_error'));
+            }
+            switch ($type) {
+                case 'message':
+                    $this->seller_tpl_update_message();
+                    break;
+                case 'short':
+                    $this->seller_tpl_update_short();
+                    break;
+                case 'mail':
+                    $this->seller_tpl_update_mail();
+                    break;
+                case 'weixin':
+                    $this->seller_tpl_update_weixin();
+                    break;
+            }
+        }
+    }
+
+    /**
+     * 商家消息模板更新站内信
+     */
+    private function seller_tpl_update_message() {
+        $message_content = trim(input('post.message_content'));
+        if (empty($message_content)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('storemt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['storemt_message_switch'] = intval(input('post.message_switch'));
+        $update['storemt_message_content'] = $message_content;
+        $update['storemt_message_forced'] = intval(input('post.message_forced'));
+        $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
+        $this->seller_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新短消息
+     */
+    private function seller_tpl_update_short() {
+        $short_content = trim(input('post.short_content'));
+        if (empty($short_content)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('storemt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['storemt_short_switch'] = intval(input('post.short_switch'));
+        $update['storemt_short_content'] = $short_content;
+        $update['smt_short_forced'] = intval(input('post.short_forced'));
+        $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
+        $this->seller_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新邮件
+     */
+    private function seller_tpl_update_mail() {
+        $mail_subject = trim(input('post.mail_subject'));
+        $mail_content = trim(input('post.mail_content'));
+        if ((empty($mail_subject) || empty($mail_content))) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('storemt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['storemt_mail_switch'] = intval(input('post.mail_switch'));
+        $update['storemt_mail_subject'] = $mail_subject;
+        $update['storemt_mail_content'] = $mail_content;
+        $update['storemt_mail_forced'] = intval(input('post.mail_forced'));
+        $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
+        $this->seller_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新邮件
+     */
+    private function seller_tpl_update_weixin() {
+        $weixin_code = trim(input('post.weixin_code'));
+        if (empty($weixin_code)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('storemt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['storemt_weixin_switch'] = intval(input('post.weixin_switch'));
+        $update['storemt_weixin_code'] = $weixin_code;
+        $update['storemt_weixin_forced'] = intval(input('post.weixin_forced'));
+        $result = model('storemsgtpl')->editStoremsgtpl($condition, $update);
+        $this->seller_tpl_update_showmessage($result);
+    }
+
+    private function seller_tpl_update_showmessage($result) {
+        if ($result>=0) {
+            $this->success(lang('ds_common_op_succ'), (string)url('Message/seller_tpl'));
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 用户消息模板
+     */
+    public function member_tpl() {
+        $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
+        View::assign('mmtpl_list', $mmtpl_list);
+        $this->setAdminCurItem('member_tpl');
+        return View::fetch('member_tpl');
+    }
+
+    /**
+     * 用户消息模板编辑
+     */
+    public function member_tpl_edit() {
+        if (!request()->isPost()) {
+            $code = trim(input('param.code'));
+            if (empty($code)) {
+                $this->error(lang('param_error'));
+            }
+            $condition = array();
+            $condition[] = array('membermt_code','=',$code);
+            $mmtpl_info = model('membermsgtpl')->getMembermsgtplInfo($condition);
+            View::assign('mmtpl_info', $mmtpl_info);
+            $this->setAdminCurItem('member_tpl_edit');
+            return View::fetch('member_tpl_edit');
+        } else {
+            $code = trim(input('post.code'));
+            $type = trim(input('post.type'));
+            if (empty($code) || empty($type)) {
+                $this->error(lang('param_error'));
+            }
+            switch ($type) {
+                case 'message':
+                    $this->member_tpl_update_message();
+                    break;
+                case 'short':
+                    $this->member_tpl_update_short();
+                    break;
+                case 'mail':
+                    $this->member_tpl_update_mail();
+                    break;
+                case 'weixin':
+                    $this->member_tpl_update_weixin();
+                    break;
+            }
+        }
+    }
+
+    public function ali_tpl(){
+        $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
+        $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
+        $mailtemplates_model = model('mailtemplates');
+        $templates_list = $mailtemplates_model->getTplList(array(array('mailmt_code','<>','bind_email')));
+        View::assign('mstpl_list',$mstpl_list);
+        View::assign('mmtpl_list',$mmtpl_list);
+        View::assign('templates_list',$templates_list);
+        $this->setAdminCurItem('message_ali_tpl');
+        return View::fetch();
+    }
+
+    public function ali_tpl_edit(){
+        $type=input('param.type');
+        $code=input('param.code');
+        $name=input('param.name');
+        switch($type){
+            case 'membermsgtpl':
+                if (!model('membermsgtpl')->editMembermsgtpl(array('membermt_code' => $name), array('ali_template_code' => $code))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            case 'storemsgtpl':
+                if (!model('storemsgtpl')->editStoremsgtpl(array('storemt_code' => $name), array('ali_template_code' => $code))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            case 'mailmsgtemlates':
+                if (!model('mailtemplates')->editTpl(array('ali_template_code' => $code), array('mailmt_code' => $name))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            default:
+                ds_json_encode(10001, lang('param_error'));
+        }
+    }
+
+    public function ali_tpl_query() {
+        $code = input('param.code');
+
+        AlibabaCloud::accessKeyClient(config('ds_config.smscf_ali_id'), config('ds_config.smscf_ali_secret'))
+                ->regionId('cn-hangzhou')
+                ->asDefaultClient();
+
+        try {
+            $result = AlibabaCloud::rpc()
+                    ->product('Dysmsapi')
+                    // ->scheme('https') // https | http
+                    ->version('2017-05-25')
+                    ->action('QuerySmsTemplate')
+                    ->method('POST')
+                    ->host('dysmsapi.aliyuncs.com')
+                    ->options([
+                        'query' => [
+                            'RegionId' => "cn-hangzhou",
+                            'TemplateCode' => $code,
+                        ],
+                    ])
+                    ->request();
+
+        } catch (\Exception $e) {
+            ds_json_encode(10001, $e->getErrorMessage());
+        }
+        ds_json_encode(10000, lang('ds_common_op_succ'),$result->toArray());
+    }
+
+    public function ten_tpl() {
+        $mstpl_list = model('storemsgtpl')->getStoremsgtplList(array());
+        $mmtpl_list = model('membermsgtpl')->getMembermsgtplList(array());
+        $mailtemplates_model = model('mailtemplates');
+        $templates_list = $mailtemplates_model->getTplList(array(array('mailmt_code','<>', 'bind_email')));
+        View::assign('mstpl_list', $mstpl_list);
+        View::assign('mmtpl_list', $mmtpl_list);
+        View::assign('templates_list', $templates_list);
+        $this->setAdminCurItem('message_ten_tpl');
+        return View::fetch();
+    }
+
+    public function ten_tpl_edit() {
+        $type = input('param.type');
+        $code = input('param.code');
+        $name = input('param.name');
+        switch ($type) {
+            case 'membermsgtpl':
+                if (!model('membermsgtpl')->editMembermsgtpl(array('membermt_code' => $name), array('ten_template_code' => $code))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            case 'storemsgtpl':
+                if (!model('storemsgtpl')->editStoremsgtpl(array('storemt_code' => $name), array('ten_template_code' => $code))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            case 'mailmsgtemlates':
+                if (!model('mailtemplates')->editTpl(array('ten_template_code' => $code), array('mailmt_code' => $name))) {
+                    ds_json_encode(10001, lang('ds_common_op_fail'));
+                } else {
+                    ds_json_encode(10000, lang('ds_common_op_succ'));
+                }
+                break;
+            default:
+                ds_json_encode(10001, lang('param_error'));
+        }
+    }
+
+    //接口
+    public function ten_tpl_query() {
+        $code = input('param.code');
+        // 短信应用 SDK AppID
+        $appid = config('ds_config.smscf_ten_id'); // SDK AppID 以1400开头
+        // 短信应用 SDK AppKey
+        $appkey = config('ds_config.smscf_ten_secret');
+        try {
+            $cred = new Credential($appid,$appkey);
+            $httpProfile = new HttpProfile();
+            $httpProfile->setEndpoint("sms.tencentcloudapi.com");
+
+            $clientProfile = new ClientProfile();
+            $clientProfile->setHttpProfile($httpProfile);
+            $client = new SmsClient($cred,"",$clientProfile);
+
+            $req = new DescribeSmsTemplateListRequest();
+
+            $params = array($code);
+            $req->fromJsonString($params);
+
+            $result = $client->DescribeSmsTemplateList($req);
+
+            $rsp = json_decode($result);
+        } catch (\Exception $e) {
+            echo var_dump($e);
+        }
+        ds_json_encode(10000, lang('ds_common_op_succ'), $rsp->toArray());
+    }
+
+    /**
+     * 商家消息模板更新站内信
+     */
+    private function member_tpl_update_message() {
+        $message_content = trim(input('post.message_content'));
+        if (empty($message_content)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('membermt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['membermt_message_switch'] = intval(input('post.message_switch'));
+        $update['membermt_message_content'] = $message_content;
+        $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
+        $this->member_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新短消息
+     */
+    private function member_tpl_update_short() {
+        $short_content = trim(input('post.short_content'));
+        if (empty($short_content)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('membermt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['membermt_short_switch'] = intval(input('post.short_switch'));
+        $update['membermt_short_content'] = $short_content;
+        $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
+        $this->member_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新邮件
+     */
+    private function member_tpl_update_weixin() {
+        $weixin_code = trim(input('post.weixin_code'));
+        if (empty($weixin_code)) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('membermt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['membermt_weixin_switch'] = intval(input('post.weixin_switch'));
+        $update['membermt_weixin_code'] = $weixin_code;
+        $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
+        $this->member_tpl_update_showmessage($result);
+    }
+
+    /**
+     * 商家消息模板更新邮件
+     */
+    private function member_tpl_update_mail() {
+        $mail_subject = trim(input('post.mail_subject'));
+        $mail_content = trim(input('post.mail_content'));
+        if ((empty($mail_subject) || empty($mail_content))) {
+            $this->error(lang('param_error'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('membermt_code','=',trim(input('post.code')));
+        // 数据
+        $update = array();
+        $update['membermt_mail_switch'] = intval(input('post.mail_switch'));
+        $update['membermt_mail_subject'] = $mail_subject;
+        $update['membermt_mail_content'] = $mail_content;
+        $result = model('membermsgtpl')->editMembermsgtpl($condition, $update);
+        $this->member_tpl_update_showmessage($result);
+    }
+
+    private function member_tpl_update_showmessage($result) {
+        if ($result>=0) {
+            $this->success(lang('ds_common_op_succ'), (string)url('Message/member_tpl'));
+        } else {
+            $this->error(lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'email',
+                'text' => lang('email_set'),
+                'url' => (string)url('Message/email')
+            ),
+            array(
+                'name' => 'mobile',
+                'text' => lang('message_mobile'),
+                'url' => (string)url('Message/mobile')
+            ),
+            array(
+                'name' => 'smslog',
+                'text' => lang('message_smslog'),
+                'url' => (string)url('Message/smslog')
+            ),
+            array(
+                'name' => 'seller_tpl',
+                'text' => lang('message_seller_tpl'),
+                'url' => (string)url('Message/seller_tpl')
+            ),
+            array(
+                'name' => 'member_tpl',
+                'text' => lang('message_member_tpl'),
+                'url' => (string)url('Message/member_tpl')
+            ),
+            array(
+                'name' => 'email_tpl',
+                'text' => lang('message_email_tpl'),
+                'url' => (string)url('Message/email_tpl')
+            ),
+        );
+        if(config('ds_config.smscf_type')=='ali'){
+            array_splice($menu_array, 2, 0, array(array(
+                'name' => 'message_ali_tpl',
+                'text' => lang('message_ali_tpl'),
+                'url' => (string)url('Message/ali_tpl')
+            )));
+        }
+        if (config('ds_config.smscf_type') == 'ten') {
+            array_splice($menu_array, 2, 0, array(array(
+                'name' => 'message_ten_tpl',
+                'text' => lang('message_ten_tpl'),
+                'url' => (string)url('Message/ten_tpl')
+            )));
+        }
+        if (request()->action() == 'seller_tpl_edit') {
+            $menu_array[] = array(
+                'name' => 'seller_tpl_edit',
+                'text' => lang('message_seller_tpl_edit'),
+                'url' => "javascript:void(0)"
+            );
+        }
+        if (request()->action() == 'member_tpl_edit') {
+            $menu_array[] = array(
+                'name' => 'member_tpl_edit',
+                'text' => lang('message_member_tpl_edit'),
+                'url' => "javascript:void(0)"
+            );
+        }
+        if (request()->action() == 'email_tpl_edit') {
+            $menu_array[] = array(
+                'name' => 'email_tpl_edit',
+                'text' => lang('message_email_tpl_edit'),
+                'url' => "javascript:void(0)"
+            );
+        }
+
+
+        return $menu_array;
+    }
+
+}
+
+?>

+ 141 - 0
app/admin/controller/Navigation.php

@@ -0,0 +1,141 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Navigation extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/navigation.lang.php');
+    }
+
+    public function index() {
+        $navigation_model = model('navigation');
+        $condition = array();
+        $nav_title = input('param.nav_title');
+        if (!empty($nav_title)) {
+            $condition[]=array('nav_title','like', "%" . $nav_title . "%");
+        }
+        $nav_location = input('param.nav_location');
+        if (!empty($nav_location)) {
+            $condition[]=array('nav_location','=',$nav_location);
+        }
+        $nav_list = $navigation_model->getNavigationList($condition, 10);
+        View::assign('nav_list', $nav_list);
+        View::assign('show_page', $navigation_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function add() {
+        if (!(request()->isPost())) {
+            $nav = [
+                'nav_location' => 'header',
+                'nav_new_open' => 0,
+            ];
+            View::assign('nav', $nav);
+            return View::fetch('form');
+        } else {
+            $data['nav_title'] = input('post.nav_title');
+            $data['nav_location'] = input('post.nav_location');
+            $data['nav_url'] = input('post.nav_url');
+            $data['nav_new_open'] = intval(input('post.nav_new_open'));
+            $data['nav_sort'] = intval(input('post.nav_sort'));
+            $navigation_validate = ds_validate('navigation');
+            if (!$navigation_validate->scene('add')->check($data)) {
+                $this->error($navigation_validate->getError());
+            }
+
+            $navigation_model= model('navigation');
+            $result=$navigation_model->addNavigation($data);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('error'));
+            }
+        }
+    }
+
+    public function edit() {
+        $navigation_model= model('navigation');
+        $nav_id = input('param.nav_id');
+        if (empty($nav_id)) {
+            $this->error(lang('param_error'));
+        }
+        if (!request()->isPost()) {
+            $condition = array();
+            $condition[] = array('nav_id','=',$nav_id);
+            $nav=$navigation_model->getOneNavigation($condition);
+            View::assign('nav', $nav);
+            return View::fetch('form');
+        } else {
+            $data['nav_title'] = input('post.nav_title');
+            $data['nav_location'] = input('post.nav_location');
+            $data['nav_url'] = input('post.nav_url');
+            $data['nav_new_open'] = intval(input('post.nav_new_open'));
+            $data['nav_sort'] = intval(input('post.nav_sort'));
+            $navigation_validate = ds_validate('navigation');
+            if (!$navigation_validate->scene('edit')->check($data)) {
+                $this->error($navigation_validate->getError());
+            }
+            $condition = array();
+            $condition[] = array('nav_id','=',$nav_id);
+            $result = $navigation_model->eidtNavigation($data,$condition);
+            if ($result>=0) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('error'));
+            }
+        }
+    }
+
+    public function drop() {
+        $navigation_model= model('navigation');
+        $nav_id = input('param.nav_id');
+        $nav_id_array = ds_delete_param($nav_id);
+        if($nav_id_array === FALSE){
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array(array('nav_id', 'in', $nav_id_array));
+        $result =$navigation_model->delNavigation($condition);
+        if ($result) {
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Navigation/index')
+            ),
+            array(
+                'name' => 'add',
+                'text' => lang('ds_add'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Navigation/add')."','".lang('ds_add')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 135 - 0
app/admin/controller/Notice.php

@@ -0,0 +1,135 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Notice extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/notice.lang.php');
+    }
+
+    /**
+     * 发送通知列表
+     */
+    public function index()
+    {
+        $special_condition = array();
+        $special_condition['message_type'] = 1;
+        $message_model = model('message');
+        $message_list = $message_model->getMessageList($special_condition,10);
+        View::assign('message_list', $message_list);
+        View::assign('show_page', $message_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+    /**
+     * 会员通知
+     */
+    public function notice(){
+        //提交
+        if (request()->isPost()) {
+            $notice_validate = ds_validate('notice');
+            $content = trim(input('param.content1')); //信息内容
+            $send_type = intval(input('param.send_type'));
+            //验证
+            switch ($send_type) {
+                //指定会员
+                case 1:
+                    $data = [
+                        "user_name" => input("param.user_name")
+                    ];
+                    if (!$notice_validate->scene('notice1')->check($data)) {
+                        $this->error($notice_validate->getError());
+                    }
+                    break;
+                //全部会员
+                case 2:
+                    break;
+            }
+            $data = [
+                "content1" => $content
+            ];
+            if (!$notice_validate->scene('notice2')->check($data)) {
+                $this->error($notice_validate->getError());
+            } else {
+                //发送会员ID 数组
+                $memberid_list = array();
+                //整理发送列表
+                //指定会员
+                if ($send_type == 1) {
+                    $member_model = model('member');
+                    $tmp = explode("\n", input('param.user_name'));
+                    if (!empty($tmp)) {
+                        foreach ($tmp as $k => $v) {
+                            $tmp[$k] = trim($v);
+                        }
+                        //查询会员列表
+                        $member_list = $member_model->getMemberList(array(array('member_name' ,'in', $tmp)));
+                        unset($membername_str);
+                        if (!empty($member_list)) {
+                            foreach ($member_list as $k => $v) {
+                                $memberid_list[] = $v['member_id'];
+                            }
+                        }
+                        unset($member_list);
+                    }
+                    unset($tmp);
+                }
+                if (empty($memberid_list) && $send_type != 2) {
+                    $this->error(lang('notice_index_member_error'));
+                }
+                //接收内容
+                $array = array();
+                $array['send_mode'] = 1;
+                $array['user_name'] = $memberid_list;
+                $array['content'] = $content;
+                //添加短消息
+                $message_model = model('message');
+                $insert_arr = array();
+                $insert_arr['from_member_id'] = 0;
+                if ($send_type == 2) {
+                    $insert_arr['member_id'] = 'all';
+                } else {
+                    $insert_arr['member_id'] = "," . implode(',', $memberid_list) . ",";
+                }
+                $insert_arr['msg_content'] = $content;
+                $insert_arr['message_type'] = 1;
+                $insert_arr['message_ismore'] = 1;
+                $message_model->addMessage($insert_arr);
+                //跳转
+                $this->log(lang('notice_index_send'), 1);
+                dsLayerOpenSuccess(lang('notice_index_send_succ'));
+//                $this->success(lang('notice_index_send_succ'), 'notice/notice');
+            }
+        } else {
+            return View::fetch('notice_add');
+        }
+    }
+    protected function getAdminItemList()
+    {
+        $menu_array=array(
+            array(
+                'name'=>'index','text'=>lang('notice_index_member_notice'),'url'=>(string)url('Notice/index')
+            ),
+            array(
+                'name'=>'notice','text'=>lang('notice_index_send'),'url'=>"javascript:dsLayerOpen('".(string)url('Notice/notice')."','".lang('notice_index_send')."')"
+            )
+        );
+        return $menu_array;
+    }
+}

+ 183 - 0
app/admin/controller/Offpayarea.php

@@ -0,0 +1,183 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Offpayarea extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/offpayarea.lang.php');
+        
+    }
+
+    public function index()
+    {
+
+        \areacache::deleteCacheFile();
+        \areacache::updateAreaArrayJs();
+        \areacache::updateAreaPhp();
+        $offpayarea_model = model('offpayarea');
+        $area_model = model('area');
+        
+        //默认平台店铺id
+        $store_id = 1;
+        if (request()->isPost()) {
+            
+            $county_array = input('post.county');
+            if (!preg_match('/^[\d,]+$/', $county_array)) {
+                $county_array = '';
+            }
+            //内置自营店ID
+            $area_info = $offpayarea_model->getOffpayareaInfo(array('store_id' => $store_id));
+            $data = array();
+            $county = trim($county_array, ',');
+            //地区修改
+            $county_array = explode(',', $county);
+
+            $all_array = array();
+
+            $province_array = input('post.province/a');
+            if (!empty($province_array) && is_array($province_array)) {
+                foreach ($province_array as $v) {
+                    $all_array[$v] = $v;
+                }
+            }
+
+            $city_array = input('post.city/a');
+            if (!empty($city_array) && is_array($city_array)) {
+                foreach ($city_array as $v) {
+                    $all_array[$v] = $v;
+                }
+            }
+
+
+            if(is_array($county_array)) {
+                foreach ($county_array as $pid) {
+                    if($pid=='') continue;
+                    $all_array[$pid] = $pid;
+                    $temp = $area_model->getChildsByPid($pid);
+                    if (!empty($temp) && is_array($temp)) {
+                        foreach ($temp as $v) {
+                            $all_array[$v] = $v;
+                        }
+                    }
+                }
+            }
+
+            $all_array = array_values($all_array);
+            $data['area_id'] = serialize($all_array);
+            if (!$area_info) {
+                $data['store_id'] = $store_id;
+                $result = $offpayarea_model->addOffpayarea($data);
+            } else {
+                $result = $offpayarea_model->editOffpayarea(array('store_id' => $store_id), $data);
+            }
+            if ($result) {
+                $this->success(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+        //取出支持货到付款的县ID及上级市ID
+        $parea_info = $offpayarea_model->getOffpayareaInfo(array('store_id' => $store_id));
+        if (!empty($parea_info['area_id'])) {
+            $parea_ids = @unserialize($parea_info['area_id']);
+        }
+        if (empty($parea_ids)) {
+            $parea_ids = array();
+        }
+        View::assign('parea_ids',$parea_ids);
+        //取出支持货到付款县ID的上级市ID
+        $city_checked_child_array = array();
+        //地区修改
+        $county_array = $area_model->getAreaList(array('area_deep' => 3), 'area_id,area_parent_id');
+        foreach ($county_array as $v) {
+            if (in_array($v['area_id'], $parea_ids)) {
+                $city_checked_child_array[$v['area_parent_id']][] = $v['area_id'];
+            }
+        }
+        //halt($city_checked_child_array);
+        View::assign('city_checked_child_array', $city_checked_child_array);
+        //市级下面的县是不是全部支持货到付款,如果全部支持,默认选中,如果其中部分县支持货到付款,默认不选中但显示一个支付到付县的数量
+
+        //格式 city_id => 下面支持到付的县ID数量
+        $city_count_array = array();
+        //格式 city_id => 是否选中true/false
+        $city_checked_array = array();
+        $list = $area_model->getAreaList(array('area_deep' => 3), 'area_parent_id,count(area_id) as child_count', 'area_parent_id');
+        foreach ($list as $k => $v) {
+            $city_count_array[$v['area_parent_id']] = $v['child_count'];
+        }
+        foreach ($city_checked_child_array as $city_id => $city_child) {
+            if (count($city_child) > 0) {
+                if (count($city_child) == $city_count_array[$city_id]) {
+                    $city_checked_array[$city_id] = true;
+                }
+            }
+        }
+        View::assign('city_checked_array', $city_checked_array);
+
+        //取得省级地区及直属子地区(循环输出)
+        require(PUBLIC_PATH . DIRECTORY_SEPARATOR . "static" . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR .  '/area_datas.php');
+        //地区修改 修改地区从3级变成5级,以及N级引发的错误
+        $province_array = array();
+        foreach ($area_array as $k => $v) {
+            if ($v['area_parent_id'] == '0') {
+                $province_array[$k] = $k;
+            }
+        }
+
+        foreach ($area_array as $k => $v) {
+            if ($v['area_parent_id'] != '0') {
+                if (in_array($v['area_parent_id'], $province_array)) {
+                    $area_array[$v['area_parent_id']]['child'][$k] = $v['area_name'];
+                }
+                unset($area_array[$k]);
+            }
+        }
+
+        View::assign('province_array', $area_array);
+
+        //计算哪些省需要默认选中(即该省下面的所有县都支持到付,即所有市都是选中状态)
+        $province_array = $area_array;
+        foreach ($province_array as $pid => $value) {
+            if (isset($value['child']) && is_array($value['child'])) {
+                foreach ($value['child'] as $k => $v) {
+                    if (!array_key_exists($k, $city_checked_array)) {
+                        unset($province_array[$pid]);
+                        break;
+                    }
+                }
+            }
+        }
+        View::assign('province_checked_array', $province_array);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_offpayarea'),
+                'url' => (string)url('Offpayarea/index')
+            )
+        );
+        return $menu_array;
+    }
+}

+ 105 - 0
app/admin/controller/Operation.php

@@ -0,0 +1,105 @@
+<?php
+/**
+ * 营销设置
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Operation extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/config.lang.php');
+    }
+
+    public function index(){
+        $this->setAdminCurItem('index');
+        return View::fetch('index');
+    }
+
+    /**
+     * 基本设置
+     */
+    public function setting(){
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $update_array = array();
+            $update_array['flea_isuse'] = intval(input('post.flea_isuse'));
+            $update_array['promotion_allow'] = intval(input('post.promotion_allow'));
+            $update_array['groupbuy_allow'] = intval(input('post.groupbuy_allow'));
+            $update_array['points_isuse'] = intval(input('post.points_isuse'));
+            $update_array['pointshop_isuse'] = input('post.pointshop_isuse');
+            $update_array['voucher_allow'] = input('post.voucher_allow');
+            $update_array['mgdiscount_allow'] = input('post.mgdiscount_allow');
+            $update_array['pointprod_isuse'] = input('post.pointprod_isuse');
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('ds_operation') . lang('ds_operation_set'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('setting');
+            return View::fetch('setting');
+        }
+
+    }
+
+    public function point_signin(){
+        $config_model = model('config');
+        if(!request()->isPost()){
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            return View::fetch('point_signin');
+        }else{
+            $update_array = array();
+            $update_array['points_signin_isuse'] = input('post.points_signin_isuse');
+            $update_array['points_signin'] = intval(input('post.points_signin'));
+            $update_array['points_signin_cycle'] = intval(input('post.points_signin_cycle'));
+            $update_array['points_signin_reward'] = intval(input('post.points_signin_reward'));
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+    
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_operation_set'),
+                'url' => (string)url('Operation/index')
+            ),
+            array(
+                'name' => 'setting',
+                'text' => lang('base_setting'),
+                'url' => (string)url('Operation/setting')
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 370 - 0
app/admin/controller/Order.php

@@ -0,0 +1,370 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Order extends AdminControl {
+
+    const EXPORT_SIZE = 1000;
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/vrorder.lang.php');
+    }
+
+    public function index() {
+        $order_model = model('order');
+        $condition = array();
+
+        $order_sn = input('param.order_sn');
+        if ($order_sn) {
+            $condition[] = array('order_sn','=',$order_sn);
+        }
+        $store_name = input('param.store_name');
+        if ($store_name) {
+            $condition[] = array('store_name','=',$store_name);
+        }
+        $order_state = input('param.order_state');
+        if (in_array($order_state, array('0', '10', '20', '30', '40'))) {
+            $condition[] = array('order_state','=',$order_state);
+        }
+        $payment_code = input('param.payment_code');
+        if ($payment_code) {
+            $condition[] = array('payment_code','=',$payment_code);
+        }
+        $buyer_name = input('param.buyer_name');
+        if ($buyer_name) {
+            $condition[] = array('buyer_name','=',$buyer_name);
+        }
+        $query_start_time = input('param.query_start_time');
+        $query_end_time = input('param.query_end_time');
+        $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
+        $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
+        $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
+        $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
+        if ($start_unixtime) {
+            $condition[] = array('add_time','>=',$start_unixtime);
+        }
+        if ($end_unixtime) {
+            $condition[] = array('add_time','<=',$end_unixtime);
+        }
+        $order_list = $order_model->getOrderList($condition, 10);
+        View::assign('show_page', $order_model->page_info->render());
+        $order_group_list=array();
+        foreach ($order_list as $order_id => $order_info) {
+            //显示取消订单
+            $order_list[$order_id]['if_cancel'] = $order_model->getOrderOperateState('system_cancel', $order_info);
+            //显示收到货款
+            $order_list[$order_id]['if_system_receive_pay'] = $order_model->getOrderOperateState('system_receive_pay', $order_info);
+            $order_group_list[$order_info['pay_sn']]['order_list'][]=$order_list[$order_id];
+            //如果有在线支付且未付款的订单则显示合并付款链接
+            if (!isset($order_group_list[$order_info['pay_sn']]['pay_amount'])) {
+                $order_group_list[$order_info['pay_sn']]['pay_amount'] = 0;
+            }
+            if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT || $order_info['order_state'] == ORDER_STATE_REST) {
+                $order_group_list[$order_info['pay_sn']]['pay_amount'] += ($order_info['order_state'] == ORDER_STATE_DEPOSIT?$order_info['presell_deposit_amount']:($order_info['order_amount']-$order_info['presell_deposit_amount'] + $order_info['presell_pd_amount'] + $order_info['presell_rcb_amount'])) - $order_info['pd_amount'] - $order_info['rcb_amount'];
+            }
+        }
+        //显示支付接口列表(搜索)
+        $payment_list = model('payment')->getPaymentOpenList();
+        View::assign('payment_list', $payment_list);
+        View::assign('order_group_list', $order_group_list);
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('add');
+        return View::fetch('index');
+    }
+
+    /**
+     * 平台订单状态操作
+     *
+     */
+    public function change_state() {
+        $state_type = input('param.state_type');
+        if ($state_type == 'cancel') {
+        $order_id = intval(input('param.order_id'));
+        if ($order_id <= 0) {
+            $this->error(lang('miss_order_number'));
+        }
+        $order_model = model('order');
+
+        //获取订单详细
+        $condition = array();
+        $condition[] = array('order_id','=',$order_id);
+        $order_info = $order_model->getOrderInfo($condition);
+
+        
+        
+            $result = $this->_order_cancel($order_info);
+            if (!$result['code']) {
+                $this->error($result['msg']);
+            } else {
+                ds_json_encode(10000, $result['msg']);
+            }
+        } elseif ($state_type == 'receive_pay') {
+            $result = $this->_order_receive_pay(input('param.'));
+            if (!$result['code']) {
+                $this->error($result['msg']);
+            } else {
+                dsLayerOpenSuccess($result['msg'],'Order/index');
+            }
+        }
+    }
+
+    /**
+     * 系统取消订单
+     */
+    private function _order_cancel($order_info) {
+        $order_id = $order_info['order_id'];
+        $order_model = model('order');
+        $logic_order = model('order','logic');
+        $if_allow = $order_model->getOrderOperateState('system_cancel', $order_info);
+        if (!$if_allow) {
+            return ds_callback(false, lang('no_right_operate'));
+        }
+        try{
+            Db::startTrans();
+            $logic_order->changeOrderStateCancel($order_info, 'system', $this->admin_info['admin_name']);
+        } catch (\Exception $e) {
+            Db::rollback();
+            return ds_callback(false, $e->getMessage());
+        }
+        Db::commit();
+        $this->log(lang('order_log_cancel') . ',' . lang('ds_order_sn') . ':' . $order_info['order_sn'], 1);
+        return ds_callback(true, lang('ds_common_op_succ'));
+    }
+
+    /**
+     * 系统收到货款
+     * @throws Exception
+     */
+    private function _order_receive_pay($post) {
+        $order_model = model('order');
+        $logic_order = model('order','logic');
+        $pay_sn=$post['pay_sn'];
+        $pay_info = $order_model->getOrderpayInfo(array('pay_sn' => $pay_sn));
+        if (empty($pay_info)) {
+            return ds_callback(false, lang('no_right_operate'));
+        }
+        
+        //取子订单列表
+        $condition = array();
+        $condition[] = array('pay_sn','=',$pay_sn);
+        $condition[]=array('order_state','in', array_values(array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_DEPOSIT, ORDER_STATE_REST)));
+        $order_list = $order_model->getOrderList($condition, 0, 'order_id,order_state,payment_code,order_amount,rcb_amount,pd_amount,order_sn,presell_deposit_amount,presell_rcb_amount,presell_pd_amount');
+        if (empty($order_list)) {
+            return ds_callback(false, lang('no_right_operate'));
+        }
+        //重新计算在线支付金额
+        $pay_amount_online = 0;
+        //订单总支付金额(不包含货到付款)
+        $pay_amount = 0;
+        $order_sn_list = array();
+        foreach($order_list as $order_info){
+            $if_allow = $order_model->getOrderOperateState('system_receive_pay', $order_info);
+            if (!$if_allow) {
+                return ds_callback(false, lang('no_right_operate'));
+            }
+            $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
+            //计算相关支付金额
+            if ($order_info['payment_code'] != 'offline') {
+                if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_REST) {
+                    $pay_amount_online += ds_price_format(floatval($order_info['order_amount']) - floatval($order_info['presell_deposit_amount']) + floatval($order_info['presell_rcb_amount']) + floatval($order_info['presell_pd_amount']) - $payed_amount);
+                }else if($order_info['order_state'] == ORDER_STATE_DEPOSIT){
+                    $pay_amount_online += ds_price_format(floatval($order_info['presell_deposit_amount']) - $payed_amount);
+                }
+                $pay_amount += floatval($order_info['order_amount']);
+            }
+            $order_sn_list[]=$order_info['order_sn'];
+        }
+
+
+        if (!request()->isPost()) {
+            View::assign('order_sn_list', implode('`', $order_sn_list));
+            View::assign('pay_amount_online', ds_price_format($pay_amount_online));
+            View::assign('pay_amount', ds_price_format($pay_amount));
+            //显示支付接口列表
+            $payment_list = model('payment')->getPaymentOpenList();
+            //去掉预存款和货到付款
+            foreach ($payment_list as $key => $value) {
+                if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
+                    unset($payment_list[$key]);
+                }
+            }
+            View::assign('payment_list', $payment_list);
+            echo View::fetch('receive_pay');
+            exit;
+        } else {
+            $order_list = $order_model->getOrderList(array(array('pay_sn' ,'=', $pay_sn), array('order_state' ,'in', [ORDER_STATE_NEW,ORDER_STATE_DEPOSIT,ORDER_STATE_REST])));
+            try{
+                Db::startTrans();
+                $logic_order->changeOrderReceivePay($order_list, 'system', $this->admin_info['admin_name'], $post);
+            } catch (\Exception $e) {
+                Db::rollback();
+                return ds_callback(false, $e->getMessage());
+            }
+            Db::commit();    
+            $this->log('将订单改为已收款状态,' . lang('ds_order_sn') . ':' . implode('`', $order_sn_list), 1);
+            return ds_callback(true, lang('ds_common_op_succ'));
+
+        }
+    }
+
+    /**
+     * 查看订单
+     *
+     */
+    public function show_order() {
+        $order_id = intval(input('param.order_id'));
+        if ($order_id <= 0) {
+            $this->error(lang('miss_order_number'));
+        }
+        $order_model = model('order');
+        $order_info = $order_model->getOrderInfo(array('order_id' => $order_id), array('order_goods', 'order_common', 'store'));
+
+        //订单变更日志
+        $log_list = $order_model->getOrderlogList(array('order_id' => $order_info['order_id']));
+        View::assign('order_log', $log_list);
+
+        //退款退货信息
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[]=array('order_id','=',$order_info['order_id']);
+        $condition[]=array('seller_state','=',2);
+        $condition[]=array('admin_time','>', 0);
+        $return_list = $refundreturn_model->getReturnList($condition);
+        View::assign('return_list', $return_list);
+
+        //退款信息
+        $refund_list = $refundreturn_model->getRefundList(array_merge($condition,array(array('refund_type','=',1))));
+        View::assign('refund_list', $refund_list);
+
+        //卖家发货信息
+        if (!empty($order_info['extend_order_common']['daddress_id'])) {
+            $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
+            View::assign('daddress_info', $daddress_info);
+        }
+        View::assign('order_info', $order_info);
+        return View::fetch('show_order');
+    }
+
+    /**
+     * 导出
+     *
+     */
+    public function export_step1() {
+
+        $order_model = model('order');
+        $condition = array();
+        $order_sn = input('param.order_sn');
+        if ($order_sn) {
+            $condition[] = array('order_sn','=',$order_sn);
+        }
+        $store_name = input('param.store_name');
+        if ($store_name) {
+            $condition[] = array('store_name','=',$store_name);
+        }
+        $order_state = input('param.order_state');
+        if (in_array($order_state, array('0', '10', '20', '30', '40'))) {
+            $condition[] = array('order_state','=',$order_state);
+        }
+        $payment_code = input('param.payment_code');
+        if ($payment_code) {
+            $condition[] = array('payment_code','=',$payment_code);
+        }
+        $buyer_name = input('param.buyer_name');
+        if ($buyer_name) {
+            $condition[] = array('buyer_name','=',$buyer_name);
+        }
+        $query_start_time = input('param.query_start_time');
+        $query_end_time = input('param.query_end_time');
+        $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
+        $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
+        $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
+        $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
+        if ($start_unixtime || $end_unixtime) {
+            $condition[] = array('add_time','between',array($start_unixtime, $end_unixtime));
+        }
+
+        if (!is_numeric(input('param.page'))) {
+            $count = $order_model->getOrderCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $order_model->getOrderList($condition, 0, '*', 'order_id desc', self::EXPORT_SIZE);
+                $this->createExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $order_model->getOrderList($condition, $limit2, '*', 'order_id desc');
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_no'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_store'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_buyer'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_xtimd'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_count'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_yfei'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_paytype'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_state'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_storeid'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_buyerid'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_bemail'));
+        //data
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => 'DS' . $v['order_sn']);
+            $tmp[] = array('data' => $v['store_name']);
+            $tmp[] = array('data' => $v['buyer_name']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['order_amount']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['shipping_fee']));
+            $tmp[] = array('data' => get_order_payment_name($v['payment_code']));
+            $tmp[] = array('data' => get_order_state($v));
+            $tmp[] = array('data' => $v['store_id']);
+            $tmp[] = array('data' => $v['buyer_id']);
+            $tmp[] = array('data' => $v['buyer_email']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_od_order'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_od_order'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+}

+ 555 - 0
app/admin/controller/Ownshop.php

@@ -0,0 +1,555 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Ownshop extends AdminControl {
+    
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/ownshop.lang.php');
+    }
+
+    public function index() {
+        $condition = array();
+        $condition[]=array('is_platform_store' ,'=', 1);
+        
+        $store_name = trim(input('get.store_name'));
+        if (strlen($store_name) > 0) {
+            $condition[]=array('store_name','like', "%$store_name%");
+            View::assign('store_name', $store_name);
+        }
+        $ownshop_model = model('store');
+        $storeList = $ownshop_model->getStoreList($condition,10);
+        View::assign('store_list', $storeList);
+        View::assign('show_page', $ownshop_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch('ownshop_list');
+    }
+
+    public function add() {
+        if (!request()->isPost()) {
+            return View::fetch('ownshop_add');
+        } else {
+
+            $member_name = input('post.member_name');
+            $member_password = input('post.member_password');
+            $store_name = input('post.store_name');
+
+            if (strlen($member_name) < 3 || strlen($member_name) > 15)
+                $this->error(lang('account_length_error'));
+
+            if (strlen($member_password) < 6)
+                $this->error(lang('password_length_error'));
+
+            if (!$this->checkMemberName($member_name))
+                $this->error(lang('member_name_remote'));
+
+
+            try {
+                $memberId = model('member')->addMember(array(
+                    'member_name' => $member_name,
+                    'member_password' => $member_password,
+                ));
+            } catch (Exception $ex) {
+                $this->error(lang('account_add_fail'));
+            }
+
+            $store_model = model('store');
+
+            $saveArray = array();
+            $saveArray['store_name'] = $store_name;
+            $saveArray['member_id'] = $memberId;
+            $saveArray['member_name'] = $member_name;
+            $saveArray['seller_name'] = $member_name;
+            $saveArray['bind_all_gc'] = 1;
+            $saveArray['store_state'] = 1;
+            $saveArray['store_addtime'] = TIMESTAMP;
+            $saveArray['is_platform_store'] = 1;
+
+            $store_id = $store_model->addStore($saveArray);
+
+            model('seller')->addSeller(array(
+                'seller_name' => $member_name,
+                'member_id' => $memberId,
+                'store_id' => $store_id,
+                'sellergroup_id' => 0,
+                'is_admin' => 1,
+            ));
+            model('storejoinin')->addStorejoinin(array(
+                'seller_name' => $member_name,
+                'store_name' => $store_name,
+                'member_name' => $member_name,
+                'member_id' => $memberId,
+                'joinin_state' => 40,
+                'company_province_id' => 0,
+                'storeclass_bail' => 0,
+                'joinin_year' => 1,
+            ));
+
+            // 添加相册默认
+            $album_model = model('album');
+            $album_arr = array();
+            $album_arr['aclass_name'] = lang('default_album');
+            $album_arr['store_id'] = $store_id;
+            $album_arr['aclass_des'] = '';
+            $album_arr['aclass_sort'] = '255';
+            $album_arr['aclass_cover'] = '';
+            $album_arr['aclass_uploadtime'] = TIMESTAMP;
+            $album_arr['aclass_isdefault'] = '1';
+            $album_model->addAlbumclass($album_arr);
+
+            //插入店铺扩展表
+            $store_model->addStoreextend(array('store_id' => $store_id));
+
+            // 删除自营店id缓存
+            model('store')->dropCachedOwnShopIds();
+
+            $this->log(lang('add_ownshop').": {$saveArray['store_name']}");
+            dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Ownshop/index'));
+        }
+    }
+
+    /*
+    // 删除自营店铺
+    public function del() {
+        $store_id = intval(input('param.id'));
+        $store_model = model('store');
+        $storeArray = $store_model->getOneStore(array('store_id'=>$store_id),'is_platform_store,store_name');
+        if (empty($storeArray)) {
+            $this->error('自营店铺不存在');
+        }
+        if (!$storeArray['is_platform_store']) {
+            $this->error('不能在此删除非自营店铺');
+        }
+        $condition = array(
+            'store_id' => $store_id,
+        );
+        if (model('goods')->getGoodsCount($condition) > 0)
+            $this->error('已经发布商品的自营店铺不能被删除');
+
+        // 完全删除店铺
+        $store_model->delStoreEntirely($condition);
+        // 删除自营店id缓存
+        model('store')->dropCachedOwnShopIds();
+        $this->log("删除自营店铺: {$storeArray['store_name']}");
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+     */
+
+    public function edit() {
+        $store_model = model('store');
+        $store_id = intval(input('param.id'));
+        $storeArray = $store_model->getStoreInfoByID($store_id);
+
+        if (!$storeArray['is_platform_store']) {
+            $this->error(lang('cannot_manage_no_ownshop'));
+        }
+
+        if (!request()->isPost()) {
+            if (empty($storeArray))
+                $this->error(lang('store_not_exist'));
+            View::assign('store_array', $storeArray);
+            //店铺分类
+            $storeclass_model = model('storeclass');
+            $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
+
+            View::assign('class_list', $parent_list);
+            return View::fetch('ownshop_edit');
+        }else {
+
+            $saveArray = array();
+            $saveArray['storeclass_id'] = intval(input('post.storeclass_id'));
+            $saveArray['store_name'] = input('post.store_name');
+            $saveArray['bind_all_gc'] = input('post.bind_all_gc') ? 1 : 0;
+            $saveArray['store_state'] = input('post.store_state') ? 1 : 0;
+            $saveArray['store_close_info'] = input('post.store_close_info');
+
+            $goods_model = model('goods');
+            $condition = array();
+            $condition[] = array('store_id','=',$store_id);
+            $goods_model->editProducesOffline($condition);
+            $store_model->editStore($saveArray, $condition);
+            if($storeArray['store_name']!=$saveArray['store_name']){
+                $goods_model = model('goods');
+                $goods_model->editGoodsCommon(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
+                $goods_model->editGoods(array('store_name'=>$saveArray['store_name']), array('store_id'=>$store_id));
+            }
+            // 删除自营店id缓存
+            model('store')->dropCachedOwnShopIds();
+
+            $this->log(lang('edit_ownshop').": {$saveArray['store_name']}");
+            dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Ownshop/index'));
+        }
+    }
+
+    /**
+     * 编辑保存注册信息
+     */
+    public function storejoinin_edit() {
+        if (request()->isPost()) {
+            $member_id = input('post.member_id');
+            if ($member_id <= 0) {
+                $this->error(lang('param_error'));
+            }
+            $param = array();
+            $param['company_name'] = input('post.company_name');
+            $param['company_province_id'] = intval(input('post.province_id'));
+            $param['company_address'] = input('post.company_address');
+            $param['company_address_detail'] = input('post.company_address_detail');
+            $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
+            $param['contacts_name'] = input('post.contacts_name');
+            $param['contacts_phone'] = input('post.contacts_phone');
+            $param['contacts_email'] = input('post.contacts_email');
+            $param['business_licence_number'] = input('post.business_licence_number');
+            $param['business_licence_address'] = input('post.business_licence_address');
+            $param['business_licence_start'] = input('post.business_licence_start');
+            $param['business_licence_end'] = input('post.business_licence_end');
+            $param['business_sphere'] = input('post.business_sphere');
+            if (!empty($_FILES['business_licence_number_electronic']['name'])) {
+                $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
+            }
+
+
+            $param['bank_account_name'] = input('post.bank_account_name');
+            $param['bank_account_number'] = input('post.bank_account_number');
+            $param['bank_name'] = input('post.bank_name');
+            $param['bank_address'] = input('post.bank_address');
+
+            $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
+            $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
+            $param['settlement_bank_name'] = input('post.settlement_bank_name');
+            $param['settlement_bank_address'] = input('post.settlement_bank_address');
+
+            $result = model('storejoinin')->editStorejoinin($param, array('member_id' => $member_id));
+            if ($result >= 0) {
+                //更新店铺信息
+                $store_update = array();
+                $store_update['store_company_name'] = $param['company_name'];
+                $store_update['area_info'] = $param['company_address'];
+                $store_update['store_address'] = $param['company_address_detail'];
+                $store_model = model('store');
+                $store_info = $store_model->getStoreInfo(array('member_id' => $member_id));
+                if (!empty($store_info)) {
+                    $r = $store_model->editStore($store_update, array('member_id' => $member_id));
+                    $this->log('编辑店铺信息' . '[ID:' . $r . ']', 1);
+                }
+                $this->success(lang('ds_common_op_succ'), (string) url('Ownshop/index'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }else{
+            $store_model = model('store');
+            $store_id = intval(input('param.id'));
+            $storeArray = $store_model->getStoreInfoByID($store_id);
+            $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $storeArray['member_id']));
+            View::assign('joinin_detail', $joinin_detail);
+            $this->setAdminCurItem('store_edit');
+            return View::fetch('storejoinin_edit');
+        }
+    }
+    public function check_seller_name() {
+        $seller_name = input('get.seller_name');
+        echo json_encode($this->checkSellerName($seller_name));
+        exit;
+    }
+
+    private function checkSellerName($sellerName) {
+        // 判断store_joinin是否存在记录
+        $count = (int) model('storejoinin')->getStorejoininCount(array(
+                    'seller_name' => $sellerName,
+        ));
+        if ($count > 0) {
+            return FALSE;
+        }
+        $seller = model('seller')->getSellerInfo(array(
+            'seller_name' => $sellerName,
+        ));
+        if (!empty($seller)) {
+            return FALSE;
+        }
+        return TRUE;
+    }
+
+    public function check_member_name() {
+        $member_name = input('get.member_name');
+        echo json_encode($this->checkMemberName($member_name));
+        exit;
+    }
+
+    private function checkMemberName($member_name) {
+        // 判断store_joinin是否存在记录
+        $count = (int) model('storejoinin')->getStorejoininCount(array(
+                    'member_name' => $member_name,
+        ));
+        if ($count > 0)
+            return false;
+
+        return !model('member')->getMemberCount(array(
+                    'member_name' => $member_name,
+        ));
+    }
+
+    public function bind_class() {
+        $store_id = intval(input('param.id'));
+
+        $store_model = model('store');
+        $storebindclass_model = model('storebindclass');
+        $goodsclass_model = model('goodsclass');
+
+        $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
+        View::assign('gc_list', $gc_list);
+
+        $store_info = $store_model->getStoreInfoByID($store_id);
+        if (empty($store_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('store_info', $store_info);
+
+        $store_bind_class_list = $storebindclass_model->getStorebindclassList(array('store_id' => $store_id), 30);
+
+        $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
+
+        for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
+            $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
+            $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
+            $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
+        }
+        View::assign('store_bind_class_list', $store_bind_class_list);
+        View::assign('showpage', $storebindclass_model->page_info->render());
+        $this->setAdminCurItem('bind_class');
+        return View::fetch('ownshop_bind_class');
+    }
+
+    /**
+     * 添加经营类目
+     */
+    public function bind_class_add() {
+        $store_id = intval(input('post.store_id'));
+        $commis_rate = intval(input('post.commis_rate'));
+        if ($commis_rate < 0 || $commis_rate > 100) {
+            $this->error(lang('param_error'));
+        }
+        @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
+        $storebindclass_model = model('storebindclass');
+        $goodsclass_model = model('goodsclass');
+
+        $param = array();
+        $param['store_id'] = $store_id;
+        $param['class_1'] = $class_1;
+        $param['storebindclass_state'] = 2;
+        $param['commis_rate'] = $commis_rate;
+
+        if (empty($class_2)) {
+            //如果没选 二级
+            $class_2_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_1));
+            if (!empty($class_2_list)) {
+                foreach ($class_2_list as $class_2_info) {
+                    $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2_info['gc_id']));
+                    if (!empty($class_3_list)) {
+                        $param['class_2'] = $class_2_info['gc_id'];
+                        foreach ($class_3_list as $class_3_info) {
+                            $param['class_3'] = $class_3_info['gc_id'];
+                            $result = $this->_add_bind_class($param);
+                        }
+                    }
+                }
+            } else {
+                //只有一级分类
+                $param['class_2'] = $param['class_3'] = 0;
+                $result = $this->_add_bind_class($param);
+            }
+        } else if (empty($class_3)) {
+            //如果没选二没选三级
+            $param['class_2'] = $class_2;
+            $class_3_list = $goodsclass_model->getGoodsclassList(array('gc_parent_id' => $class_2));
+            if (!empty($class_3_list)) {
+                foreach ($class_3_list as $class_3_info) {
+                    $param['class_3'] = $class_3_info['gc_id'];
+                    // 检查类目是否已经存在
+                    $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
+                    if (empty($store_bind_class_info)) {
+                        $result = $this->_add_bind_class($param);
+                    }
+                }
+            } else {
+                //二级就是最后一级
+                $param['class_3'] = 0;
+                $result = $this->_add_bind_class($param);
+            }
+        } else {
+            $param['class_2'] = $class_2;
+            $param['class_3'] = $class_3;
+            $result = $this->_add_bind_class($param);
+        }
+
+        if ($result) {
+            // 删除自营店id缓存
+            model('store')->dropCachedOwnShopIds();
+
+            $this->log('增加自营店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
+            $this->success(lang('ds_common_save_succ'));
+        } else {
+            $this->error(lang('ds_common_save_fail'));
+        }
+    }
+
+    private function _add_bind_class($param) {
+        $storebindclass_model = model('storebindclass');
+        // 检查类目是否已经存在
+        $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
+        if (!empty($store_bind_class_info))
+            return true;
+        return $storebindclass_model->addStorebindclass($param);
+    }
+
+    /**
+     * 删除经营类目
+     */
+    public function bind_class_del() {
+        $bid = input('param.bid');
+        $bid_array = ds_delete_param($bid);
+        if ($bid_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $storebindclass_model = model('storebindclass');
+        
+        foreach ($bid_array as $key => $bid) {
+            $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
+            if (empty($store_bind_class_info)) {
+                ds_json_encode('10001', lang('store_bind_class_drop_fail'));
+            }
+
+            /* 自营店不下架商品
+              $goods_model = model('goods');
+              // 商品下架
+              $condition = array();
+              $condition[] = array('store_id','=',$store_bind_class_info['store_id']);
+              $gc_id = $store_bind_class_info['class_1'].','.$store_bind_class_info['class_2'].','.$store_bind_class_info['class_3'];
+              $update = array();
+              $update['goods_stateremark'] = '管理员删除经营类目';
+              $condition[]=array('gc_id','in', rtrim($gc_id, ','));
+              $goods_model->editProducesLockUp($update, $condition);
+             */
+
+            $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
+
+            if (!$result) {
+                ds_json_encode('10001', lang('store_bind_class_drop_fail'));
+            }
+            // 删除自营店id缓存
+            model('store')->dropCachedOwnShopIds();
+            $this->log('删除自营店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
+        }
+        ds_json_encode('10000', lang('ds_common_del_succ'));
+        
+    }
+
+
+    public function bind_class_update() {
+        $bid = intval(input('param.id'));
+        if ($bid <= 0) {
+            echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
+            die;
+        }
+        $new_commis_rate = intval(input('get.value'));
+        if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
+            echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
+            die;
+        } else {
+            $update = array('commis_rate' => $new_commis_rate);
+            $condition = array('storebindclass_id' => $bid);
+            $storebindclass_model = model('storebindclass');
+            $result = $storebindclass_model->editStorebindclass($update, $condition);
+            if ($result) {
+                // 删除自营店id缓存
+                model('store')->dropCachedOwnShopIds();
+
+                $this->log('更新自营店铺经营类目,类目编号:' . $bid);
+                echo json_encode(array('result' => TRUE));
+                die;
+            } else {
+                echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
+                die;
+            }
+        }
+    }
+
+    /**
+     * 验证店铺名称是否存在
+     */
+    public function ckeck_store_name() {
+        $store_name = trim(input('get.store_name'));
+        if (empty($store_name)) {
+            echo 'false';
+            exit;
+        }
+        $where = array();
+        $where[]=array('store_name','=',$store_name);
+        $store_id = input('get.store_id');
+        if (isset($store_id)) {
+            $where[]=array('store_id','<>', $store_id);
+        }
+        $store_info = model('store')->getStoreInfo($where);
+        if (!empty($store_info['store_name'])) {
+            echo 'false';
+        } else {
+            echo 'true';
+        }
+    }
+    //ajax操作
+    public function ajax() {
+        $store_model = model('store');
+        switch (input('param.branch')) {
+            /**
+             * 品牌名称
+             */
+            case 'store_sort':
+                $id = intval(input('param.id'));
+                $result = $store_model->editStore(array('store_sort'=>trim(input('param.value'))), array('store_id' => $id));
+                if($result){
+                    $this->log(lang('ds_edit').'自营店铺' . '[' . $id . ']', 1);
+                }
+                echo 'true';
+                exit;
+                break;
+        }
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Ownshop/index')
+            ), array(
+                'name' => 'add',
+                'text' => lang('ds_new'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Ownshop/add')."','".lang('ds_new')."')"
+            )
+        );
+        if (request()->action() == 'bind_class') {
+            $menu_array[] = array(
+                'name' => 'bind_class',
+                'text' => lang('bind_class'),
+                'url' => (string)url('Ownshop/bind_class')
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 223 - 0
app/admin/controller/Payment.php

@@ -0,0 +1,223 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Payment extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/payment.lang.php');
+    }
+
+    /**
+     * 支付方式
+     */
+    public function index() {
+        $payment_model = model('payment');
+        //获取数据库中已安装的支付方式
+        $install_payment_list = $payment_model->getPaymentList(array(array('payment_code', '<>', 'predeposit')));
+        $install_payment_list = ds_change_arraykey($install_payment_list, 'payment_code');
+        //获取已存在的支付列表文件
+        $file_payment_list = $payment_model->get_builtin();
+
+        $payment_platform = input('param.payment_platform');
+        if (!in_array($payment_platform, array('pc', 'h5', 'app'))) {
+            $payment_platform = 'pc';
+        }
+
+        foreach ($file_payment_list as $key => $value) {
+            if ($value['payment_platform'] != $payment_platform) {
+                unset($file_payment_list[$key]);
+                continue;
+            }
+            if (array_key_exists($key, $install_payment_list)) {
+                $file_payment_list[$key]['install'] = 1;
+                //已安装的支付,配置信息使用数据库中配置信息
+                $file_payment_list[$key]['payment_config'] = $install_payment_list[$key]['payment_config'];
+                $file_payment_list[$key]['payment_state'] = $install_payment_list[$key]['payment_state'];
+            } else {
+                $file_payment_list[$key]['install'] = 0;
+                $file_payment_list[$key]['payment_state'] = 0;
+            }
+        }
+
+        View::assign('payment_list', $file_payment_list);
+        $this->setAdminCurItem('index_' . $payment_platform);
+        return View::fetch();
+    }
+
+    /**
+     * 安装支付方式
+     */
+    function install() {
+        $payment_code = input('param.payment_code');
+        $payment_mod = model('payment');
+        //如果是小程序支付、微信JS支付、微信H5支付、微信APP支付则必须先开启微信扫码支付
+        if (in_array($payment_code, array('wxpay_minipro', 'wxpay_jsapi', 'wxpay_h5', 'wxpay_app'))) {
+            $payment = model('payment')->getPaymentInfo(array('payment_code' => 'wxpay_native'));
+            if (empty($payment) || empty(unserialize($payment['payment_config']))) {
+                ds_json_encode('10001', lang('please_open_wechat_payment'));
+            }
+        }
+        //如果是支付宝H5支付则开启支付宝支付
+        if (in_array($payment_code, array('alipay_h5'))) {
+            $payment = model('payment')->getPaymentInfo(array('payment_code' => 'alipay'));
+            if (empty($payment) || empty(unserialize($payment['payment_config']))) {
+                ds_json_encode('10001', lang('please_open_alipay_payment'));
+            }
+        }
+
+
+        $payment = model('payment')->getPaymentInfo(array('payment_code' => $payment_code));
+        if (empty($payment)) {
+            $file_payment = include_once(PLUGINS_PATH . '/payments/' . $payment_code . '/payment.info.php');
+            $data['payment_code'] = $file_payment['payment_code'];
+            $data['payment_name'] = $file_payment['payment_name'];
+            $data['payment_state'] = 1;
+            $data['payment_platform'] = $file_payment['payment_platform'];
+            $data['payment_config'] = serialize(array());
+            $resutlt = $payment_mod->addPayment($data);
+            if ($resutlt) {
+                ds_json_encode('10000', lang('ds_common_op_succ'));
+            } else {
+                ds_json_encode('10001', lang('ds_common_op_fail'));
+            }
+        } else {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 编辑
+     */
+    public function edit() {
+        $payment_model = model('payment');
+        $payment_code = trim(input('param.payment_code'));
+        $install_payment = $payment_model->getPaymentInfo(array('payment_code' => $payment_code));
+        $file_payment = include_once(PLUGINS_PATH . '/payments/' . $install_payment['payment_code'] . '/payment.info.php');
+
+        if (is_array($file_payment['payment_config'])) {
+            $install_payment_config = unserialize($install_payment['payment_config']);
+            unset($install_payment['payment_config']);
+            foreach ($file_payment['payment_config'] as $key => $value) {
+                $install_payment['payment_config'][$key]['name'] = $value['name'];
+                $install_payment['payment_config'][$key]['type'] = $value['type'];
+                $install_payment['payment_config'][$key]['desc'] = lang($value['name'] . '_desc');
+                $install_payment['payment_config'][$key]['lable'] = lang($value['name']);
+                $install_payment['payment_config'][$key]['value'] = isset($install_payment_config[$value['name']]) ? $install_payment_config[$value['name']] : $value['value'];
+            }
+        }
+        if (!(request()->isPost())) {
+
+            View::assign('payment', $install_payment);
+            return View::fetch();
+        } else {
+            $data = array();
+            $data['payment_state'] = intval(input('post.payment_state'));
+            $config_info = array();
+
+            $cfg_value_array = input('post.cfg_value/a'); #获取数组
+            $cfg_name_array = input('post.cfg_name/a'); #获取数组
+            if (is_array($cfg_value_array) && !empty($cfg_value_array)) {
+                foreach ($cfg_value_array as $i => $v) {
+                    $config_info[trim($cfg_name_array[$i])] = trim($cfg_value_array[$i]);
+                }
+            }
+
+            $cfg_name2_array = input('post.cfg_name2/a'); #获取数组
+            if (is_array($cfg_name2_array)) {
+                foreach ($cfg_name2_array as $i => $v) {
+                    $cfg_value2 = isset($install_payment_config[trim($cfg_name2_array[$i])]) ? $install_payment_config[trim($cfg_name2_array[$i])] : '';
+                    $file = array();
+                    foreach ($_FILES['cfg_value2_' . $i] as $key => $value) {
+                        $file[$key] = $value;
+                    }
+                    if (!empty($file['name'])) {
+                        $upload_file = PLUGINS_PATH . '/payments/' . $install_payment['payment_code'] . '/asserts';
+                        $file = request()->file('cfg_value2_' . $i);
+
+
+                        $file_config = array(
+                            'disks' => array(
+                                'local' => array(
+                                    'root' => $upload_file
+                                )
+                            )
+                        );
+                        config($file_config, 'filesystem');
+                        try {
+                            validate(['image' => 'fileSize:' . ALLOW_IMG_SIZE . '|fileExt:pfx'])
+                                    ->check(['image' => $file]);
+                            $file_name = \think\facade\Filesystem::putFile('', $file);
+                            $cfg_value2 = $file_name;
+                        } catch (\Exception $e) {
+                            $this->error($e->getMessage());
+                        }
+                    }
+                    $config_info[trim($cfg_name2_array[$i])] = $cfg_value2;
+                }
+            }
+            $data['payment_config'] = serialize($config_info);
+            $payment_model->editPayment($data, array('payment_code' => $payment_code));
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }
+    }
+
+    /**
+     * 删除支付方式,卸载
+     */
+    public function del() {
+        $payment_model = model('payment');
+        $payment_code = trim(input('param.payment_code'));
+        $condition = array();
+        $condition[] = array('payment_code', '=', $payment_code);
+        $result = $payment_model->delPayment($condition);
+        if ($result) {
+            ds_json_encode('10000', lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index_pc',
+                'text' => lang('payment_index_pc'),
+                'url' => (string) url('Payment/index')
+            ),
+            array(
+                'name' => 'index_h5',
+                'text' => lang('payment_index_h5'),
+                'url' => (string) url('Payment/index', ['payment_platform' => 'h5'])
+            ),
+            array(
+                'name' => 'index_app',
+                'text' => lang('payment_index_app'),
+                'url' => (string) url('Payment/index', ['payment_platform' => 'app'])
+            ),
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 176 - 0
app/admin/controller/Pointorder.php

@@ -0,0 +1,176 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Pointorder extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/pointorder.lang.php');
+    }
+
+    /**
+     * 积分兑换列表
+     */
+    public function pointorder_list() {
+        $pointorder_model = model('pointorder');
+        //获取兑换订单状态
+        $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
+        $where = array();
+        //兑换单号
+        $pordersn = trim(input('param.pordersn'));
+        if ($pordersn) {
+            $where[]=array('point_ordersn','like', "%{$pordersn}%");
+        }
+        //兑换会员名称
+        $pbuyname = trim(input('param.pbuyname'));
+        if (trim(input('param.pbuyname'))) {
+            $where[]=array('point_buyername','like', "%{$pbuyname}%");
+        }
+        //订单状态
+        if (trim(input('param.porderstate'))) {
+            $where[]=array('point_orderstate','=',$pointorderstate_arr[input('param.porderstate')][0]);
+        }
+        //查询兑换订单列表
+        $order_list = $pointorder_model->getPointorderList($where, '*', 10, 0, 'point_orderid desc');
+
+        //信息输出
+        View::assign('pointorderstate_arr', $pointorderstate_arr);
+        View::assign('order_list', $order_list);
+        View::assign('show_page', $pointorder_model->page_info->render());
+        $this->setAdminCurItem('pointorder_list');
+        return View::fetch();
+    }
+
+    /**
+     * 删除兑换订单信息
+     */
+    public function order_drop() {
+        $data = model('pointorder')->delPointorderByOrderID(input('param.order_id'));
+        if ($data['state']) {
+            ds_json_encode(10000, lang('admin_pointorder_del_success'));
+        } else {
+            ds_json_encode(10001, $data['msg']);
+        }
+    }
+
+    /**
+     * 取消兑换
+     */
+    public function order_cancel() {
+        $pointorder_model = model('pointorder');
+        //取消订单
+        $data = $pointorder_model->cancelPointorder(input('param.id'));
+        if ($data['state']) {
+            ds_json_encode(10000, lang('admin_pointorder_cancel_success'));
+        } else {
+            ds_json_encode(10001, $data['msg']);
+        }
+    }
+
+    /**
+     * 发货
+     */
+    public function order_ship() {
+        $order_id = intval(input('param.id'));
+        if ($order_id <= 0) {
+            $this->error(lang('admin_pointorder_parameter_error'),(string)url('Pointorder/pointorder_list'));
+        }
+        $pointorder_model = model('pointorder');
+        //获取订单状态
+        $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
+
+        //查询订单信息
+        $where = array();
+        $where[]=array('point_orderid','=',$order_id);
+        $where[]=array('point_orderstate','in', array($pointorderstate_arr['waitship'][0], $pointorderstate_arr['waitreceiving'][0])); //待发货和已经发货状态
+        $order_info = $pointorder_model->getPointorderInfo($where);
+        if (!$order_info) {
+            $this->error(lang('admin_pointorderd_record_error'),(string)url('Pointorder/pointorder_list'));
+        }
+        if (request()->isPost()) {
+            $data = [
+                'shippingcode' => input('post.shippingcode')
+            ];
+            $point_validate = ds_validate('point');
+            if (!$point_validate->scene('order_ship')->check($data)) {
+                $this->error($point_validate->getError());
+            }
+
+            //发货
+            $data = $pointorder_model->shippingPointorder($order_id, input('post.'), $order_info);
+            if ($data['state']) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error($data['msg'],(string)url('Pointorder/pointorder_list'));
+            }
+        } else {
+            $express_list = model('express')->getExpressList();
+            View::assign('express_list', $express_list);
+            View::assign('order_info', $order_info);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 兑换信息详细
+     */
+    public function order_info() {
+        $order_id = intval(input('param.order_id'));
+        if ($order_id <= 0) {
+            $this->error(lang('admin_pointorder_parameter_error'));
+        }
+        //查询订单信息
+        $pointorder_model = model('pointorder');
+        $order_info = $pointorder_model->getPointorderInfo(array('point_orderid' => $order_id));
+        if (!$order_info) {
+            $this->error(lang('admin_pointorderd_record_error'));
+        }
+        $orderstate_arr = $pointorder_model->getPointorderState($order_info['point_orderstate']);
+        $order_info['point_orderstatetext'] = $orderstate_arr[1];
+
+        //查询兑换订单收货人地址
+        $orderaddress_info = $pointorder_model->getPointorderAddressInfo(array('pointoa_orderid' => $order_id));
+        View::assign('orderaddress_info', $orderaddress_info);
+
+        //兑换商品信息
+        $prod_list = $pointorder_model->getPointordergoodsList(array('pointog_orderid' => $order_id));
+        View::assign('prod_list', $prod_list);
+
+        //物流公司信息
+        if ($order_info['point_shipping_ecode'] != '') {
+            $data = model('express')->getExpressInfoByECode($order_info['point_shipping_ecode']);
+            if ($data['state']) {
+                $express_info = $data['data']['express_info'];
+            }
+            View::assign('express_info', $express_info);
+        }
+
+        View::assign('order_info', $order_info);
+        return View::fetch();
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'pointorder_list', 'text' => lang('admin_pointorder_list_title'), 'url' => (string)url('Pointorder/pointorder_list')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 504 - 0
app/admin/controller/Pointprod.php

@@ -0,0 +1,504 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Pointprod extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/pointprod.lang.php');
+    }
+
+    /**
+     * 积分礼品列表
+     */
+    public function index() {
+        $pointprod_model = model('pointprod');
+
+        //获得兑换商品的上下架状态
+        $pgoodsshowstate_arr = $pointprod_model->getPgoodsShowState();
+        //获得兑换商品的推荐状态
+        $pgoodsrecommendstate_arr = $pointprod_model->getPgoodsRecommendState();
+
+        //条件
+        $where = array();
+        $pgoods_name = trim(input('param.pg_name'));
+        if ($pgoods_name) {
+            $where[] = array('pgoods_name', 'like', "%{$pgoods_name}%");
+        }
+        switch (trim(input('param.pg_state'))) {
+            case 'show':
+                $where[] = array('pgoods_show', '=', $pgoodsshowstate_arr['show'][0]);
+                break;
+            case 'nshow':
+                $where[] = array('pgoods_show', '=', $pgoodsshowstate_arr['unshow'][0]);
+                break;
+            case 'commend':
+                $where[] = array('pgoods_commend', '=', $pgoodsrecommendstate_arr['commend'][0]);
+                break;
+        }
+        $prod_list = $pointprod_model->getPointProdList($where, '*', 'pgoods_sort asc,pgoods_id desc', 0, 10);
+        //信息输出
+        View::assign('prod_list', $prod_list);
+        View::assign('show_page', $pointprod_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 积分礼品添加
+     */
+    public function prod_add() {
+        $hourarr = array(
+            '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17',
+            '18', '19', '20', '21', '22', '23'
+        );
+        $upload_model = model('upload');
+        if (request()->isPost()) {
+            //验证表单
+            $data = [
+                'goodsname' => input('post.goodsname'), 'goodsprice' => input('post.goodsprice'),
+                'goodspoints' => input('post.goodspoints'), 'goodsserial' => input('post.goodsserial'),
+                'goodsstorage' => input('post.goodsstorage'), 'sort' => input('post.sort'),
+            ];
+            if (input('post.sort') == 1) {
+                $data['limitnum'] = input('postlimitnumsort');
+            }
+            if (input('post.islimittime')) {
+                $data['starttime'] = input('post.starttime');
+                $data['endtime'] = input('post.endtime');
+            }
+
+            $point_validate = ds_validate('point');
+            if (!$point_validate->scene('prod_add')->check($data)) {
+                $this->error($point_validate->getError());
+            }
+            $pointprod_model = model('pointprod');
+            $goods_array = array();
+            $goods_array['pgoods_name'] = trim(input('post.goodsname'));
+            $goods_array['pgoods_tag'] = trim(input('post.goodstag'));
+            $goods_array['pgoods_price'] = trim(input('post.goodsprice'));
+
+            $goods_array['pgoods_points'] = trim(input('post.goodspoints'));
+            $goods_array['pgoods_serial'] = trim(input('post.goodsserial'));
+            $goods_array['pgoods_storage'] = intval(input('post.goodsstorage'));
+
+
+            $goods_array['pgoods_islimit'] = intval(input('post.islimit'));
+            if ($goods_array['pgoods_islimit'] == 1) {
+                $goods_array['pgoods_limitnum'] = intval(input('post.limitnum'));
+            } else {
+                $goods_array['pgoods_limitnum'] = 0;
+            }
+            $goods_array['pgoods_islimittime'] = intval(input('post.islimittime'));
+            if ($goods_array['pgoods_islimittime'] == 1) {
+                //如果添加了开始时间
+                if (trim(input('post.starttime'))) {
+                    $starttime = trim(input('post.starttime'));
+                    $sdatearr = explode('-', $starttime);
+                    $starttime = mktime(intval(input('post.starthour')), 0, 0, $sdatearr[1], $sdatearr[2], $sdatearr[0]);
+                    unset($sdatearr);
+                }
+                if (trim(input('post.endtime'))) {
+                    $endtime = trim(input('post.endtime'));
+                    $edatearr = explode('-', $endtime);
+                    $endtime = mktime(intval(input('post.endhour')), 0, 0, $edatearr[1], $edatearr[2], $edatearr[0]);
+                }
+                $goods_array['pgoods_starttime'] = $starttime;
+                $goods_array['pgoods_endtime'] = $endtime;
+            } else {
+                $goods_array['pgoods_starttime'] = '';
+                $goods_array['pgoods_endtime'] = '';
+            }
+            $goods_array['pgoods_show'] = trim(input('post.showstate'));
+            $goods_array['pgoods_commend'] = trim(input('post.commendstate'));
+            $goods_array['pgoods_addtime'] = TIMESTAMP;
+
+            $goods_array['pgoods_close_reason'] = trim(input('post.forbidreason'));
+            $goods_array['pgoods_keywords'] = trim(input('post.keywords'));
+            $goods_array['pgoods_description'] = trim(input('post.description'));
+
+            $goods_array['pgoods_body'] = trim(input('post.pgoods_body'));
+            $goods_array['pgoods_sort'] = intval(input('post.sort'));
+
+            $goods_array['pgoods_limitmgrade'] = intval(input('post.limitgrade'));
+
+            //添加礼品代表图片
+
+            $indeximg_succ = false;
+
+            if (!empty($_FILES['goods_images']['name'])) {
+
+                $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_POINTPROD;
+                $res = ds_upload_pic(ATTACH_POINTPROD, 'goods_images');
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $indeximg_succ = true;
+                    $goods_array['pgoods_image'] = $file_name;
+                    ds_create_thumb($upload_file, $file_name, '60,240', '60,240', '_small,_normal');
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+
+            $state = $pointprod_model->addPointgoods($goods_array);
+            if ($state) {
+                //礼品代表图片数据入库
+                if ($indeximg_succ) {
+                    $insert_array = array();
+                    $insert_array['file_name'] = $file_name;
+                    $insert_array['upload_type'] = 5;
+                    $insert_array['file_size'] = (config('ds_config.upload_type')=='alioss')?0:filesize($upload_file . DIRECTORY_SEPARATOR . $file_name);
+                    $insert_array['item_id'] = $state;
+                    $insert_array['upload_time'] = TIMESTAMP;
+                    $upload_model->addUpload($insert_array);
+                }
+                //更新积分礼品描述图片
+                $file_idstr = '';
+                $condition = array();
+                $condition[] = array('upload_type', '=', 6);
+                $condition[] = array('item_id', '=', 0);
+
+                $file_id_array = input('post.file_id/a');
+                if (is_array($file_id_array) && count($file_id_array) > 0) {
+                    $condition[] = array('upload_id', 'in', $file_id_array);
+                }
+                $upload_model->editUpload(array('item_id' => $state), $condition);
+
+                $this->log(lang('admin_pointprod_add_title') . '[' . input('post.goodsname') . ']');
+                $this->success(lang('admin_pointprod_add_success'), 'pointprod/index');
+            }
+        }
+        //模型实例化
+        $condition = array();
+        $condition[] = array('upload_type', '=', '6');
+        $condition[] = array('item_id', '=', '0');
+        $file_upload = $upload_model->getUploadList($condition);
+        View::assign('file_upload', $file_upload);
+        View::assign('PHPSESSID', session_id());
+        $hourarr = array(
+            '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17',
+            '18', '19', '20', '21', '22', '23'
+        );
+        View::assign('hourarr', $hourarr);
+        //会员级别
+        $member_grade = model('member')->getMemberGradeArr();
+
+        View::assign('member_grade', $member_grade);
+        $this->setAdminCurItem('prod_add');
+        return View::fetch();
+    }
+
+    /**
+     * 积分礼品编辑
+     */
+    public function prod_edit() {
+        $hourarr = array(
+            '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17',
+            '18', '19', '20', '21', '22', '23'
+        );
+        $upload_model = model('upload');
+        $pg_id = intval(input('param.pg_id'));
+        if (!$pg_id) {
+            $this->error(lang('admin_pointprod_parameter_error'), 'pointprod/index');
+        }
+        $pointprod_model = model('pointprod');
+        //查询礼品记录是否存在
+        $prod_info = $pointprod_model->getPointProdInfo(array('pgoods_id' => $pg_id));
+
+        if (!$prod_info) {
+            $this->error(lang('admin_pointprod_record_error'), 'pointprod/index');
+        }
+        if (request()->isPost()) {
+            //验证表单
+            $data = [
+                'goodsname' => input('post.goodsname'), 'goodsprice' => input('post.goodsprice'),
+                'goodspoints' => input('post.goodspoints'), 'goodsserial' => input('post.goodsserial'),
+                'goodsstorage' => input('post.goodsstorage'), 'sort' => input('post.sort'),
+            ];
+
+            if (input('post.islimit') == 1) {
+                $data['limitnum'] = input('post.limitnum');
+            }
+            if (input('post.islimittime')) {
+                $data['starttime'] = input('post.starttime');
+                $data['endtime'] = input('post.endtime');
+            }
+
+            $point_validate = ds_validate('point');
+            if (!$point_validate->scene('prod_edit')->check($data)) {
+                $this->error($point_validate->getError());
+            }
+
+            //实例化店铺商品模型
+            $pointprod_model = model('pointprod');
+
+            $goods_array = array();
+            $goods_array['pgoods_name'] = trim(input('post.goodsname'));
+            $goods_array['pgoods_tag'] = trim(input('post.goodstag'));
+            $goods_array['pgoods_price'] = trim(input('post.goodsprice'));
+
+            $goods_array['pgoods_points'] = trim(input('post.goodspoints'));
+            $goods_array['pgoods_serial'] = trim(input('post.goodsserial'));
+            $goods_array['pgoods_storage'] = intval(input('post.goodsstorage'));
+            $goods_array['pgoods_islimit'] = intval(input('post.islimit'));
+            if ($goods_array['pgoods_islimit'] == 1) {
+                $goods_array['pgoods_limitnum'] = intval(input('post.limitnum'));
+            } else {
+                $goods_array['pgoods_limitnum'] = 0;
+            }
+            $goods_array['pgoods_islimittime'] = intval(input('post.islimittime'));
+            if ($goods_array['pgoods_islimittime'] == 1) {
+                //如果添加了开始时间
+                if (trim(input('post.starttime'))) {
+                    $starttime = trim(input('post.starttime'));
+                    $sdatearr = explode('-', $starttime);
+                    $starttime = mktime(intval(input('post.starthour')), 0, 0, $sdatearr[1], $sdatearr[2], $sdatearr[0]);
+                    unset($sdatearr);
+                }
+                if (trim(input('post.endtime'))) {
+                    $endtime = trim(input('post.endtime'));
+                    $edatearr = explode('-', $endtime);
+                    $endtime = mktime(intval(input('post.endhour')), 0, 0, $edatearr[1], $edatearr[2], $edatearr[0]);
+                }
+                $goods_array['pgoods_starttime'] = $starttime;
+                $goods_array['pgoods_endtime'] = $endtime;
+            } else {
+                $goods_array['pgoods_starttime'] = '';
+                $goods_array['pgoods_endtime'] = '';
+            }
+            $goods_array['pgoods_show'] = trim(input('post.showstate'));
+            $goods_array['pgoods_commend'] = trim(input('post.commendstate'));
+
+            $goods_array['pgoods_close_reason'] = trim(input('post.forbidreason'));
+            $goods_array['pgoods_keywords'] = trim(input('post.keywords'));
+            $goods_array['pgoods_description'] = trim(input('post.description'));
+
+            $goods_array['pgoods_body'] = trim(input('post.pgoods_body'));
+
+            $goods_array['pgoods_sort'] = intval(input('post.sort'));
+            $goods_array['pgoods_limitmgrade'] = intval(input('post.limitgrade'));
+
+            //添加礼品代表图片
+            $indeximg_succ = false;
+
+            if (!empty($_FILES['goods_images']['name'])) {
+                $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_POINTPROD;
+                $res = ds_upload_pic(ATTACH_POINTPROD, 'goods_images');
+                if ($res['code']) {
+                    $file_name = $res['data']['file_name'];
+                    $indeximg_succ = true;
+                    $goods_array['pgoods_image'] = $file_name;
+                    ds_create_thumb($upload_file, $file_name, '60,240', '60,240', '_small,_normal');
+                } else {
+                    $this->error($res['msg']);
+                }
+            }
+
+            $state = $pointprod_model->editPointProd($goods_array, array('pgoods_id' => $prod_info['pgoods_id']));
+            if ($state) {
+                //礼品代表图片数据入库
+                if ($indeximg_succ) {
+                    //删除原有图片
+                    $upload_list = $upload_model->getUploadList(array('upload_type' => 5, 'item_id' => $prod_info['pgoods_id']));
+
+                    if (is_array($upload_list) && count($upload_list) > 0) {
+                        $upload_idarr = array();
+                        foreach ($upload_list as $v) {
+                            //批量删除图片
+                            ds_unlink($upload_file, $v['file_name']);
+                            $upload_idarr[] = $v['upload_id'];
+                        }
+                        //删除图片
+                        $condition = array();
+                        $condition[] = array('upload_id', 'in', $upload_idarr);
+                        $upload_model->delUpload($condition);
+                    }
+                    $insert_array = array();
+                    $insert_array['file_name'] = $file_name;
+                    $insert_array['upload_type'] = 5;
+                    $insert_array['file_size'] = (config('ds_config.upload_type')=='alioss')?0:filesize($upload_file . DIRECTORY_SEPARATOR . $file_name);
+                    $insert_array['item_id'] = $prod_info['pgoods_id'];
+                    $insert_array['upload_time'] = TIMESTAMP;
+                    $upload_model->addUpload($insert_array);
+                }
+                //更新积分礼品描述图片
+
+                $file_idstr = '';
+                $condition = array();
+                $condition[] = array('upload_type', '=', 6);
+                $condition[] = array('item_id', '=', 0);
+                $file_id_array = input('post.file_id/a');
+                if (is_array($file_id_array) && count($file_id_array) > 0) {
+                    $file_idstr = "'" . implode("','", $file_id_array) . "'";
+                    $condition[] = array('upload_id', 'in', $file_idstr);
+                }
+                $upload_model->editUpload(array('item_id' => $prod_info['pgoods_id']), $condition);
+
+
+                $this->log(lang('ds_edit') . lang('admin_pointprodp') . '[' . input('post.goodsname') . ']');
+                $this->success(lang('admin_pointprod_edit_success'), 'pointprod/index');
+            }
+            $this->error(lang('admin_pointprod_edit_fail'));
+        } else {
+            $condition = array();
+            $condition[] = array('upload_type', '=', '6');
+            $condition[] = array('item_id', '=', $pg_id);
+            $file_upload = $upload_model->getUploadList($condition);
+            //会员级别
+            $member_grade = model('member')->getMemberGradeArr();
+            View::assign('member_grade', $member_grade);
+            View::assign('file_upload', $file_upload);
+            View::assign('PHPSESSID', session_id());
+            View::assign('hourarr', $hourarr);
+            View::assign('prod_info', $prod_info);
+            $this->setAdminCurItem('prod_edit');
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除积分礼品
+     */
+    public function prod_drop() {
+        $pg_id = input('param.pg_id');
+        $pg_id_array = ds_delete_param($pg_id);
+        if ($pg_id_array === FALSE) {
+            ds_json_encode('10001', lang('admin_pointprod_parameter_error'));
+        }
+        $pointprod_model = model('pointprod');
+        $result = $pointprod_model->delPointProdById($pg_id_array);
+        if ($result) {
+            $this->log(lang('ds_del') . lang('admin_pointprodp') . '[ID:' . $pg_id . ']');
+            ds_json_encode('10000', lang('admin_pointprod_del_success'));
+        } else {
+            ds_json_encode('10001', lang('admin_pointprod_del_fail'));
+        }
+    }
+
+    /**
+     * 积分礼品异步状态修改
+     */
+    public function ajax() {
+        //礼品上架,礼品推荐,礼品禁售
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            echo 'false';
+            exit;
+        }
+        $pointprod_model = model('pointprod');
+        $update_array = array();
+        $update_array[input('param.column')] = trim(input('param.value'));
+        $pointprod_model->editPointProd($update_array, array('pgoods_id' => $id));
+        echo 'true';
+        exit;
+    }
+
+    /**
+     * 积分礼品上传
+     */
+    public function pointprod_pic_upload() {
+        /**
+         * 上传图片
+         */
+        $file_name = '';
+        $file_object = request()->file('fileupload');
+        if ($file_object) {
+            $res = ds_upload_pic(ATTACH_POINTPROD, 'fileupload');
+            if ($res['code']) {
+                $file_name = $res['data']['file_name'];
+            } else {
+                echo $res['msg'];
+                exit;
+            }
+        } else {
+            echo 'error';
+            exit;
+        }
+
+        /**
+         * 模型实例化
+         */
+        $upload_model = model('upload');
+        /**
+         * 图片数据入库
+         */
+        $insert_array = array();
+        $insert_array['file_name'] = $file_name;
+        $insert_array['upload_type'] = '6';
+        $insert_array['file_size'] = $_FILES['fileupload']['size'];
+        $insert_array['upload_time'] = TIMESTAMP;
+        $insert_array['item_id'] = input('param.item_id', 0);
+        $result = $upload_model->addUpload($insert_array);
+        if ($result) {
+            $data = array();
+            $data['file_id'] = $result;
+            $data['file_name'] = $file_name;
+            $data['file_path'] = ds_get_pic( ATTACH_POINTPROD , $file_name);
+            /**
+             * 整理为json格式
+             */
+            $output = json_encode($data);
+            echo $output;
+        }
+    }
+
+    /**
+     * ajax操作删除已上传图片
+     */
+    public function ajaxdelupload() {
+        //删除文章图片
+        if (intval(input('param.file_id')) > 0) {
+            $upload_model = model('upload');
+            /**
+             * 删除图片
+             */
+            $file_array = $upload_model->getOneUpload(intval(input('param.file_id')));
+            @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_POINTPROD . DIRECTORY_SEPARATOR . $file_array['file_name']);
+            /**
+             * 删除信息
+             */
+            $condition = array();
+            $condition[] = array('upload_id', '=', intval(input('param.file_id')));
+            $upload_model->delUpload($condition);
+            echo 'true';
+            exit;
+        } else {
+            echo 'false';
+            exit;
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('admin_pointprod_list_title'), 'url' => (string) url('Pointprod/index')
+            ), array(
+                'name' => 'prod_add', 'text' => lang('admin_pointprod_add_title'), 'url' => (string) url('Pointprod/prod_add')
+            ),
+        );
+        if (request()->action() == 'prod_edit') {
+            $menu_array[] = array(
+                'name' => 'prod_edit', 'text' => lang('admin_pointprod_edit_title'), 'url' => 'javascript:void()'
+            );
+        }
+
+        return $menu_array;
+    }
+
+}

+ 278 - 0
app/admin/controller/Points.php

@@ -0,0 +1,278 @@
+<?php
+
+/**
+ * 积分管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Points extends AdminControl {
+    const EXPORT_SIZE = 5000;
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/points.lang.php');
+    }
+
+    public function index() {
+        if (!request()->isPost()) {
+            $condition_arr = array();
+            $mname = input('param.mname');
+            if (!empty($mname)) {
+                $condition_arr[] = array('pl_membername','like', '%' . $mname . '%');
+            }
+            $aname = input('param.aname');
+            if (!empty($aname)) {
+                $condition_arr[] = array('pl_adminname','like', '%' . $aname . '%');
+            }
+            $stage = input('get.stage');
+            if ($stage) {
+                $condition_arr[]=array('pl_stage','=',trim($stage));
+            }
+            $stime = input('get.stime');
+            $etime = input('get.etime');
+            $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+            $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+            $start_unixtime = $if_start_time ? strtotime($stime) : null;
+            $end_unixtime = $if_end_time ? strtotime($etime) : null;
+            if ($start_unixtime) {
+                $condition_arr[] = array('pl_addtime','>=', $start_unixtime);
+            }
+            if ($end_unixtime) {
+                $end_unixtime=$end_unixtime+86399;
+                $condition_arr[] = array('pl_addtime','<=', $end_unixtime);
+            }
+            
+            $search_desc = trim(input('param.description'));
+            if (!empty($search_desc)) {
+                $condition_arr[] = array('pl_desc','like', "%" . $search_desc . "%");
+            }
+
+
+            $points_model = model('points');
+            $list_log = $points_model->getPointslogList($condition_arr, 10, '*', '');
+
+            View::assign('pointslog', $list_log);
+            View::assign('show_page', $points_model->page_info->render());
+            $this->setAdminCurItem('index');
+            return View::fetch();
+        }
+    }
+
+    //积分规则设置
+    function setting(){
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $update_array = array();
+            $update_array['points_reg'] = intval(input('post.points_reg'));
+            $update_array['points_login'] = intval(input('post.points_login'));
+            $update_array['points_comments'] = intval(input('post.points_comments'));
+            $update_array['points_orderrate'] = intval(input('post.points_orderrate'));
+            $update_array['points_ordermax'] = intval(input('post.points_ordermax'));
+            $update_array['points_invite'] = intval(input('post.points_invite'));
+            $update_array['points_rebate'] = intval(input('post.points_rebate'));
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('setting');
+            return View::fetch('setting');
+        }
+    }
+    
+    //积分明细查询
+    function pointslog() {
+        if (!request()->isPost()) {
+            return View::fetch();
+        } else {
+            $data = [
+                'member_name' => input('post.member_name'),
+                'points_type' => input('post.points_type'),
+                'points_num' => intval(input('post.points_num')),
+                'points_desc' => input('post.points_desc'),
+            ];
+            $point_validate = ds_validate('point');
+            if (!$point_validate->scene('pointslog')->check($data)) {
+                $this->error($point_validate->getError());
+            }
+
+            $member_name = $data['member_name'];
+            $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
+            if (!is_array($member_info) || count($member_info) <= 0) {
+                $this->error(lang('admin_points_userrecord_error'));
+            }
+            if ($data['points_type'] == 2 && $data['points_num'] > $member_info['member_points']) {
+                $this->error(lang('admin_points_points_short_error') . $member_info['member_points']);
+            }
+            //积分数据记录
+            $insert_arr['pl_memberid'] = $member_info['member_id'];
+            $insert_arr['pl_membername'] = $member_info['member_name'];
+            if ($data['points_type'] == 2) {
+                $insert_arr['pl_points'] = -$data['points_num'];
+            } else {
+                $insert_arr['pl_points'] = $data['points_num'];
+            }
+            $insert_arr['pl_desc'] = $data['points_desc'];
+            $insert_arr['pl_adminname'] = session('admin_name');
+
+            $result = model('points')->savePointslog('system', $insert_arr);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('error'), 'Points/index');
+            }
+        }
+    }
+
+    public function checkmember() {
+        $name = trim(input('param.name'));
+        if (!$name) {
+            exit(json_encode(array('id' => 0)));
+        }
+        $member_info = model('member')->getMemberInfo(array('member_name' => $name));
+        if (is_array($member_info) && count($member_info) > 0) {
+            echo json_encode(array('id' => $member_info['member_id'], 'name' => $member_info['member_name'], 'points' => $member_info['member_points']));
+        } else {
+            exit(json_encode(array('id' => 0)));
+            die;
+        }
+    }
+
+
+	/**
+     * 积分日志列表导出
+     */
+    public function export_step1() {
+        $condition_arr = array();
+        
+        $mname = input('param.mname');
+        if (!empty($mname)) {
+            $condition_arr[] = array('pl_membername','like', '%' . $mname . '%');
+        }
+        $aname = input('param.aname');
+        if (!empty($aname)) {
+            $condition_arr[] = array('pl_adminname','like', '%' . $aname . '%');
+        }
+        
+        $stage = input('get.stage');
+        if ($stage) {
+            $condition_arr[]=array('pl_stage','=',trim($stage));
+        }
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_time ? strtotime($stime) : null;
+        $end_unixtime = $if_end_time ? strtotime($etime) : null;
+        if ($start_unixtime || $end_unixtime) {
+            $condition_arr[] = array('pl_addtime','between', array($start_unixtime, $end_unixtime));
+        }
+        $search_desc = trim(input('param.description'));
+        if (!empty($search_desc)) {
+            $condition_arr[] = array('pl_desc','like', "%" . $search_desc . "%");
+        }
+        
+        
+        $points_model = model('points');
+        
+        if (!is_numeric(input('param.page'))) {
+            $count = $points_model->getPointsCount($condition_arr);
+            $array = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $array[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $array);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $list_log = $points_model->getPointsLogList($condition_arr, '', '*', self::EXPORT_SIZE);
+                $this->createExcel($list_log);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $list_log = $points_model->getPointsLogList($condition_arr, $limit2);
+            $this->createExcel($list_log);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_member'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_system'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_point'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_time'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_jd'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_ms'));
+        $state_cn = array(lang('admin_points_stage_regist'), lang('admin_points_stage_login'), lang('admin_points_stage_comments'), lang('admin_points_stage_order'), lang('admin_points_stage_system'), lang('admin_points_stage_pointorder'), lang('admin_points_stage_app'));
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['pl_membername']);
+            $tmp[] = array('data' => $v['pl_adminname']);
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pl_points']));
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pl_addtime']));
+            $tmp[] = array('data' => str_replace(array('regist', 'login', 'comments', 'order', 'system', 'pointorder', 'app'), $state_cn, $v['pl_stage']));
+            $tmp[] = array('data' => $v['pl_desc']);
+
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('admin_points_log_title'),
+                'url' => (string)url('Points/index')
+            ),
+            array(
+                'name' => 'pointslog',
+                'text' => lang('pointslog'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Points/pointslog')."','".lang('pointslog')."')"
+            ),
+            array(
+                'name' => 'setting',
+                'text' => lang('points_setting'),
+                'url' => (string)url('Points/setting')
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 891 - 0
app/admin/controller/Predeposit.php

@@ -0,0 +1,891 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Predeposit extends AdminControl {
+    const EXPORT_SIZE = 1000;
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/predeposit.lang.php');
+    }
+
+    /*
+     * 充值明细
+     */
+
+    public function pdrecharge_list() {
+        $condition = array();
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
+        $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
+        $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
+        if ($start_unixtime) {
+            $condition[]=array('pdr_addtime','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[]=array('pdr_addtime','<=', $end_unixtime);
+        }
+        if (input('param.mname') != '') {
+            $condition[]=array('pdr_member_name','like', "%" . input('param.mname') . "%");
+        }
+        if (input('param.paystate_search') != '') {
+            $condition[]=array('pdr_payment_state','=',input('param.paystate_search'));
+        }
+        $predeposit_model = model('predeposit');
+        $recharge_list = $predeposit_model->getPdRechargeList($condition, 20, '*', 'pdr_id desc');
+        View::assign('recharge_list', $recharge_list);
+        View::assign('show_page', $predeposit_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('pdrecharge_list');
+        return View::fetch();
+    }
+
+    /**
+     * 充值编辑(更改成收到款)
+     */
+    public function recharge_edit() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdrecharge_list');
+        }
+        //查询充值信息
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdr_id','=',$id);
+        $condition[] = array('pdr_payment_state','=',0);
+        $info = $predeposit_model->getPdRechargeInfo($condition);
+        if (empty($info)) {
+            $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdrecharge_list');
+        }
+        if (!request()->isPost()) {
+            //显示支付接口列表
+            $payment_list = model('payment')->getPaymentOpenList();
+            //去掉预存款和货到付款
+            foreach ($payment_list as $key => $value) {
+                if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
+                    unset($payment_list[$key]);
+                }
+            }
+            View::assign('payment_list', $payment_list);
+            View::assign('info', $info);
+            return View::fetch('recharge_edit');
+        }
+
+        //取支付方式信息
+        $payment_model = model('payment');
+        $condition = array();
+        $condition[]=array('payment_code','=',input('post.payment_code'));
+        $payment_info = $payment_model->getPaymentOpenInfo($condition);
+        if (!$payment_info || $payment_info['payment_code'] == 'offline' || $payment_info['payment_code'] == 'offline') {
+            $this->error(lang('payment_index_sys_not_support'));
+        }
+
+        $condition = array();
+        $condition[] = array('pdr_sn','=',$info['pdr_sn']);
+        $condition[] = array('pdr_payment_state','=',0);
+        $update = array();
+        $update['pdr_payment_state'] = 1;
+        $update['pdr_paymenttime'] = strtotime(input('post.payment_time'));
+        $update['pdr_payment_code'] = $payment_info['payment_code'];
+        $update['pdr_trade_sn'] = input('post.trade_no');
+        $update['pdr_admin'] = $this->admin_info['admin_name'];
+        $log_msg = lang('admin_predeposit_recharge_edit_state') . ',' . lang('admin_predeposit_sn') . ':' . $info['pdr_sn'];
+
+        Db::startTrans();
+        try {
+            //更改充值状态
+            $state = $predeposit_model->editPdRecharge($update, $condition);
+            if (!$state) {
+                throw Exception(lang('predeposit_payment_pay_fail'));
+            }
+            //变更会员预存款
+            $data = array();
+            $data['member_id'] = $info['pdr_member_id'];
+            $data['member_name'] = $info['pdr_member_name'];
+            $data['amount'] = $info['pdr_amount'];
+            $data['pdr_sn'] = $info['pdr_sn'];
+            $data['admin_name'] = $this->admin_info['admin_name'];
+            $predeposit_model->changePd('recharge', $data);
+            Db::commit();
+            $this->log($log_msg, 1);
+            dsLayerOpenSuccess(lang('admin_predeposit_recharge_edit_success'));
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->log($log_msg, 0);
+            $this->error($e->getMessage(), 'Predeposit/pdrecharge_list');
+        }
+    }
+
+    /**
+     * 充值查看
+     */
+    public function recharge_info() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdrecharge_list');
+        }
+        //查询充值信息
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdr_id','=',$id);
+        $info = $predeposit_model->getPdRechargeInfo($condition);
+        if (empty($info)) {
+            $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdrecharge_list');
+        }
+        View::assign('info', $info);
+        return View::fetch('recharge_info');
+    }
+
+    /**
+     * 充值删除
+     */
+    public function recharge_del() {
+        $pdr_id = input('param.pdr_id');
+        $pdr_id_array = ds_delete_param($pdr_id);
+        if($pdr_id_array === FALSE){
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdr_id','in', $pdr_id_array);
+        $condition[] = array('pdr_payment_state','=',0);
+        $result = $predeposit_model->delPdRecharge($condition);
+        if ($result) {
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+
+
+    /*
+     * 预存款明细
+     */
+
+    public function pdlog_list() {
+        $condition = array();
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_date ? strtotime($stime) : null;
+        $end_unixtime = $if_end_date ? strtotime($etime) : null;
+        if ($start_unixtime) {
+            $condition[]=array('lg_addtime','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[]=array('lg_addtime','<=', $end_unixtime);
+        }
+        $mname = input('get.mname');
+        if (!empty($mname)) {
+            $condition[] = array('lg_member_name','=',$mname);
+        }
+        $aname = input('get.aname');
+        if (!empty($aname)) {
+            $condition[] = array('lg_admin_name','=',$aname);
+        }
+        $predeposit_model = model('predeposit');
+        $list_log = $predeposit_model->getPdLogList($condition, 10, '*', 'lg_id desc');
+        View::assign('show_page', $predeposit_model->page_info->render());
+        View::assign('list_log', $list_log);
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('pdlog_list');
+        return View::fetch();
+    }
+
+    /*
+     * 提现设置
+     */
+    public function pdcash_set(){
+        $config_model = model('config');
+        if(!request()->isPost()){
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting',$list_setting);
+            $this->setAdminCurItem('pdcash_set');
+            return View::fetch();
+        }else{
+            $update_array=array(
+                'member_withdraw_min'=>abs(round(input('post.member_withdraw_min'),2)),
+                'member_withdraw_max'=>abs(round(input('post.member_withdraw_max'),2)),
+                'member_withdraw_cycle'=>abs(intval(input('post.member_withdraw_cycle'))),
+            );
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log(lang('ds_update').lang('admin_predeposit_cashset'),1);
+                $this->success(lang('ds_common_op_succ'), 'Predeposit/pdcash_set');
+            }else{
+                $this->log(lang('ds_update').lang('admin_predeposit_cashset'),0);
+            }
+        }
+    }
+    /*
+     * 提现列表
+     */
+    public function pdcash_list() {
+        $condition = array();
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_date ? strtotime($stime) : null;
+        $end_unixtime = $if_end_date ? strtotime($etime) : null;
+        if ($start_unixtime) {
+            $condition[]=array('pdc_addtime','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[]=array('pdc_addtime','<=', $end_unixtime);
+        }
+        $mname = input('get.mname');
+        if (!empty($mname)) {
+            $condition[]=array('pdc_member_name','like', "%" . $mname . "%");
+        }
+        $pdc_bank_user = input('get.pdc_bank_user');
+        if (!empty($pdc_bank_user)) {
+            $condition[]=array('pdc_bank_user','like', "%" . $pdc_bank_user . "%");
+        }
+        $paystate_search = input('get.paystate_search');
+        if ($paystate_search != '') {
+            $condition[]=array('pdc_payment_state','=',$paystate_search);
+        }
+        $predeposit_model = model('predeposit');
+        $predeposit_list = $predeposit_model->getPdcashList($condition, 20, '*', 'pdc_payment_state asc,pdc_id asc');
+        View::assign('predeposit_list', $predeposit_list);
+        View::assign('show_page', $predeposit_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('pdcash_list');
+        return View::fetch('pdcash_list');
+    }
+
+    /**
+     * 删除提现记录
+     */
+    public function pdcash_del() {
+        $pdc_id = intval(input('param.pdc_id'));
+        if ($pdc_id <= 0) {
+             ds_json_encode(10001, lang('param_error'));
+        }
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdc_id','=',$pdc_id);
+        $condition[] = array('pdc_payment_state','=',0);
+        $info = $predeposit_model->getPdcashInfo($condition);
+        if (!$info) {
+            ds_json_encode(10001, lang('admin_predeposit_parameter_error'));
+        }
+        try {
+            $result = $predeposit_model->delPdcash($condition);
+            if (!$result) {
+                ds_json_encode(10001, lang('admin_predeposit_cash_del_fail'));
+            }
+            //退还冻结的预存款
+            $member_model = model('member');
+            $member_info = $member_model->getMemberInfo(array('member_id' => $info['pdc_member_id']));
+            //扣除冻结的预存款
+            $admininfo = $this->getAdminInfo();
+            $data = array();
+            $data['member_id'] = $member_info['member_id'];
+            $data['member_name'] = $member_info['member_name'];
+            $data['amount'] = $info['pdc_amount'];
+            $data['order_sn'] = $info['pdc_sn'];
+            $data['admin_name'] = $admininfo['admin_name'];
+            $predeposit_model->changePd('cash_del', $data);
+            $predeposit_model->commit();
+            ds_json_encode(10000, lang('admin_predeposit_cash_del_success'));
+        } catch (Exception $e) {
+            $predeposit_model->commit();
+            ds_json_encode(10001, lang($e->getMessage()));
+        }
+    }
+
+    /**
+     * 更改提现为支付状态
+     */
+    public function pdcash_pay() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('admin_predeposit_parameter_error'),'Predeposit/pdcash_list');
+        }
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdc_id','=',$id);
+        $condition[] = array('pdc_payment_state','=',0);
+        $info = $predeposit_model->getPdcashInfo($condition);
+        if (!is_array($info) || count($info) < 0) {
+            $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdcash_list');
+        }
+        //查询用户信息
+        $member_model = model('member');
+        $member_info = $member_model->getMemberInfo(array('member_id' => $info['pdc_member_id']));
+
+        $update = array();
+        $admininfo = $this->getAdminInfo();
+        $update['pdc_payment_state'] = 1;
+        $update['pdc_payment_admin'] = $admininfo['admin_name'];
+        $update['pdc_payment_time'] = TIMESTAMP;
+        $log_msg = lang('admin_predeposit_cash_edit_state') . ',' . lang('admin_predeposit_cs_sn') . ':' . $info['pdc_sn'];
+
+        Db::startTrans();
+        try {
+            $result = $predeposit_model->editPdcash($update, $condition);
+            if (!$result) {
+                $this->error(lang('admin_predeposit_cash_edit_fail'));
+            }
+            //扣除冻结的预存款
+            $data = array();
+            $data['member_id'] = $member_info['member_id'];
+            $data['member_name'] = $member_info['member_name'];
+            $data['amount'] = $info['pdc_amount'];
+            $data['order_sn'] = $info['pdc_sn'];
+            $data['admin_name'] = $admininfo['admin_name'];
+            $predeposit_model->changePd('cash_pay', $data);
+            if($info['pdc_bank_type']=='alipay'){//如果是支付宝且开启了支付宝提现
+                $logic_payment = model('payment', 'logic');
+                $payment_code='alipay';
+                $result = $logic_payment->getPaymentInfo($payment_code);
+                if ($result['code']) {
+                    $payment_info = $result['data'];
+                    if($payment_info['payment_config']['alipay_trade_transfer_state'] == 1){
+                        $payment_api = new $payment_code($payment_info);
+                        $result = $payment_api->fund_transfer($info);
+                        if (!$result['code']) {
+                            throw new \think\Exception($result['msg'], 10006);
+                        }
+                        $result = $predeposit_model->editPdcash(array('pdc_payment_code'=>$payment_code,'pdc_trade_sn'=>$result['data']['pdc_trade_sn']), array('pdc_id'=>$id));
+                        if (!$result) {
+                            throw new \think\Exception(lang('admin_predeposit_cash_edit_fail'), 10006);
+                        }
+                    }
+                }
+            }elseif($info['pdc_bank_type']=='weixin'){//如果是微信且开启了微信提现
+                $logic_payment = model('payment', 'logic');
+                $payment_code='wxpay_native';
+                $result = $logic_payment->getPaymentInfo($payment_code);
+                if ($result['code']) {
+                    $payment_info = $result['data'];
+                    if($payment_info['payment_config']['wx_trade_transfer_state'] == 1){
+                        $payment_api = new $payment_code($payment_info);
+                        $result = $payment_api->fund_transfer($info);
+                        if (!$result['code']) {
+                            throw new \think\Exception($result['msg'], 10006);
+                        }
+                        $result = $predeposit_model->editPdcash(array('pdc_payment_code'=>$payment_code,'pdc_trade_sn'=>$result['data']['pdc_trade_sn']), array('pdc_id'=>$id));
+                        if (!$result) {
+                            throw new \think\Exception(lang('admin_predeposit_cash_edit_fail'), 10006);
+                        }
+                    }
+                }
+            }
+            
+            Db::commit();
+            $this->log($log_msg, 1);
+            dsLayerOpenSuccess(lang('admin_predeposit_cash_edit_success'));
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->log($log_msg, 0);
+            $this->error($e->getMessage(), 'Predeposit/pdcash_list');
+        }
+    }
+
+    /**
+     * 查看提现信息
+     */
+    public function pdcash_view() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('admin_predeposit_parameter_error'), 'Predeposit/pdcash_list');
+        }
+        $predeposit_model = model('predeposit');
+        $condition = array();
+        $condition[] = array('pdc_id','=',$id);
+        $info = $predeposit_model->getPdcashInfo($condition);
+        if (!is_array($info) || count($info) < 0) {
+            $this->error(lang('admin_predeposit_record_error'), 'Predeposit/pdcash_list');
+        }
+        View::assign('info', $info);
+        return View::fetch();
+    }
+
+    /*
+     * 调节预存款
+     */
+
+    public function pd_add() {
+        if (!(request()->isPost())) {
+            $member_id = intval(input('get.member_id'));
+            if($member_id>0){
+                $condition = array();
+                $condition[] = array('member_id','=',$member_id);
+                $member = model('member')->getMemberInfo($condition);
+                if(!empty($member)){
+                    View::assign('member_info',$member);
+                }
+            }
+            return View::fetch();
+        } else {
+            $data = array(
+                'member_id' => input('post.member_id'),
+                'amount' => input('post.amount'),
+                'operatetype' => input('post.operatetype'),
+                'lg_desc' => input('post.lg_desc'),
+            );
+            $predeposit_validate = ds_validate('predeposit');
+            if (!$predeposit_validate->scene('pd_add')->check($data)) {
+                $this->error($predeposit_validate->getError());
+            }
+
+            $money = abs(floatval(input('post.amount')));
+            $memo = trim(input('post.lg_desc'));
+            if ($money <= 0) {
+                $this->error(lang('amount_min'));
+            }
+            //查询会员信息
+            $member_mod = model('member');
+            $member_id = intval(input('post.member_id'));
+            $operatetype = input('post.operatetype');
+            $member_info = $member_mod->getMemberInfo(array('member_id' => $member_id));
+
+            if (!is_array($member_info) || count($member_info) <= 0) {
+                $this->error(lang('user_not_exist'), 'Predeposit/pd_add');
+            }
+            $available_predeposit = floatval($member_info['available_predeposit']);
+            $freeze_predeposit = floatval($member_info['freeze_predeposit']);
+            if ($operatetype == 2 && $money > $available_predeposit) {
+                $this->error(lang('avaliable_predeposit_not_enough') . $available_predeposit, 'Predeposit/pd_add');
+            }
+            if ($operatetype == 3 && $money > $available_predeposit) {
+                $this->error(lang('freezen_predeposit_not_enough') . $available_predeposit, 'Predeposit/pd_add');
+            }
+            if ($operatetype == 4 && $money > $freeze_predeposit) {
+                $this->error(lang('recover_freezen_predeposit_not_enough') . $freeze_predeposit, 'Predeposit/pd_add');
+            }
+            $predeposit_model = model('predeposit');
+            #生成对应订单号
+            $order_sn = makePaySn($member_id);
+            $admininfo = $this->getAdminInfo();
+            $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款,金额为" . $money . ",编号为" . $order_sn;
+            $admin_act = "sys_add_money";
+            switch ($operatetype) {
+                case 1:
+                    $admin_act = "sys_add_money";
+                    $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【增加】,金额为" . $money . ",编号为" . $order_sn;
+                    break;
+                case 2:
+                    $admin_act = "sys_del_money";
+                    $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【减少】,金额为" . $money . ",编号为" . $order_sn;
+                    break;
+                case 3:
+                    $admin_act = "sys_freeze_money";
+                    $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【冻结】,金额为" . $money . ",编号为" . $order_sn;
+                    break;
+                case 4:
+                    $admin_act = "sys_unfreeze_money";
+                    $log_msg = "管理员【" . $admininfo['admin_name'] . "】操作会员【" . $member_info['member_name'] . "】预存款【解冻】,金额为" . $money . ",编号为" . $order_sn;
+                    break;
+                default:
+                    $this->error(lang('ds_common_op_fail'), 'Predeposit/pdlog_list');
+                    break;
+            }
+            try {
+                Db::startTrans();
+                //扣除冻结的预存款
+                $data = array();
+                $data['member_id'] = $member_info['member_id'];
+                $data['member_name'] = $member_info['member_name'];
+                $data['amount'] = $money;
+                $data['order_sn'] = $order_sn;
+                $data['admin_name'] = $admininfo['admin_name'];
+                $data['pdr_sn'] = $order_sn;
+                $data['lg_desc'] = $memo;
+                $predeposit_model->changePd($admin_act, $data);
+                Db::commit();
+                $this->log($log_msg, 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->log($log_msg, 0);
+                $this->error($e->getMessage(), 'Predeposit/pdlog_list');
+            }
+        }
+    }
+
+    //取得会员信息
+    public function checkmember() {
+        $name = input('post.name');
+        if (!$name) {
+            exit(json_encode(array('id' => 0)));
+            die;
+        }
+        $obj_member = model('member');
+        $member_info = $obj_member->getMemberInfo(array('member_name' => $name));
+        if (is_array($member_info) && count($member_info) > 0) {
+            exit(json_encode(array('id' => $member_info['member_id'], 'name' => $member_info['member_name'], 'available_predeposit' => $member_info['available_predeposit'], 'freeze_predeposit' => $member_info['freeze_predeposit'])));
+        } else {
+            exit(json_encode(array('id' => 0)));
+        }
+    }
+    
+    
+    
+
+    /**
+     * 导出预存款充值记录
+     *
+     */
+    public function export_step1() {
+        $condition = array();
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
+        $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
+        $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
+        if ($start_unixtime) {
+            $condition[] = array('pdr_addtime','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[] = array('pdr_addtime','<=', $end_unixtime);
+        }
+        if (input('param.mname') != '') {
+            $condition[]=array('pdr_member_name','like', "%" . input('param.mname') . "%");
+        }
+        if (input('param.paystate_search') != '') {
+            $condition[]=array('pdr_payment_state','=',input('param.paystate_search'));
+        }
+        
+        
+        $predeposit_model = model('predeposit');
+        if (!is_numeric(input('param.page'))) {
+            $count = $predeposit_model->getPdRechargeCount($condition);
+            $array = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $array[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $array);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $predeposit_model->getPdRechargeList($condition, '', '*', 'pdr_id desc', self::EXPORT_SIZE);
+                $rechargepaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
+                foreach ($data as $k => $v) {
+                    $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
+                }
+                $this->createExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $predeposit_model->getPdRechargeList($condition, $limit2, '*', 'pdr_id desc');
+            $rechargepaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
+            foreach ($data as $k => $v) {
+                $data[$k]['pdr_payment_state'] = $rechargepaystate[$v['pdr_payment_state']];
+            }
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成导出预存款充值excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_no'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_member'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_ctime'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_ptime'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_pay'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_money'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_paystate'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_yc_memberid'));
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['pdr_sn']);
+            $tmp[] = array('data' => $v['pdr_member_name']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdr_addtime']));
+            if (intval($v['pdr_paymenttime'])) {
+                if (date('His', $v['pdr_paymenttime']) == 0) {
+                    $tmp[] = array('data' => date('Y-m-d', $v['pdr_paymenttime']));
+                } else {
+                    $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdr_paymenttime']));
+                }
+            } else {
+                $tmp[] = array('data' => '');
+            }
+            $tmp[] = array('data' => $v['pdr_payment_code']);
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pdr_amount']));
+            $tmp[] = array('data' => $v['pdr_payment_state']);
+            $tmp[] = array('data' => $v['pdr_member_id']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_yc_yckcz'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_yc_yckcz'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    
+    /**
+     * 导出预存款提现记录
+     *
+     */
+    public function export_cash_step1() {
+        $condition = array();
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_date ? strtotime($stime) : null;
+        $end_unixtime = $if_end_date ? strtotime($etime) : null;
+        if ($start_unixtime) {
+            $condition[] = array('pdc_addtime','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[] = array('pdc_addtime','<=', $end_unixtime);
+        }
+        $mname = input('get.mname');
+        if (!empty($mname)) {
+            $condition[]=array('pdc_member_name','like', "%" . $mname . "%");
+        }
+        $pdc_bank_user = input('get.pdc_bank_user');
+        if (!empty($pdc_bank_user)) {
+            $condition[]=array('pdc_bank_user','like', "%" . $pdc_bank_user . "%");
+        }
+        $paystate_search = input('get.paystate_search');
+        if ($paystate_search != '') {
+            $condition[]=array('pdc_payment_state','=',$paystate_search);
+        }
+
+        $predeposit_model = Model('predeposit');
+
+        if (!is_numeric(input('param.page'))) {
+            $count = $predeposit_model->getPdCashCount($condition);
+            $array = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $array[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $array);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $predeposit_model->getPdCashList($condition, '', '*', 'pdc_id desc', self::EXPORT_SIZE);
+                $cashpaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
+                foreach ($data as $k => $v) {
+                    $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
+                }
+                $this->createCashExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $predeposit_model->getPdCashList($condition, $limit2, '*', 'pdc_id desc');
+            $cashpaystate = array(0 => lang('admin_predeposit_rechargewaitpaying'), 1 => lang('admin_predeposit_rechargepaysuccess'));
+            foreach ($data as $k => $v) {
+                $data[$k]['pdc_payment_state'] = $cashpaystate[$v['pdc_payment_state']];
+            }
+            $this->createCashExcel($data);
+        }
+    }
+
+    /**
+     * 生成导出预存款提现excel
+     *
+     * @param array $data
+     */
+    private function createCashExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_no'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_member'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_money'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_ctime'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_state'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tx_memberid'));
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['pdc_sn']);
+            $tmp[] = array('data' => $v['pdc_member_name']);
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pdc_amount']));
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pdc_addtime']));
+            $tmp[] = array('data' => $v['pdc_payment_state']);
+            $tmp[] = array('data' => $v['pdc_member_id']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_tx_title'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_tx_title'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 预存款明细信息导出
+     */
+    public function export_mx_step1() {
+        $condition = array();
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_date ? strtotime($stime) : null;
+        $end_unixtime = $if_end_date ? strtotime($etime) : null;
+        if ($start_unixtime) {
+            $condition[] = array('lg_addtime','>=',$start_unixtime);
+        }
+        if ($end_unixtime) {
+            $end_unixtime=$end_unixtime+86399;
+            $condition[] = array('lg_addtime','<=',$end_unixtime);
+        }
+        $mname = input('get.mname');
+        if (!empty($mname)) {
+            $condition[] = array('lg_member_name','=',$mname);
+        }
+        $aname = input('get.aname');
+        if (!empty($aname)) {
+            $condition[] = array('lg_admin_name','=',$aname);
+        }
+        
+        
+        $predeposit_model = model('predeposit');
+        if (!is_numeric(input('param.page'))) {
+            $count = $predeposit_model->getPdLogCount($condition);
+            $array = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $array[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $array);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $predeposit_model->getPdLogList($condition, '', '*', 'lg_id desc', self::EXPORT_SIZE);
+                $this->createmxExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $predeposit_model->getPdLogList($condition, $limit2, '*', 'lg_id desc');
+            $this->createmxExcel($data);
+        }
+    }
+
+    /**
+     * 导出预存款明细excel
+     *
+     * @param array $data
+     */
+    private function createmxExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_member'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_ctime'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_av_money'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_freeze_money'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_system'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_mx_mshu'));
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => $v['lg_member_name']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['lg_addtime']));
+            if (floatval($v['lg_av_amount']) == 0) {
+                $tmp[] = array('data' => '');
+            } else {
+                $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['lg_av_amount']));
+            }
+            if (floatval($v['lg_freeze_amount']) == 0) {
+                $tmp[] = array('data' => '');
+            } else {
+                $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['lg_freeze_amount']));
+            }
+            $tmp[] = array('data' => $v['lg_admin_name']);
+            $tmp[] = array('data' => $v['lg_desc']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_mx_rz'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_mx_rz'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+    
+    
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'pdrecharge_list',
+                'text' => lang('pdrecharge_list'),
+                'url' => (string)url('Predeposit/pdrecharge_list')
+            ),
+            array(
+                'name' => 'pdcash_set',
+                'text' => lang('admin_predeposit_cashset'),
+                'url' => (string)url('Predeposit/pdcash_set')
+            ),
+            array(
+                'name' => 'pdcash_list',
+                'text' => lang('admin_predeposit_cashmanage'),
+                'url' => (string)url('Predeposit/pdcash_list')
+            ),
+            array(
+                'name' => 'pdlog_list',
+                'text' => lang('pdlog_list'),
+                'url' => (string)url('Predeposit/pdlog_list')
+            ),
+            array(
+                'name' => 'pd_add',
+                'text' => lang('pd_add'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Predeposit/pd_add')."','".lang('pd_add')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}
+
+?>

+ 227 - 0
app/admin/controller/Promotionbargain.php

@@ -0,0 +1,227 @@
+<?php
+
+/**
+ * 砍价管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+
+
+class Promotionbargain extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionbargain.lang.php');
+    }
+
+    /**
+     * 砍价列表
+     */
+    public function index() {
+        $bargain_model = model('pbargain');
+        $condition = array();
+        if (!empty(input('param.bargain_name'))) {
+            $condition[]=array('bargain_name','like', '%' . input('param.bargain_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if (input('param.state') != '' && in_array(input('param.state'), array(0, 1, 2, 3))) {
+            $condition[]=array('bargain_state','=',intval(input('param.state')));
+        }
+        $bargain_list = $bargain_model->getBargainList($condition, 10, 'bargain_id desc');
+        foreach ($bargain_list as $key => $val) {
+            $bargain_list[$key]['bargain_state_text'] = $bargain_model->getBargainStateText($val);
+            $bargain_list[$key] = array_merge($bargain_list[$key], $bargain_model->getBargainBtn($val));
+        }
+        View::assign('bargain_list', $bargain_list);
+        View::assign('show_page', $bargain_model->page_info->render());
+        View::assign('bargain_state_array', $bargain_model->getBargainStateArray());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('bargain_list');
+        return View::fetch();
+    }
+
+    /**
+     * 商品砍价订单列表
+     */
+    public function bargain_order() {
+        $pbargainorder_model = model('pbargainorder');
+        $bargain_id = intval(input('param.bargain_id'));
+        $condition = array();
+        $condition[] = array('bargain_id','=',$bargain_id);
+        if(input('param.bargainorder_state')!=''){
+            $condition[] = array('bargainorder_state','=',intval(input('param.bargainorder_state')));
+        }
+
+        $pbargainorder_list = $pbargainorder_model->getPbargainorderList($condition, 10); #获取开团信息
+        View::assign('show_page', $pbargainorder_model->page_info->render());
+        View::assign('pbargainorder_list', $pbargainorder_list);
+        View::assign('bargainorder_state_array', $pbargainorder_model->getBargainorderStateArray());
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('bargain_order');
+        return View::fetch();
+    }
+    /**
+     * 商品砍价记录列表
+     */
+    public function bargain_log() {
+        $pbargainlog_model = model('pbargainlog');
+        $bargainorder_id = intval(input('param.bargainorder_id'));
+        
+        $condition = array();
+        $condition[] = array('bargainorder_id','=',$bargainorder_id);
+        $pbargainlog_list = $pbargainlog_model->getPbargainlogList($condition, 10); #获取砍价记录信息
+        View::assign('show_page', $pbargainlog_model->page_info->render());
+        View::assign('pbargainlog_list', $pbargainlog_list);
+        return View::fetch();
+    }
+    
+
+    /**
+     * 砍价活动 取消
+     */
+    public function bargain_end() {
+        $bargain_id = intval(input('param.bargain_id'));
+        $pbargain_model = model('pbargain');
+
+        $bargain_info = $pbargain_model->getBargainInfoByID($bargain_id);
+        if (!$bargain_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        if(!in_array($bargain_info['bargain_state'],array(1,2))){//只有未开始、进行中的活动可以取消
+            ds_json_encode(10001, lang('bargain_cant_cancel'));
+        }
+        Db::startTrans();
+        try {
+            /**
+             * 指定砍价活动结束
+             */
+            if(!$pbargain_model->cancelBargain(array('bargain_id' => $bargain_id))){
+                throw new \think\Exception(lang('bargain_edit_fail'), 10006);
+            }
+            if($bargain_info['bargain_state']){
+                //取消用户发起的活动
+                $pbargainorder_model = model('pbargainorder');
+                $pbargainorder_model->lock=true;
+                $pbargainorder_list=$pbargainorder_model->getPbargainorderList(array('bargainorder_state'=>1,'bargain_id'=>$bargain_id));
+                if(!empty($pbargainorder_list) && !$pbargainorder_model->editPbargainorder(array('bargainorder_state'=>1,'bargain_id'=>$bargain_id), array('bargainorder_state'=>0))){
+                    throw new \think\Exception(lang('user_bargain_edit_fail'), 10006);
+                }
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            ds_json_encode(10001, $e->getMessage());
+        }
+        $this->log('砍价活动取消,活动名称:' . $bargain_info['bargain_name'] . '活动编号:' . $bargain_id, 1);
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+    /**
+     * 拼团活动 删除
+     */
+    public function bargain_del() {
+        $bargain_id = intval(input('param.bargain_id'));
+        $pbargain_model = model('pbargain');
+        $bargain_info = $pbargain_model->getBargainInfoByID($bargain_id);
+        if (!$bargain_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        /**
+         * 指定拼团活动删除
+         */
+        $result = $pbargain_model->delBargain(array('bargain_id' => $bargain_id));
+
+        if ($result) {
+            $this->log('砍价活动删除,活动名称:' . $bargain_info['bargain_name'] . '活动编号:' . $bargain_id, 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+    /**
+     * 砍价套餐管理
+     */
+    public function bargain_quota() {
+        $bargainquota_model = model('pbargainquota');
+
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $bargainquota_list = $bargainquota_model->getBargainquotaList($condition, 10, 'bargainquota_endtime desc');
+        View::assign('bargainquota_list', $bargainquota_list);
+        View::assign('show_page', $bargainquota_model->page_info->render());
+
+        $this->setAdminCurItem('bargain_quota');
+        return View::fetch();
+    }
+
+    /**
+     * 砍价设置
+     */
+    public function bargain_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $promotion_bargain_price = intval(input('post.promotion_bargain_price'));
+            if ($promotion_bargain_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_bargain_price'] = $promotion_bargain_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改砍价套餐价格为' . $promotion_bargain_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'bargain_list', 'text' => lang('bargain_list'), 'url' => (string)url('Promotionbargain/index')
+            ), array(
+                'name' => 'bargain_quota', 'text' => lang('bargain_quota'),
+                'url' => (string)url('Promotionbargain/bargain_quota')
+            ), array(
+                'name' => 'bargain_setting',
+                'text' => lang('bargain_setting'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Promotionbargain/bargain_setting') . "','" . lang('bargain_setting') . "')"
+            ),
+        );
+        if (request()->action() == 'bargain_detail') {
+            $menu_array[] = array(
+                'name' => 'bargain_detail', 'text' => lang('bargain_detail'),
+                'url' => (string)url('Promotionbargain/bargain_detail')
+            );
+        }
+
+        return $menu_array;
+    }
+
+}

+ 162 - 0
app/admin/controller/Promotionbooth.php

@@ -0,0 +1,162 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionbooth extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionbooth.lang.php');
+    }
+
+    public function index() {
+
+        //自动开启优惠套装
+        if (intval(input('param.promotion_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+        /**
+         * 处理商品分类
+         */
+        $gcid = intval(input('param.choose_gcid'));
+        $choose_gcid = $gcid > 0 ? $gcid : 0;
+        $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
+        View::assign('gc_json', json_encode($gccache_arr['showclass']));
+        View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
+
+        $pbooth_model = model('pbooth');
+        $where = array();
+        if (intval(input('param.choose_gcid')) > 0) {
+            $where=$pbooth_model->_getRecursiveClass($where,intval(input('param.choose_gcid')));
+        }
+        $goods_list = $pbooth_model->getBoothgoodsList($where, 'goods_id', 10);
+        if (!empty($goods_list)) {
+            $goodsid_array = array();
+            foreach ($goods_list as $val) {
+                $goodsid_array[] = $val['goods_id'];
+            }
+            $goods_list = model('goods')->getGoodsList(array(array('goods_id','in', $goodsid_array)));
+        }
+        View::assign('gc_list', model('goodsclass')->getGoodsclassForCacheModel());
+        View::assign('goods_list', $goods_list);
+        View::assign('show_page', $pbooth_model->page_info->render());
+
+        $this->setAdminCurItem('index');
+        // 输出自营店铺IDS
+        View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        return View::fetch();
+    }
+
+    /**
+     * 套餐列表
+     */
+    public function booth_quota() {
+        $pbooth_model = model('pbooth');
+        $where = array();
+        if (input('param.store_name') != '') {
+            $where[]=array('store_name','like', '%' . trim(input('param.store_name')) . '%');
+        }
+        $booth_list = $pbooth_model->getBoothquotaList($where, '*', 10);
+
+        // 状态数组
+        $state_array = array(0 => lang('ds_close'), 1 => lang('ds_open'));
+        View::assign('state_array', $state_array);
+
+        $this->setAdminCurItem('booth_quota');
+        View::assign('booth_list', $booth_list);
+        View::assign('show_page', $pbooth_model->page_info->render());
+        return View::fetch();
+    }
+
+    /**
+     * 删除推荐商品
+     */
+    public function del_goods() {
+        $where = array();
+        $goods_id = input('param.goods_id');
+        $goods_id_array = ds_delete_param($goods_id);
+        if ($goods_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $where[]=array('goods_id','in', $goods_id_array);
+        $rs = model('pbooth')->delBoothgoods($where);
+        if ($rs) {
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 设置
+     */
+    public function booth_setting() {
+        // 实例化模型
+        $config_model = model('config');
+
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'promotion_booth_price' => input('post.promotion_booth_price'),
+                'promotion_booth_goods_sum' => input('post.promotion_booth_goods_sum'),
+            ];
+            $promotionbooth_validate = ds_validate('promotionbooth');
+            if (!$promotionbooth_validate->scene('booth_setting')->check($data)){
+                $this->error($promotionbooth_validate->getError());
+            }
+
+            $data['promotion_booth_price'] = intval(input('post.promotion_booth_price'));
+            $data['promotion_booth_goods_sum'] = intval(input('post.promotion_booth_goods_sum'));
+
+            $return = $config_model->editConfig($data);
+            if ($return) {
+                $this->log(lang('ds_set') . ' 推荐展位');
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+            // 查询setting列表
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('goods_list'),
+                'url' => (string)url('Promotionbooth/index')
+            ), array(
+                'name' => 'booth_quota',
+                'text' => lang('booth_list'),
+                'url' => (string)url('Promotionbooth/booth_quota')
+            ), array(
+                'name' => 'booth_setting',
+                'text' => lang('ds_setting'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Promotionbooth/booth_setting') . "','".lang('ds_setting')."')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 186 - 0
app/admin/controller/Promotionbundling.php

@@ -0,0 +1,186 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionbundling extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionbundling.lang.php');
+    }
+
+
+    /**
+     * 套餐管理
+     */
+    public function bundling_quota()
+    {
+        //自动开启优惠套装
+        if (intval(input('param.promotion_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+
+        $pbundling_model = model('pbundling');
+
+        // 查询添加
+        $where = array();
+        if (input('param.store_name') != '') {
+            $where[]=array('store_name','like', '%' . trim(input('param.store_name')) . '%');
+        }
+        if (is_numeric(input('param.state'))) {
+            $where[]=array('blquota_state','=',intval(input('param.state')));
+        }
+
+        $bundlingquota_list = $pbundling_model->getBundlingQuotaList($where,10);
+        View::assign('show_page', $pbundling_model->page_info->render());
+
+        // 状态数组
+        $state_array = array(0 => lang('bundling_state_0'), 1 => lang('bundling_state_1'));
+        View::assign('state_array', $state_array);
+        $this->setAdminCurItem('bundling_quota');
+        View::assign('bundlingquota_list', $bundlingquota_list);
+        return View::fetch();
+    }
+
+
+    /**
+     * 活动管理
+     */
+    public function index()
+    {
+        $pbundling_model = model('pbundling');
+
+        // 查询添加
+        $where = '';
+        if (input('param.bundling_name') != '') {
+            $where[]=array('bl_name','like', '%' . trim(input('param.bundling_name')) . '%');
+        }
+        if (input('param.store_name') != '') {
+            $where[]=array('store_name','like', '%' . trim(input('param.store_name')) . '%');
+        }
+        if (is_numeric(input('param.state'))) {
+            $where[]=array('bl_state','=',input('param.state'));
+        }
+        $pbundling_list = $pbundling_model->getBundlingList($where,'*','bl_id desc',10);
+        $pbundling_list = array_under_reset($pbundling_list, 'bl_id');
+        View::assign('show_page', $pbundling_model->page_info->render());
+        if (!empty($pbundling_list)) {
+            $blid_array = array_keys($pbundling_list);
+            $bgoods_array = $pbundling_model->getBundlingGoodsList(array( array('bl_id','in', $blid_array)), 'bl_id,goods_id,count(*) as count', 'blgoods_appoint desc', 'bl_id');
+            $bgoods_array = array_under_reset($bgoods_array, 'bl_id');
+            foreach ($pbundling_list as $key => $val) {
+                $pbundling_list[$key]['goods_id'] = isset($bgoods_array[$val['bl_id']]['goods_id'])?$bgoods_array[$val['bl_id']]['goods_id']:'';
+                $pbundling_list[$key]['count'] = isset($bgoods_array[$val['bl_id']]['count'])?$bgoods_array[$val['bl_id']]['count']:'';
+            }
+        }
+        View::assign('pbundling_list', $pbundling_list);
+
+        // 状态数组
+        $state_array = array(0 => lang('bundling_state_0'), 1 => lang('bundling_state_1'));
+        View::assign('state_array', $state_array);
+
+
+        // 输出自营店铺IDS
+        // View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        View::assign('flippedOwnShopIds', '');
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 设置
+     */
+    public function bundling_setting()
+    {
+        // 实例化模型
+        $config_model = model('config');
+
+        if (request()->isPost()) {
+            // 验证
+            $data = [
+                'promotion_bundling_price' => input('post.promotion_bundling_price'),
+                'promotion_bundling_sum' => input('post.promotion_bundling_sum'),
+                'promotion_bundling_goods_sum' => input('post.promotion_bundling_goods_sum')
+            ];
+            $promotionbundling_validate = ds_validate('promotionbundling');
+            if (!$promotionbundling_validate->scene('bundling_setting')->check($data)){
+                $this->error($promotionbundling_validate->getError());
+            }
+
+            $data['promotion_bundling_price'] = intval(input('post.promotion_bundling_price'));
+            $data['promotion_bundling_sum'] = intval(input('post.promotion_bundling_sum'));
+            $data['promotion_bundling_goods_sum'] = intval(input('post.promotion_bundling_goods_sum'));
+
+            $return = $config_model->editConfig($data);
+            if ($return) {
+                $this->log(lang('ds_set') . lang('ds_promotion_bundling'));
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            }
+            else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        } else {
+            $this->setAdminCurItem('bundling_setting');
+            // 查询setting列表
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除套餐活动
+     */
+    public function del_bundling()
+    {
+        $bl_id = intval(input('param.bl_id'));
+        if ($bl_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $rs = model('pbundling')->delBundlingForAdmin(array('bl_id' => $bl_id));
+        if ($rs) {
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('bundling_list'), 
+                'url' => (string)url('Promotionbundling/index')
+            ), array(
+                'name' => 'bundling_quota',
+                'text' => lang('bundling_quota'),
+                'url' => (string)url('Promotionbundling/bundling_quota')
+            ), array(
+                'name' => 'bundling_setting',
+                'text' => lang('bundling_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Promotionbundling/bundling_setting')."','".lang('bundling_setting')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 214 - 0
app/admin/controller/Promotionmansong.php

@@ -0,0 +1,214 @@
+<?php
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionmansong extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionmansong.lang.php');
+    }
+
+
+    /**
+     * 活动列表
+     **/
+    public function index()
+    {
+        //自动开启满就送
+        if (intval(input('param.promotion_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+        $mansong_model = model('pmansong');
+
+        $param = array();
+        if (!empty(input('param.mansong_name'))) {
+            $param[] = array('mansong_name','like', '%' . input('param.mansong_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $param[] = array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if (!empty(input('param.state'))) {
+            $param[]=array('mansong_state','=',input('param.state'));
+        }
+        $mansong_list = $mansong_model->getMansongList($param, 10);
+        View::assign('mansong_list', $mansong_list);
+        View::assign('show_page', $mansong_model->page_info->render());
+        View::assign('mansong_state_array', $mansong_model->getMansongStateArray());
+
+
+        $this->setAdminCurItem('index');
+        // 输出自营店铺IDS
+        View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        return View::fetch();
+    }
+
+    /**
+     * 活动详细信息
+     * temp
+     **/
+    public function mansong_detail()
+    {
+        $mansong_id = intval(input('param.mansong_id'));
+
+        $mansong_model = model('pmansong');
+        $mansongrule_model = model('pmansongrule');
+
+        $mansong_info = $mansong_model->getMansongInfoByID($mansong_id);
+        if (empty($mansong_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('mansong_info', $mansong_info);
+
+        $param = array();
+        $param['mansong_id'] = $mansong_id;
+        $mansongrule_list = $mansongrule_model->getMansongruleListByID($mansong_id);
+        View::assign('mansongrule_list', $mansongrule_list);
+        $this->setAdminCurItem('mansong_detail');
+
+        return View::fetch();
+    }
+
+    /**
+     * 满即送活动取消
+     **/
+    public function mansong_cancel()
+    {
+        $mansong_id = intval(input('param.mansong_id'));
+        
+        if ($mansong_id<=0) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        
+        $mansong_model = model('pmansong');
+        $result = $mansong_model->cancelMansong(array('mansong_id' => $mansong_id));
+        if ($result) {
+            $this->log('取消满即送活动,活动编号' . $mansong_id);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 满即送活动删除
+     **/
+    public function mansong_del() {
+        $mansong_model = model('pmansong');
+        $mansong_id = input('param.mansong_id');
+        $mansong_id_array = ds_delete_param($mansong_id);
+        if($mansong_id_array === FALSE){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array(array('mansong_id','in', $mansong_id_array));
+        $result =$mansong_model->delMansong($condition);
+        if ($result) {
+            $this->log('删除满即送活动,活动编号' . implode(',', $mansong_id_array));
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+    
+
+    /**
+     * 套餐管理
+     **/
+    public function mansong_quota()
+    {
+        $mansongquota_model = model('pmansongquota');
+
+        $param = array();
+        if (!empty(input('param.store_name'))) {
+            $param[] = array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        $mansongquota_list = $mansongquota_model->getMansongquotaList($param, 10, 'mansongquota_id desc');
+        View::assign('mansongquota_list', $mansongquota_list);
+        View::assign('show_page', $mansongquota_model->page_info->render());
+        $this->setAdminCurItem('mansong_quota');
+
+        return View::fetch();
+
+    }
+
+    /**
+     * 设置
+     **/
+    public function mansong_setting()
+    {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            $this->setAdminCurItem('mansong_setting');
+            return View::fetch();
+        } else {
+            $promotion_mansong_price = intval(input('post.promotion_mansong_price'));
+            if ($promotion_mansong_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_mansong_price'] = $promotion_mansong_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_config') . lang('ds_promotion_mansong') . lang('mansong_price'));
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 页面内导航菜单
+     *
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 
+                'text' => lang('mansong_list'), 
+                'url' => (string)url('Promotionmansong/index')
+            ), array(
+                'name' => 'mansong_quota',
+                'text' => lang('mansong_quota'),
+                'url' => (string)url('Promotionmansong/mansong_quota')
+            ), array(
+                'name' => 'mansong_setting',
+                'text' => lang('mansong_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Promotionmansong/mansong_setting')."','".lang('mansong_setting')."')"
+            ),
+        );
+        if (request()->action() == 'mansong_detail') {
+            $menu_array[] = array(
+                'name' => 'mansong_detail', 'text' => lang('mansong_detail'),
+                'url' => (string)url('Promotionmansong/mansong_detail')
+            );
+        }
+        return $menu_array;
+    }
+}

+ 142 - 0
app/admin/controller/Promotionmgdiscount.php

@@ -0,0 +1,142 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionmgdiscount extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionmgdiscount.lang.php');
+        //自动开启会员等级折扣
+        if (intval(input('param.mgdiscount_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['mgdiscount_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+    }
+
+    /**
+     * 显示店铺统一设置的 会员等级折扣
+     */
+    public function mgdiscount_store() {
+        $store_model = model('store');
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
+        foreach($store_list as $key=>$store){
+            $store_list[$key]['store_mgdiscount_arr'] = $this->_get_mgdiscount_arr($store['store_mgdiscount']);
+        }
+        
+        View::assign('store_list', $store_list);
+        View::assign('show_page', $store_model->page_info->render());
+
+        $this->setAdminCurItem('mgdiscount_store');
+        return View::fetch();
+    }
+
+    /**
+     * 显示店铺针对单个商品设置的 会员等级折扣
+     */
+    public function mgdiscount_goods() {
+        $goods_model = model('goods');
+        $condition[]=array('goods_mgdiscount','<>', '');
+        $goods_list = $goods_model->getGoodsCommonOnlineList($condition);
+        foreach ($goods_list as $key => $goods) {
+            $goods_list[$key]['goods_mgdiscount_arr'] = $this->_get_mgdiscount_arr($goods['goods_mgdiscount']);
+        }
+        View::assign('show_page', $goods_model->page_info->render());
+        View::assign('goods_list', $goods_list);
+        $this->setAdminCurItem('mgdiscount_goods');
+        return View::fetch();
+    }
+    
+
+    /**
+     * 通过系统会员等级和现有数据比对得出数值
+     * @param type $mgdiscount_arr_temp
+     * @return type
+     */
+    private function _get_mgdiscount_arr($mgdiscount_arr_temp)
+    {
+        $mgdiscount_arr_temp = @unserialize($mgdiscount_arr_temp);
+
+        $member_model = model('member');
+        //系统等级设置
+        $membergrade_arr = $member_model->getMemberGradeArr();
+
+        $mgdiscount_arr = array();
+        foreach ($membergrade_arr as $key => $value) {
+            $mgdiscount_arr[$key] = $value;
+            $mgdiscount_arr[$key]['level_discount'] = isset($mgdiscount_arr_temp[$key]['level_discount'])?$mgdiscount_arr_temp[$key]['level_discount']:10;
+        }
+        return $mgdiscount_arr;
+    }
+
+    /**
+     * 会员等级设置
+     */
+    public function mgdiscount_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $mgdiscount_price = intval(input('post.mgdiscount_price'));
+            if ($mgdiscount_price < 0) {
+                $this->error(lang('param_error'));
+            }
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['mgdiscount_price'] = $mgdiscount_price;
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改会员等级折扣价格为' . $mgdiscount_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 页面内导航菜单
+     *
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'mgdiscount_store',
+                'text' => lang('mgdiscount_store'),
+                'url' => (string)url('Promotionmgdiscount/mgdiscount_store')
+            ), array(
+                'name' => 'mgdiscount_goods',
+                'text' => lang('mgdiscount_goods'),
+                'url' => (string)url('Promotionmgdiscount/mgdiscount_goods')
+            ), array(
+                'name' => 'mgdiscount_setting',
+                'text' => lang('mgdiscount_setting'),
+                'url' => "javascript:dsLayerOpen('" . (string)url('Promotionmgdiscount/mgdiscount_setting') . "','" . lang('mgdiscount_setting') . "')"
+            ),
+        );
+        return $menu_array;
+    }
+
+}

+ 202 - 0
app/admin/controller/Promotionpintuan.php

@@ -0,0 +1,202 @@
+<?php
+/**
+ * 拼团管理
+ */
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionpintuan extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionpintuan.lang.php');
+    }
+    /**
+     * 拼团列表
+     */
+    public function index()
+    {
+        $pintuan_model = model('ppintuan');
+        $condition = array();
+        if (!empty(input('param.pintuan_name'))) {
+            $condition[]=array('pintuan_name','like', '%' . input('param.pintuan_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if (input('param.state') != '') {
+            $condition[]=array('pintuan_state','=',intval(input('param.state')));
+        }
+        $pintuan_list = $pintuan_model->getPintuanList($condition, 10, 'pintuan_state desc, pintuan_end_time desc');
+        View::assign('pintuan_list', $pintuan_list);
+        View::assign('show_page', $pintuan_model->page_info->render());
+        View::assign('pintuan_state_array', $pintuan_model->getPintuanStateArray());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('pintuan_list');
+        return View::fetch();
+    }
+    /**
+     * 拼团详情
+     */
+    public function pintuan_manage()
+    {
+        $ppintuangroup_model = model('ppintuangroup');
+        $ppintuanorder_model = model('ppintuanorder');
+        $pintuan_id = intval(input('param.pintuan_id'));
+        $condition = array();
+        $condition[] = array('pintuan_id','=',$pintuan_id);
+        if (input('param.pintuangroup_state')){
+            $condition[] = array('pintuangroup_state','=',intval(input('param.pintuangroup_state')));
+        }
+        
+        $ppintuangroup_list = $ppintuangroup_model->getPpintuangroupList($condition, 10); #获取开团信息
+        foreach ($ppintuangroup_list as $key => $ppintuangroup) {
+            //获取开团订单下的参团订单
+            $condition = array();
+            $condition[] = array('pintuangroup_id','=',$ppintuangroup['pintuangroup_id']);
+            if($ppintuangroup['pintuangroup_is_virtual']){
+                $ppintuangroup_list[$key]['order_list'] = $ppintuanorder_model->getPpintuanvrorderList($condition);
+            }else{
+                $ppintuangroup_list[$key]['order_list'] = $ppintuanorder_model->getPpintuanorderList($condition);
+            }
+        }
+        $ppintuan_info = model('ppintuan')->getPintuanInfo(['pintuan_id'=>$pintuan_id]);
+        View::assign('pintuan_info', $ppintuan_info);
+        View::assign('show_page', $ppintuangroup_model->page_info->render());
+        View::assign('pintuangroup_list', $ppintuangroup_list);
+        View::assign('pintuangroup_state_array', $ppintuangroup_model->getPintuangroupStateArray());
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('pintuan_manage');
+        return View::fetch();
+    }
+    
+    /**
+     * 拼团活动 提前结束
+     */
+    public function pintuan_end() {
+        $pintuan_id = intval(input('param.pintuan_id'));
+        $ppintuan_model = model('ppintuan');
+
+        $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id);
+        if (!$pintuan_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+
+        /**
+         * 指定拼团活动结束
+         */
+        $result = $ppintuan_model->endPintuan(array('pintuan_id' => $pintuan_id));
+
+        if ($result) {
+            $this->log('拼团活动提前结束,活动名称:' . $pintuan_info['pintuan_name'] . '活动编号:' . $pintuan_id, 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+    /**
+     * 拼团活动 删除
+     */
+    public function pintuan_del() {
+        $pintuan_id = intval(input('param.pintuan_id'));
+        $ppintuan_model = model('ppintuan');
+        $pintuan_info = $ppintuan_model->getPintuanInfoByID($pintuan_id);
+        if (!$pintuan_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        /**
+         * 指定拼团活动删除
+         */
+        $result = $ppintuan_model->delPintuan(array('pintuan_id' => $pintuan_id));
+
+        if ($result) {
+            $this->log('拼团活动删除,活动名称:' . $pintuan_info['pintuan_name'] . '活动编号:' . $pintuan_id, 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+    /**
+     * 拼团套餐管理
+     */
+    public function pintuan_quota()
+    {
+        $pintuanquota_model = model('ppintuanquota');
+
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $pintuanquota_list = $pintuanquota_model->getPintuanquotaList($condition, 10, 'pintuanquota_endtime desc');
+        View::assign('pintuanquota_list', $pintuanquota_list);
+        View::assign('show_page', $pintuanquota_model->page_info->render());
+
+        $this->setAdminCurItem('pintuan_quota');
+        return View::fetch();
+    }
+    /**
+     * 拼团设置
+     */
+    public function pintuan_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $promotion_pintuan_price = intval(input('post.promotion_pintuan_price'));
+            if ($promotion_pintuan_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_pintuan_price'] = $promotion_pintuan_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改拼团套餐价格为' . $promotion_pintuan_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'pintuan_list', 'text' => lang('pintuan_list'), 'url' => (string)url('Promotionpintuan/index')
+            ), array(
+                'name' => 'pintuan_quota', 'text' => lang('pintuan_quota'),
+                'url' => (string)url('Promotionpintuan/pintuan_quota')
+            ), array(
+                'name' => 'pintuan_setting',
+                'text' => lang('pintuan_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Promotionpintuan/pintuan_setting')."','".lang('pintuan_setting')."')"
+            ),
+        );
+        if (request()->action() == 'pintuan_detail'){
+            $menu_array[] = array(
+                'name' => 'pintuan_detail', 'text' => lang('pintuan_detail'),
+                'url' => (string)url('Promotionpintuan/pintuan_detail')
+            );
+        }
+            
+        return $menu_array;
+    }
+}
+

+ 191 - 0
app/admin/controller/Promotionpresell.php

@@ -0,0 +1,191 @@
+<?php
+
+/**
+ * 预售管理
+ */
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionpresell extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/promotionpresell.lang.php');
+    }
+
+    /**
+     * 预售列表
+     */
+    public function index() {
+        $presell_model = model('presell');
+        $condition = array();
+        if (!empty(input('param.goods_name'))) {
+            $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
+        }
+        if (input('param.state') != '' && in_array(input('param.state'), array(0, 1, 2, 3))) {
+            $condition[] = array('presell_state', '=', intval(input('param.state')));
+        }
+        $presell_list = $presell_model->getPresellList($condition, 10, 'presell_id desc');
+        foreach ($presell_list as $key => $val) {
+            $presell_list[$key]['presell_state_text'] = $presell_model->getPresellStateText($val);
+            $presell_list[$key] = array_merge($presell_list[$key], $presell_model->getPresellBtn($val));
+        }
+        View::assign('presell_list', $presell_list);
+        View::assign('show_page', $presell_model->page_info->render());
+        View::assign('presell_state_array', $presell_model->getPresellStateArray());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('presell_list');
+        return View::fetch();
+    }
+
+    /**
+     * 预售活动 取消
+     */
+    public function presell_end() {
+        $presell_id = intval(input('param.presell_id'));
+        $presell_model = model('presell');
+
+        $presell_info = $presell_model->getPresellInfoByID($presell_id);
+        if (!$presell_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        if (!in_array($presell_info['presell_state'], array(1, 2))) {//只有未开始、进行中的活动可以取消
+            ds_json_encode(10001, lang('presell_cant_cancel'));
+        }
+        try {
+            Db::startTrans();
+            //取消用户发起的活动
+            $condition = array();
+            $condition[] = array('goods_type', '=', 10);
+            $condition[] = array('promotions_id', '=', $presell_id);
+            $order_ids = Db::name('ordergoods')->where($condition)->column('order_id');
+            if (!empty($order_ids)) {
+                $order_model = model('order');
+                $logic_order = model('order', 'logic');
+                $condition = array();
+                $condition[] = array('order_id', 'in', $order_ids);
+                $condition[] = array('order_state', 'in', [ORDER_STATE_NEW,ORDER_STATE_DEPOSIT, ORDER_STATE_REST,ORDER_STATE_PAY]);
+                $order_list = $order_model->getOrderList($condition);
+                if (!empty($order_list)) {
+                    foreach ($order_list as $order_info) {
+                        $logic_order->changeOrderStateCancel($order_info, 'admin', $this->admin_info['admin_name'], '管理员取消预售活动');
+                    }
+                }
+            }
+            if (!$presell_model->cancelPresell(array('presell_id' => $presell_id))) {
+                throw new \think\Exception(lang('presell_edit_fail'), 10006);
+            }
+        } catch (\Exception $e) {
+            Db::rollback();
+            ds_json_encode(10001, $e->getMessage());
+        }
+        Db::commit();
+
+        $this->log('预售活动取消,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
+        ds_json_encode(10000, lang('ds_common_op_succ'));
+    }
+    /**
+     * 拼团活动 删除
+     */
+    public function presell_del() {
+        $presell_id = intval(input('param.presell_id'));
+        $presell_model = model('presell');
+        $presell_info = $presell_model->getPresellInfoByID($presell_id);
+        if (!$presell_info) {
+            ds_json_encode(10001, lang('param_error'));
+        }
+        /**
+         * 指定拼团活动删除
+         */
+        $result = $presell_model->delPresell(array('presell_id' => $presell_id));
+
+        if ($result) {
+            $this->log('预售活动删除,商品名称:' . $presell_info['goods_name'] . '活动编号:' . $presell_id, 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+    /**
+     * 预售套餐管理
+     */
+    public function presell_quota() {
+        $presellquota_model = model('presellquota');
+
+        $condition = array();
+        $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
+        $presellquota_list = $presellquota_model->getPresellquotaList($condition, 10, 'presellquota_endtime desc');
+        View::assign('presellquota_list', $presellquota_list);
+        View::assign('show_page', $presellquota_model->page_info->render());
+
+        $this->setAdminCurItem('presell_quota');
+        return View::fetch();
+    }
+
+    /**
+     * 预售设置
+     */
+    public function presell_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $promotion_presell_price = intval(input('post.promotion_presell_price'));
+            if ($promotion_presell_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_presell_price'] = $promotion_presell_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改预售套餐价格为' . $promotion_presell_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'presell_list', 'text' => lang('presell_list'), 'url' => (string) url('Promotionpresell/index')
+            ), array(
+                'name' => 'presell_quota', 'text' => lang('presell_quota'),
+                'url' => (string) url('Promotionpresell/presell_quota')
+            ), array(
+                'name' => 'presell_setting',
+                'text' => lang('presell_setting'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Promotionpresell/presell_setting') . "','" . lang('presell_setting') . "')"
+            ),
+        );
+
+        return $menu_array;
+    }
+
+}

+ 251 - 0
app/admin/controller/Promotionwholesale.php

@@ -0,0 +1,251 @@
+<?php
+/**
+ * 批发
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionwholesale extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionwholesale.lang.php');
+    }
+
+
+    /**
+     * 活动列表
+     **/
+    public function index()
+    {
+        //自动开启批发
+        if (intval(input('param.promotion_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+
+        $wholesale_model = model('wholesale');
+        $condition = array();
+        if (!empty(input('param.goods_name'))) {
+            $condition[]=array('goods_name','like', '%' . input('param.goods_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if (!empty(input('param.state'))) {
+            $condition[]=array('wholesale_state','=',intval(input('param.state')));
+        }
+        $wholesale_list = $wholesale_model->getWholesaleList($condition, 10, 'wholesale_state desc, wholesale_end_time desc');
+        View::assign('wholesale_list', $wholesale_list);
+        View::assign('show_page', $wholesale_model->page_info->render());
+        View::assign('wholesale_state_array', $wholesale_model->getWholesaleStateArray());
+
+        $this->setAdminCurItem('wholesale_list');
+        // 输出自营店铺IDS
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        return View::fetch();
+    }
+
+    /**
+     * 批发活动取消
+     **/
+    public function wholesale_cancel()
+    {
+        $wholesale_id = intval(input('param.wholesale_id'));
+        $wholesale_model = model('wholesale');
+        $result = $wholesale_model->cancelWholesale(array('wholesale_id' => $wholesale_id));
+        if ($result) {
+            $this->log(lang('ds_cancel').lang('ds_promotion_wholesale').'ID:' . $wholesale_id);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 批发活动删除
+     **/
+    public function wholesale_del()
+    {
+        $wholesale_model = model('wholesale');
+        $wholesale_id = input('param.wholesale_id');
+        $wholesale_id_array = ds_delete_param($wholesale_id);
+        if($wholesale_id_array === FALSE){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array(array('wholesale_id' ,'in', $wholesale_id_array));
+        $result = $wholesale_model->delWholesale($condition);
+        if ($result) {
+            $this->log(lang('ds_del').lang('ds_promotion_wholesale').'ID:' . $wholesale_id);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 活动详细信息
+     **/
+    public function wholesale_detail()
+    {
+        $wholesale_id = intval(input('param.wholesale_id'));
+
+        $wholesale_model = model('wholesale');
+        $wholesalegoods_model = model('wholesalegoods');
+
+        $wholesale_info = $wholesale_model->getWholesaleInfoByID($wholesale_id);
+        if (empty($wholesale_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('wholesale_info', $wholesale_info);
+
+        //获取批发商品列表
+        $condition = array();
+        $condition[] = array('wholesale_id','=',$wholesale_id);
+        $wholesalegoods_list = $wholesalegoods_model->getWholesalegoodsExtendList($condition,5);
+        View::assign('wholesalegoods_list', $wholesalegoods_list);
+        View::assign('show_page',$wholesalegoods_model->page_info->render());
+        return View::fetch();
+    }
+
+    /**
+     * 套餐管理
+     **/
+    public function wholesale_quota()
+    {
+        $wholesalequota_model = model('wholesalequota');
+
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $wholesalequota_list = $wholesalequota_model->getWholesalequotaList($condition, 10, 'wholesalequota_endtime desc');
+        View::assign('wholesalequota_list', $wholesalequota_list);
+        View::assign('show_page', $wholesalequota_model->page_info->render());
+
+        $this->setAdminCurItem('wholesale_quota');
+        return View::fetch();
+
+    }
+
+    /**
+     * 设置
+     **/
+   public function wholesale_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $promotion_wholesale_price = intval(input('post.promotion_wholesale_price'));
+            if ($promotion_wholesale_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_wholesale_price'] = $promotion_wholesale_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改批发价格为' . $promotion_wholesale_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * ajax修改抢购信息
+     */
+    public function ajax()
+    {
+        $result = true;
+        $update_array = array();
+        $condition = array();
+
+        switch (input('param.branch')) {
+            case 'recommend':
+                $wholesalegoods_model = model('wholesalegoods');
+                $update_array['wholesalegoods_recommend'] = input('param.value');
+                $condition[] = array('wholesalegoods_id','=',input('param.id'));
+                $result = $wholesalegoods_model->editWholesalegoods($update_array, $condition);
+                break;
+        }
+
+        if ($result) {
+            echo 'true';
+            exit;
+        }
+        else {
+            echo 'false';
+            exit;
+        }
+
+    }
+
+
+    /*
+     * 发送消息
+     */
+    private function send_message($member_id, $member_name, $message)
+    {
+        $param = array();
+        $param['from_member_id'] = 0;
+        $param['member_id'] = $member_id;
+        $param['to_member_name'] = $member_name;
+        $param['message_type'] = '1';//表示为系统消息
+        $param['msg_content'] = $message;
+        $message_model = model('message');
+        return $message_model->addMessage($param);
+    }
+
+    /**
+     * 页面内导航菜单
+     *
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'wholesale_list', 'text' => lang('wholesale_list'), 'url' => (string)url('Promotionwholesale/index')
+            ), array(
+                'name' => 'wholesale_quota', 'text' => lang('wholesale_quota'),
+                'url' => (string)url('Promotionwholesale/wholesale_quota')
+            ), array(
+                'name' => 'wholesale_setting',
+                'text' => lang('wholesale_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Promotionwholesale/wholesale_setting')."','".lang('wholesale_setting')."')"
+            ),
+        );
+        if (request()->action() == 'wholesale_detail')
+            $menu_array[] = array(
+                'name' => 'wholesale_detail', 'text' => lang('wholesale_detail'),
+                'url' => (string)url('Promotionwholesale/wholesale_detail')
+            );
+        return $menu_array;
+    }
+}

+ 252 - 0
app/admin/controller/Promotionxianshi.php

@@ -0,0 +1,252 @@
+<?php
+/**
+ * 秒杀
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Promotionxianshi extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/promotionxianshi.lang.php');
+    }
+
+
+    /**
+     * 活动列表
+     **/
+    public function index()
+    {
+        //自动开启秒杀
+        if (intval(input('param.promotion_allow')) === 1) {
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_allow'] = 1;
+            $config_model->editConfig($update_array);
+        }
+
+        $xianshi_model = model('pxianshi');
+        $condition = array();
+        if (!empty(input('param.xianshi_name'))) {
+            $condition[]=array('xianshi_name','like', '%' . input('param.xianshi_name') . '%');
+        }
+        if (!empty(input('param.store_name'))) {
+            $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        }
+        if (!empty(input('param.state'))) {
+            $condition[]=array('xianshi_state','=',intval(input('param.state')));
+        }
+        $xianshi_list = $xianshi_model->getXianshiList($condition, 10, Db::raw('FIELD(xianshi_state, 1,0,2,3), xianshi_end_time desc'));
+        View::assign('xianshi_list', $xianshi_list);
+        View::assign('show_page', $xianshi_model->page_info->render());
+        View::assign('xianshi_state_array', $xianshi_model->getXianshiStateArray());
+
+        $this->setAdminCurItem('xianshi_list');
+        // 输出自营店铺IDS
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        View::assign('flippedOwnShopIds', array_flip(model('store')->getOwnShopIds()));
+        return View::fetch();
+    }
+
+    /**
+     * 秒杀活动取消
+     **/
+    public function xianshi_cancel()
+    {
+        $xianshi_id = intval(input('param.xianshi_id'));
+        $xianshi_model = model('pxianshi');
+        $result = $xianshi_model->cancelXianshi(array('xianshi_id' => $xianshi_id));
+        if ($result) {
+            $this->log('取消秒杀活动,活动编号' . $xianshi_id);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 秒杀活动删除
+     **/
+    public function xianshi_del()
+    {
+        $xianshi_model = model('pxianshi');
+        $xianshi_id = input('param.xianshi_id');
+        $xianshi_id_array = ds_delete_param($xianshi_id);
+        if($xianshi_id_array === FALSE){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array(array('xianshi_id' ,'in', $xianshi_id_array));
+        $result = $xianshi_model->delXianshi($condition);
+        if ($result) {
+            $this->log('删除秒杀活动,活动编号' . $xianshi_id);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        }
+        else {
+            ds_json_encode(10001, lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 活动详细信息
+     **/
+    public function xianshi_detail()
+    {
+        $xianshi_id = intval(input('param.xianshi_id'));
+
+        $xianshi_model = model('pxianshi');
+        $xianshigoods_model = model('pxianshigoods');
+
+        $xianshi_info = $xianshi_model->getXianshiInfoByID($xianshi_id);
+        if (empty($xianshi_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('xianshi_info', $xianshi_info);
+
+        //获取秒杀商品列表
+        $condition = array();
+        $condition[] = array('xianshi_id','=',$xianshi_id);
+        $xianshigoods_list = $xianshigoods_model->getXianshigoodsExtendList($condition,5);
+        View::assign('xianshigoods_list', $xianshigoods_list);
+        View::assign('show_page',$xianshigoods_model->page_info->render());
+        return View::fetch();
+    }
+
+    /**
+     * 套餐管理
+     **/
+    public function xianshi_quota()
+    {
+        $xianshiquota_model = model('pxianshiquota');
+
+        $condition = array();
+        $condition[]=array('store_name','like', '%' . input('param.store_name') . '%');
+        $xianshiquota_list = $xianshiquota_model->getXianshiquotaList($condition, 10, 'xianshiquota_endtime desc');
+        View::assign('xianshiquota_list', $xianshiquota_list);
+        View::assign('show_page', $xianshiquota_model->page_info->render());
+
+        $this->setAdminCurItem('xianshi_quota');
+        return View::fetch();
+
+    }
+
+    /**
+     * 设置
+     **/
+   public function xianshi_setting() {
+        if (!(request()->isPost())) {
+            $setting = rkcache('config', true);
+            View::assign('setting', $setting);
+            return View::fetch();
+        } else {
+            $promotion_xianshi_price = intval(input('post.promotion_xianshi_price'));
+            if ($promotion_xianshi_price < 0) {
+                $this->error(lang('param_error'));
+            }
+
+            $config_model = model('config');
+            $update_array = array();
+            $update_array['promotion_xianshi_price'] = $promotion_xianshi_price;
+
+            $result = $config_model->editConfig($update_array);
+            if ($result) {
+                $this->log('修改秒杀价格为' . $promotion_xianshi_price . '元');
+                dsLayerOpenSuccess(lang('setting_save_success'));
+            } else {
+                $this->error(lang('setting_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * ajax修改抢购信息
+     */
+    public function ajax()
+    {
+        $result = true;
+        $update_array = array();
+        $condition = array();
+
+        switch (input('param.branch')) {
+            case 'recommend':
+                $pxianshigoods_model = model('pxianshigoods');
+                $update_array['xianshigoods_recommend'] = input('param.value');
+                $condition[] = array('xianshigoods_id','=',input('param.id'));
+                $result = $pxianshigoods_model->editXianshigoods($update_array, $condition);
+                break;
+        }
+
+        if ($result) {
+            echo 'true';
+            exit;
+        }
+        else {
+            echo 'false';
+            exit;
+        }
+
+    }
+
+
+    /*
+     * 发送消息
+     */
+    private function send_message($member_id, $member_name, $message)
+    {
+        $param = array();
+        $param['from_member_id'] = 0;
+        $param['member_id'] = $member_id;
+        $param['to_member_name'] = $member_name;
+        $param['message_type'] = '1';//表示为系统消息
+        $param['msg_content'] = $message;
+        $message_model = model('message');
+        return $message_model->addMessage($param);
+    }
+
+    /**
+     * 页面内导航菜单
+     *
+     * @param string $menu_key 当前导航的menu_key
+     * @param array $array 附加菜单
+     * @return
+     */
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'xianshi_list', 'text' => lang('xianshi_list'), 'url' => (string)url('Promotionxianshi/index')
+            ), array(
+                'name' => 'xianshi_quota', 'text' => lang('xianshi_quota'),
+                'url' => (string)url('Promotionxianshi/xianshi_quota')
+            ), array(
+                'name' => 'xianshi_setting',
+                'text' => lang('xianshi_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Promotionxianshi/xianshi_setting')."','".lang('xianshi_setting')."')"
+            ),
+        );
+        if (request()->action() == 'xianshi_detail')
+            $menu_array[] = array(
+                'name' => 'xianshi_detail', 'text' => lang('xianshi_detail'),
+                'url' => (string)url('Promotionxianshi/xianshi_detail')
+            );
+        return $menu_array;
+    }
+}

+ 303 - 0
app/admin/controller/Rechargecard.php

@@ -0,0 +1,303 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Rechargecard extends AdminControl
+{
+    const EXPORT_SIZE = 100;
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/rechargecard.lang.php');
+    }
+
+    public function index()
+    {
+        $rechargecard_model = model('rechargecard');
+        $condition = array();
+
+        if (request()->isGet()) {
+            $sn = trim((string)input('param.sn'));
+            $batchflag = trim((string)input('param.batchflag'));
+            $state = input('param.state');
+            if (strlen($sn) > 0) {
+                $condition[]=array('rc_sn','like', "%{$sn}%");
+            }
+
+            if (strlen($batchflag) > 0) {
+                $condition[]=array('rc_batchflag','like', "%{$batchflag}%");
+            }
+
+            if ($state == '0' || $state == '1') {
+                $condition[]=array('rc_state','=',$state);
+            }
+        }
+
+        $cardList = $rechargecard_model->getRechargecardList($condition, 20);
+
+        View::assign('card_list', $cardList);
+        View::assign('show_page', $rechargecard_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function add_card()
+    {
+        if (!request()->isPost()) {
+            return View::fetch();
+        }
+        else {
+            $denomination = (float)input('post.denomination');
+            if ($denomination < 0.01) {
+                $this->error(lang('rechargecard_denomination_min'));
+            }
+            if ($denomination > 1000) {
+                $this->error(lang('rechargecard_denomination_max'));
+            }
+
+            $snKeys = array();
+
+            switch (input('post.type')) {
+                case '0':
+                    $total = (int)input('post.total');
+                    if ($total < 1 || $total > 5000) {
+                        $this->error(lang('r0total_message'));
+                    }
+                    $prefix = (string)input('post.prefix');
+                    if (!preg_match('/^[0-9a-zA-Z]{0,16}$/', $prefix)) {
+                        $this->error(lang('r0prefix_message'));
+                    }
+                    while (count($snKeys) < $total) {
+                        $snKeys[$prefix . md5(uniqid(mt_rand(), true))] = null;
+                    }
+                    break;
+
+                case '1':
+                    $f = $_FILES['_textfile'];
+                    if (!$f || $f['error'] != 0) {
+                        $this->error(lang('file_upload_fail'));
+                    }
+                    if (!is_uploaded_file($f['tmp_name'])) {
+                        $this->error(lang('file_empty'));
+                    }
+                    foreach (file($f['tmp_name']) as $sn) {
+                        $sn = trim($sn);
+                        if (preg_match('/^[0-9a-zA-Z]{1,50}$/', $sn))
+                            $snKeys[$sn] = null;
+                    }
+                    break;
+
+                case '2':
+                    foreach (explode("\n", (string)input('post.manual')) as $sn) {
+                        $sn = trim($sn);
+                        if (preg_match('/^[0-9a-zA-Z]{1,50}$/', $sn))
+                            $snKeys[$sn] = null;
+                    }
+                    break;
+
+                default:
+                    $this->error(lang('param_error'));
+                    exit;
+            }
+
+            $totalKeys = count($snKeys);
+            if ($totalKeys < 1 || $totalKeys > 9999) {
+                $this->error(lang('recharge_number_error'));
+            }
+
+            if (empty($snKeys)) {
+                $this->error(lang('recharge_number_invalid'));
+            }
+
+            $snOccupied = 0;
+            $rechargecard_model = model('rechargecard');
+
+            // chunk size = 50
+            foreach (array_chunk(array_keys($snKeys), 50) as $snValues) {
+                foreach ($rechargecard_model->getOccupiedRechargecardSNsBySNs($snValues) as $sn) {
+                    $snOccupied++;
+                    unset($snKeys[$sn]);
+                }
+            }
+
+            if (empty($snKeys)) {
+                $this->error(lang('recharge_number_exist'));
+            }
+
+            $batchflag = input('post.batchflag');
+            $adminName = $this->admin_info['admin_name'];
+            $ts = TIMESTAMP;
+
+            $snToInsert = array();
+            foreach (array_keys($snKeys) as $sn) {
+                $snToInsert[] = array(
+                    'rc_sn' => $sn, 'rc_denomination' => $denomination, 'rc_batchflag' => $batchflag, 'rc_admin_name' => $adminName,
+                    'rc_tscreated' => $ts,
+                );
+            }
+
+            if (!$rechargecard_model->addRechargecardAll($snToInsert)) {
+                $this->error(lang('ds_common_op_fail'));
+            }
+
+            $countInsert = count($snToInsert);
+            $this->log("新增{$countInsert}张充值卡(面额¥{$denomination},批次标识“{$batchflag}”)");
+
+            $msg = lang('ds_common_op_succ');
+            if ($snOccupied > 0)
+                $msg .= sprintf(lang('rechargecard_number_exist_error'),$snOccupied);
+
+            dsLayerOpenSuccess($msg);
+        }
+    }
+
+
+    /**
+     * 删除平台充值卡
+     */
+    public function del_card() {
+        $rechargecard_model= model('rechargecard');
+        $rc_id = input('param.rc_id');
+        $rc_id_array = ds_delete_param($rc_id);
+        if($rc_id_array === FALSE){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array(array('rc_id','in', $rc_id_array));
+        $condition[]=array('rc_state','=',0);
+        $result =$rechargecard_model->delRechargecard($condition);
+        if ($result) {
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+
+
+    /**
+     * 导出
+     */
+    public function export_step1()
+    {
+        $rechargecard_model = model('rechargecard');
+        $condition = array();
+
+        if (request()->isPost()) {
+            $sn = trim((string)input('param.sn'));
+            $batchflag = trim((string)input('param.batchflag'));
+            $state = trim((string)input('param.state'));
+
+            if (strlen($sn) > 0) {
+                $condition[]=array('rc_sn','like', "%{$sn}%");
+                View::assign('sn', $sn);
+            }
+
+            if (strlen($batchflag) > 0) {
+                $condition[]=array('rc_batchflag','like', "%{$batchflag}%");
+                View::assign('batchflag', $batchflag);
+            }
+
+            if ($state === '0' || $state === '1') {
+                $condition[]=array('rc_state','=',$state);
+                View::assign('state', $state);
+            }
+        }
+
+        if (!is_numeric(input('param.page'))) {
+            $count = $rechargecard_model->getRechargecardCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) {    //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[]=array($i,'=',$limit1 . ' ~ ' . $limit2);
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            }
+            else {    //如果数量小,直接下载
+                $data = $rechargecard_model->getRechargecardList($condition, 0,self::EXPORT_SIZE);
+
+                $this->createExcel($data);
+            }
+        }
+        else {    //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+
+            $data = $rechargecard_model->getRechargecardList($condition, $limit2);
+
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array())
+    {
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array(
+                                 'id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')
+                             ));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('rc_sn'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('rc_batchflag'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('rc_denomination'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('rc_admin_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('rc_tscreated'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('receive_user'));
+
+        //data
+        foreach ((array)$data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => "\t" . $v['rc_sn']);
+            $tmp[] = array('data' => "\t" . $v['rc_batchflag']);
+            $tmp[] = array('data' => "\t" . $v['rc_denomination']);
+            $tmp[] = array('data' => "\t" . $v['rc_admin_name']);
+            $tmp[] = array('data' => "\t" . date('Y-m-d H:i:s', $v['rc_tscreated']));
+            if ($v['rc_state'] == 1 && $v['member_id'] > 0 && $v['rc_tsused'] > 0) {
+                $tmp[] = array('data' => "\t" . $v['member_name']);
+            }
+            else {
+                $tmp[] = array('data' => "\t-");
+            }
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('rechargecard'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('rechargecard'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('ds_list'), 'url' => (string)url('Rechargecard/index')
+            ), array(
+                'name' => 'add_card', 'text' => lang('ds_new'),'url' => "javascript:dsLayerOpen('" . (string)url('Rechargecard/add_card') . "','".lang('ds_new')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}

+ 461 - 0
app/admin/controller/Refund.php

@@ -0,0 +1,461 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Refund extends AdminControl
+{
+    const EXPORT_SIZE = 1000;
+    public function initialize()
+    {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/refund.lang.php');
+        //向模板页面输出退款退货状态
+        $this->getRefundStateArray();
+    }
+
+    function getRefundStateArray($type = 'all')
+    {
+        $state_array = array(
+            '1' => lang('refund_state_confirm'), '2' => lang('refund_state_yes'), '3' => lang('refund_state_no')
+        ); //卖家处理状态:1为待审核,2为同意,3为不同意
+        View::assign('state_array', $state_array);
+
+        $admin_array = array(
+            '1' => lang('admin_state_1'), '2' => lang('admin_state_2'), '3' => lang('admin_state_3'), '4' => lang('refund_state_no')
+        ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
+        View::assign('admin_array', $admin_array);
+
+        $state_data = array(
+            'seller' => $state_array, 'admin' => $admin_array
+        );
+        if ($type == 'all') {
+            return $state_data; //返回所有
+        }
+        return $state_data[$type];
+    }
+
+    /**
+     * 待处理列表
+     */
+    public function refund_manage()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[]=array('refund_type','=',1);
+        $condition[]=array('refund_state','=','2'); //状态:1为处理中,2为待管理员处理,3为已完成
+
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        $refund_list = $refundreturn_model->getRefundList($condition, 10);
+        View::assign('show_page', $refundreturn_model->page_info->render());
+        View::assign('refund_list', $refund_list);
+        $this->setAdminCurItem('refund_manage');
+        return View::fetch('refund_manage');
+    }
+
+    /**
+     * 所有记录
+     */
+    public function refund_all()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[]=array('refund_type','=',1);
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        $refund_list = $refundreturn_model->getRefundList($condition, 10);
+        View::assign('show_page', $refundreturn_model->page_info->render());
+        View::assign('refund_list', $refund_list);
+        $this->setAdminCurItem('refund_all');
+        return View::fetch('refund_all');
+    }
+
+    /**
+     * 退款处理页
+     *
+     */
+    public function edit()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[] = array('refund_id','=',intval(input('param.refund_id')));
+        $refund_list = $refundreturn_model->getRefundList(array_merge($condition,array(array('refund_type','=',1))));
+        $refund = $refund_list[0];
+        //查询交易凭证
+        $order_model = model('order');
+        $order = $order_model->getOrderInfo(array('order_id' => $refund['order_id']));
+        if (request()->isPost()) {
+            if(!in_array(input('post.refund_state'),[3,4])){
+              $this->error(lang('refund_state_null'));
+            }
+            $check = request()->checkToken('__token__');
+            if(false === $check) {
+                $this->error('invalid token');
+            }
+            if ($refund['refund_state'] != '2') {//检查状态,防止页面刷新不及时造成数据错误
+                $this->error(lang('ds_common_save_fail'));
+            }
+            $order_id = $refund['order_id'];
+            $refund_array = array();
+            $refund_array['admin_time'] = TIMESTAMP;
+            $refund_array['refund_state'] = '4'; //状态:1为处理中,2为待管理员处理,3为已完成
+            $refund_array['admin_message'] = input('post.admin_message');
+            if (input('post.refund_state') == '3') {
+                $trade_no=input('param.trade_no');
+                if($trade_no && $trade_no!=$order['trade_no']){
+                    $order_model->editOrder(array('trade_no'=>$trade_no), array(
+                    'order_id' => $order['order_id']
+                    ));
+                    //添加订单日志
+                    $data = array();
+                    $data['order_id'] = $order['order_id'];
+                    $data['log_role'] = 'system';
+                    $data['log_user'] = $this->admin_info['admin_name'];
+                    $data['log_msg'] = '修改支付平台交易号 : ' . $trade_no;
+                    $data['log_orderstate'] = $order['order_state'];
+                    $order_model->addOrderlog($data);
+                }
+                $refund_array['refund_state'] = '3';
+                $res = $refundreturn_model->editOrderRefund($refund);
+                $state=$res['code'];
+                if(!$state){
+                    $this->error($res['msg']);
+                }
+            }else{
+                if($refund['order_lock'] == '2'){
+                    $state = $refundreturn_model->editOrderUnlock($order_id); //订单解锁
+                }else{
+                    $state = true;
+                }
+                //自提点订单解锁
+                $chain_order_model=model('chain_order');
+                $chain_order_model->editChainOrderUnlock($order_id);
+            }
+            
+            if ($state) {
+                $refundreturn_model->editRefundreturn($condition, $refund_array);
+
+                // 发送买家消息
+                $param = array();
+                $param['code'] = 'refund_return_notice';
+                $param['member_id'] = $refund['buyer_id'];
+                //阿里短信参数
+                $param['ali_param'] = array(
+                    'refund_sn' => $refund['refund_sn']
+                );
+                $param['ten_param'] = array(
+                    $refund['refund_sn']
+                );
+                $param['param'] = array_merge($param['ali_param'],array(
+                    'refund_url' => HOME_SITE_URL .'/memberrefund/view?refund_id='.$refund['refund_id'],
+                ));
+                //微信模板消息
+                $param['weixin_param'] = array(
+                    'url' => config('ds_config.h5_site_url').'/member/refund_view?refund_id='.$refund['refund_id'],
+                    'data'=>array(
+                        "keyword1" => array(
+                            "value" => $refund['order_sn'],
+                            "color" => "#333"
+                        ),
+                        "keyword2" => array(
+                            "value" => $refund['refund_amount'],
+                            "color" => "#333"
+                        )
+                    ),
+                );
+                model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
+              
+                $this->log('退款确认,退款编号' . $refund['refund_sn']);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+            else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        View::assign('trade_no', $order['trade_no']);
+        View::assign('refund', $refund);
+        $info['buyer'] = array();
+        if (!empty($refund['pic_info'])) {
+            $info = unserialize($refund['pic_info']);
+        }
+        View::assign('pic_list', $info['buyer']);
+        return View::fetch('edit');
+    }
+
+    /**
+     * 退款记录查看页
+     *
+     */
+    public function view()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[]=array('refund_id','=',intval(input('param.refund_id')));
+        $condition[] =array('refund_type','=',1);
+        $refund_list = $refundreturn_model->getRefundList($condition);
+        $refund = $refund_list[0];
+        View::assign('refund', $refund);
+        $info['buyer'] = array();
+        if (!empty($refund['pic_info'])) {
+            $info = unserialize($refund['pic_info']);
+        }
+        View::assign('pic_list', $info['buyer']);
+        return View::fetch('view');
+    }
+
+    /**
+     * 退款退货原因
+     */
+    public function reason()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $reason_list = $refundreturn_model->getReasonList($condition, 10);
+        View::assign('reason_list', $reason_list);
+        View::assign('show_page', $refundreturn_model->page_info->render());
+
+        $this->setAdminCurItem('reason');
+        return View::fetch('reason');
+    }
+
+    /**
+     * 新增退款退货原因
+     */
+    public function add_reason()
+    {
+        $refundreturn_model = model('refundreturn');
+        if (request()->post()) {
+            $reason_array = array();
+            $reason_array['reason_info'] = input('post.reason_info');
+            $reason_array['reason_sort'] = intval(input('post.reason_sort'));
+            $reason_array['reason_updatetime'] = TIMESTAMP;
+
+            $state = $refundreturn_model->addReason($reason_array);
+            if ($state) {
+                $this->log('新增退款退货原因,编号' . $state);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+            else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        return View::fetch('add_reason');
+    }
+
+    /**
+     * 编辑退款退货原因
+     *
+     */
+    public function edit_reason()
+    {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $reason_id = intval(input('param.reason_id'));
+        $condition[] = array('reason_id','=',$reason_id);
+        $reason_list = $refundreturn_model->getReasonList($condition);
+        $reason = $reason_list[$reason_id];
+        if (request()->post()) {
+            $reason_array = array();
+            $reason_array['reason_info'] = input('post.reason_info');
+            $reason_array['reason_sort'] = intval(input('post.reason_sort'));
+            $reason_array['reason_updatetime'] = TIMESTAMP;
+            $state = $refundreturn_model->editReason($condition, $reason_array);
+            if ($state) {
+                $this->log('编辑退款退货原因,编号' . $reason_id);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            }
+            else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        View::assign('reason', $reason);
+        return View::fetch('edit_reason');
+    }
+
+    /**
+     * 删除退款退货原因
+     *
+     */
+    public function del_reason()
+    {
+        $refundreturn_model = model('refundreturn');
+        $reason_id = input('param.reason_id');
+        $reason_id_array = ds_delete_param($reason_id);
+        if($reason_id_array === FALSE){
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array(array('reason_id','in', $reason_id_array));
+        $state = $refundreturn_model->delReason($condition);
+        if ($state) {
+            $this->log('删除退款退货原因,编号' . $reason_id);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        }
+        else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 导出
+     *
+     */
+    public function export_step1() {
+
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        if (!is_numeric(input('param.page'))) {
+            $count = $refundreturn_model->getRefundCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $refundreturn_model->getRefundList(array_merge($condition,array(array('refund_type','=',1))), '', '*', 'refund_id desc', self::EXPORT_SIZE);
+                $this->createExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $refundreturn_model->getRefundList(array_merge($condition,array(array('refund_type','=',1))), $limit2, '*', 'refund_id desc');
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_order_sn'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_refund_sn'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_store_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_goods_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_buyer_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tk_order_add_time'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_tk_order_refund'));
+        //data
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => 'DS' . $v['order_sn']);
+            $tmp[] = array('data' => $v['refund_sn']);
+            $tmp[] = array('data' => $v['store_name']);
+            $tmp[] = array('data' => $v['goods_name']);
+            $tmp[] = array('data' => $v['buyer_name']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['refund_amount']));
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_tk_refund'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_tk_refund'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'refund_manage', 'text' => lang('admin_state_2'), 'url' => (string)url('Refund/refund_manage')
+            ), array(
+                'name' => 'refund_all', 'text' => lang('refund_all'), 'url' => (string)url('Refund/refund_all')
+            ), array(
+                'name' => 'reason', 'text' => lang('refund_return_reason'), 'url' => (string)url('Refund/reason')
+            ),
+        );
+        if (request()->action() == 'reason') {
+            $menu_array[] = [
+                'name' => 'add_reason', 'text' => lang('add_reason'), 'url' =>"javascript:dsLayerOpen('".(string)url('Refund/add_reason')."','".lang('add_reason')."')"
+            ];
+        }
+        return $menu_array;
+    }
+}
+
+?>

+ 340 - 0
app/admin/controller/Region.php

@@ -0,0 +1,340 @@
+<?php
+
+/**
+ * 地区设置
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Region extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/region.lang.php');
+        $this->_area_model = model('Area');
+        define('MAX_LAYER', 3);
+    }
+
+    public function index() {
+        $region_list = $this->_area_model->getAreaChild(0);
+        /* 先根排序 */
+        foreach ($region_list as $key => $val) {
+            $region_list[$key]['switchs'] = 0;
+            if ($this->_area_model->getAreaChild($val['area_id'])) {
+                $region_list[$key]['switchs'] = 1;
+            }
+        }
+        View::assign('region_list', $region_list);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    function ajax_cate() {
+        $cate_id = input('param.id');
+        if (empty($cate_id)) {
+            return;
+        }
+
+        $cate = $this->_area_model->getAreaChild($cate_id);
+        foreach ($cate as $key => $val) {
+            $child = $this->_area_model->getAreaChild($val['area_id']);
+            if ($val['area_deep'] >= MAX_LAYER) {
+                $cate[$key]['add_child'] = 0;
+            } else {
+                $cate[$key]['add_child'] = 1;
+            }
+            if (!$child || empty($child)) {
+                $cate[$key]['switchs'] = 0;
+            } else {
+                $cate[$key]['switchs'] = 1;
+            }
+        }
+        echo json_encode(array_values($cate));
+        return;
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $condition = array();
+        switch (input('param.branch')) {
+            /**
+             * 更新地区
+             */
+            case 'area_name':
+                $area_model = model('area');
+                $condition[] = array('area_id','=',intval(input('get.id')));
+                $update_array = array();
+                $update_array['area_name'] = addslashes(trim(input('get.value')));
+                $area_model->editArea($update_array, $condition);
+
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaPhp();
+                \areacache::updateAreaArrayJs();
+                echo 'true';
+                exit;
+
+                break;
+            /**
+             * 地区 排序 显示 设置
+             */
+            case 'area_sort':
+                $area_model = model('area');
+                $condition[] = array('area_id','=',intval(input('get.id')));
+                $update_array = array();
+                $update_array['area_sort'] = trim(input('get.value'));
+                $area_model->editArea($update_array, $condition);
+
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaPhp();
+                \areacache::updateAreaArrayJs();
+                echo 'true';
+                exit;
+
+            case 'area_region':
+                $area_model = model('area');
+                $condition[] = array('area_id','=',intval(input('get.id')));
+                $update_array = array();
+                $update_array['area_region'] = trim(input('get.value'));
+                $area_model->editArea($update_array, $condition);
+                
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaArrayJs();
+                \areacache::updateAreaPhp();
+                echo 'true';
+                exit;
+
+            case 'area_index_show':
+                $area_model = model('area');
+                $condition[] = array('area_id','=',intval(input('get.id')));
+                $update_array = array();
+                $update_array[input('get.column')] = input('get.value');
+                $area_model->editArea($update_array, $condition);
+
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaArrayJs();
+                \areacache::updateAreaPhp();
+                echo 'true';
+                exit;
+                break;
+            /**
+             * 添加、修改操作中 检测类别名称是否有重复
+             */
+            case 'check_class_name':
+                $area_model = model('area');
+                $condition[]=array('area_name','=',trim(input('param.area_name')));
+                $condition[]=array('area_parent_id','=',intval(input('param.area_parent_id')));
+                $condition[]=array('area_id','<>', intval(input('param.area_id')));
+                $class_list = $area_model->getAreaList($condition);
+                if (empty($class_list)) {
+                    echo 'true';
+                    exit;
+                } else {
+                    echo 'false';
+                    exit;
+                }
+                break;
+        }
+    }
+
+    public function add() {
+        if (!request()->isPost()) {
+            $area = array(
+                'area_parent_id' => input('param.area_id'),
+            );
+            View::assign('area', $area);
+            View::assign('parents', $this->_get_options());
+            return View::fetch('form');
+        } else {
+            $area_mod=model('area');
+            $area_parent_id = intval(input('param.area_parentid'));
+            
+            $area = $area_mod->getAreaInfo(array('area_id'=>$area_parent_id));
+            $area_deep=intval($area['area_deep'])+1;
+            if($area_deep>MAX_LAYER){
+                $this->error(sprintf(lang('area_deep_error'), MAX_LAYER));
+            }
+            $data = array(
+                'area_name' => input('post.area_name'),
+				'area_initial' => input('post.area_initial'),
+                'area_region' => input('post.area_region'),
+                'area_parent_id' => $area_parent_id,
+                'area_deep'=> $area_deep,
+                'area_sort' => input('post.area_sort'),
+            );
+            $region_validate = ds_validate('region');
+            if (!$region_validate->scene('add')->check($data)) {
+                $this->error($region_validate->getError());
+            }
+
+            $result = $area_mod->addArea($data);
+            if ($result) {
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaArrayJs();
+                \areacache::updateAreaPhp();
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    public function edit() {
+        $area_id = intval(input('param.area_id'));
+        if ($area_id<=0) {
+            $this->error(lang('param_error'));
+        }
+        $area_mod=model('area');
+        $area = $area_mod->getAreaInfo(array('area_id'=>$area_id));
+        if(!$area){
+            $this->error(lang('area_empty'));
+        }
+        if (!request()->isPost()) {
+            
+            View::assign('area', $area);
+            View::assign('parents', $this->_get_options());
+            return View::fetch('form');
+        } else {
+            $area_parent_id = intval(input('param.area_parentid'));
+            $data = array(
+                'area_name' => input('post.area_name'),
+				'area_initial' => input('post.area_initial'),
+                'area_region' => input('post.area_region'),
+                'area_parent_id' => $area_parent_id,
+                'area_sort' => input('post.area_sort'),
+            );
+            $region_validate = ds_validate('region');
+            if (!$region_validate->scene('edit')->check($data)) {
+                $this->error($region_validate->getError());
+            }
+
+            if($data['area_parent_id']==$area_id){
+                $this->error(lang('area_parent_error'));
+            }
+            try {
+                Db::startTrans();
+            if($data['area_parent_id']!=$area['area_parent_id']){
+                //如果不同级
+                $now_deep=intval(Db::name('area')->where('area_id='.$data['area_parent_id'])->value('area_deep'))+1;
+                $old_deep=intval(Db::name('area')->where('area_id='.$area['area_parent_id'])->value('area_deep'))+1;
+                if($now_deep!=$old_deep){
+                    if($now_deep>MAX_LAYER){
+                        $this->error(sprintf(lang('area_deep_error'), MAX_LAYER));
+                    }
+                    $data['area_deep']=$now_deep;
+                    $j=$old_deep;
+                    $subQuery='('.$area_id.')';
+                    while($j<=MAX_LAYER){
+                        //如果自己的上级是自己的下级则报错
+                        if(Db::name('area')->where('area_id='.$data['area_parent_id'].' AND area_parent_id IN '.$subQuery)->value('area_id')){
+                            Db::rollback();
+                            $this->error(lang('area_parent_error'));
+                        }
+                        $subQuery=Db::name('area')->field('area_id')->where('area_parent_id IN '.$subQuery)->buildSql();
+                        $j++;
+                    }
+                    //给他的下级修改深度
+                    $i=$now_deep+1;
+                    $subQuery='('.$area_id.')';
+                    while($i<=MAX_LAYER){
+
+                        Db::name('area')->where('area_parent_id IN '.$subQuery)->update(array('area_deep'=>$i));
+                        $subQuery='(SELECT area_id FROM '.Db::name('area')->field('area_id')->where('area_parent_id IN '.$subQuery)->buildSql().' a)';
+                        $i++;
+                    }
+                }
+            }
+            $result = $area_mod->editArea($data,array('area_id'=>$area_id));
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        Db::commit();
+            if ($result >= 0) {
+                \areacache::deleteCacheFile();
+                \areacache::updateAreaArrayJs();
+                \areacache::updateAreaPhp();
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    public function drop() {
+        $area_id = input('param.area_id');
+        if (empty($area_id)) {
+            $this->error(lang('param_error'));
+        }
+        //判断此分类下是否有子分类
+        $area_mod=model('area');
+        $result = $area_mod->getAreaInfo(array('area_parent_id'=>$area_id));
+        if ($result) {
+            ds_json_encode(10001, lang('please_drop_child_region'));
+        }
+        $result = $area_mod->delArea(array('area_id'=>$area_id));
+        if ($result) {
+            \areacache::deleteCacheFile();
+            \areacache::updateAreaArrayJs();
+            \areacache::updateAreaPhp();
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode(10001, lang('error'));
+        }
+    }
+
+    /* 取得可以作为上级的地区分类数据 */
+
+    function _get_options($except = NULL) {
+        $area = $this->_area_model->getAreaChild();
+        if (empty($area)) {
+            return;
+        }
+        $tree = new \mall\Tree();
+        $tree->setTree($area, 'area_id', 'area_parent_id', 'area_name');
+        return $tree->getOptions(MAX_LAYER - 1, 0, $except);
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_manage'),
+                'url' => (string)url('Region/index')
+            ),
+        );
+
+        if (request()->action() == 'add' || request()->action() == 'index') {
+            $menu_array[] = array(
+                'name' => 'add',
+                'text' => lang('ds_new'),
+                'url' =>"javascript:dsLayerOpen('".(string)url('Region/add')."','".lang('ds_add')."')",
+            );
+        }
+        if (request()->action() == 'edit') {
+            $menu_array[] = array(
+                'name' => 'edit',
+                'text' => lang('ds_edit'),
+                'url' => 'javascript:void(0)'
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 379 - 0
app/admin/controller/Returnmanage.php

@@ -0,0 +1,379 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Returnmanage extends AdminControl {
+
+    const EXPORT_SIZE = 1000;
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/returnmanage.lang.php');
+        //向模板页面输出退款退货状态
+        $this->getRefundStateArray();
+    }
+
+    function getRefundStateArray($type = 'all') {
+        $state_array = array(
+            '1' => lang('refund_state_confirm'),
+            '2' => lang('refund_state_yes'),
+            '3' => lang('refund_state_no')
+        ); //卖家处理状态:1为待审核,2为同意,3为不同意
+        View::assign('state_array', $state_array);
+
+        $admin_array = array(
+            '1' => lang('admin_state_1'),
+            '2' => lang('admin_state_2'),
+            '3' => lang('admin_state_3'), 
+            '4' => lang('refund_state_no')
+        ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
+        View::assign('admin_array', $admin_array);
+
+        $state_data = array(
+            'seller' => $state_array,
+            'admin' => $admin_array
+        );
+        if ($type == 'all') {
+            return $state_data; //返回所有
+        }
+        return $state_data[$type];
+    }
+
+    /**
+     * 待处理列表
+     */
+    public function return_manage() {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[]=array('refund_state','=','2'); //状态:1为处理中,2为待管理员处理,3为已完成
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        $return_list = $refundreturn_model->getReturnList($condition, 10);
+
+        View::assign('return_list', $return_list);
+        View::assign('show_page', $refundreturn_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('return_manage');
+        return View::fetch('return_manage');
+    }
+
+    /**
+     * 所有记录
+     */
+    public function return_all() {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        $return_list = $refundreturn_model->getReturnList($condition, 10);
+        View::assign('return_list', $return_list);
+        View::assign('show_page', $refundreturn_model->page_info->render());
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        $this->setAdminCurItem('return_all');
+        return View::fetch('return_all');
+    }
+
+    /**
+     * 退货处理页
+     *
+     */
+    public function edit() {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[] = array('refund_id','=',intval(input('param.refund_id')));
+        $return = $refundreturn_model->getRefundreturnInfo($condition);
+        if(empty($return)){
+            $this->error(lang('param_error'));
+        }
+        //查询交易凭证
+        $order_model = model('order');
+        $order = $order_model->getOrderInfo(array('order_id' => $return['order_id']));
+        if (request()->isPost()) {
+            if(!in_array(input('post.refund_state'),[3,4])){
+              $this->error(lang('refund_state_null'));
+            }
+            $check = request()->checkToken('__token__');
+            if(false === $check) {
+                $this->error('invalid token');
+            }
+            if ($return['refund_state'] != '2') {//检查状态,防止页面刷新不及时造成数据错误
+                $this->error(lang('ds_common_save_fail'));
+            }
+            $order_id = $return['order_id'];
+            $refund_array = array();
+            $refund_array['admin_time'] = TIMESTAMP;
+            $refund_array['refund_state'] = '4'; //状态:1为处理中,2为待管理员处理,3为已完成
+            $refund_array['admin_message'] = input('post.admin_message');
+            if (input('post.refund_state') == '3') {
+                $trade_no=input('param.trade_no');
+                if($trade_no && $trade_no!=$order['trade_no']){
+                    $order_model->editOrder(array('trade_no'=>$trade_no), array(
+                    'order_id' => $order['order_id']
+                    ));
+                    //添加订单日志
+                    $data = array();
+                    $data['order_id'] = $order['order_id'];
+                    $data['log_role'] = 'system';
+                    $data['log_user'] = $this->admin_info['admin_name'];
+                    $data['log_msg'] = '修改支付平台交易号 : ' . $trade_no;
+                    $data['log_orderstate'] = $order['order_state'];
+                    $order_model->addOrderlog($data);
+                }
+                $refund_array['refund_state'] = '3';
+                $res = $refundreturn_model->editOrderRefund($return);
+                $state=$res['code'];
+                if(!$state){
+                    $this->error($res['msg']);
+                }
+            }else{
+                if($return['order_lock'] == '2'){
+                    $state = $refundreturn_model->editOrderUnlock($order_id); //订单解锁
+                }else{
+                    $state = true;
+                }
+            }
+            
+            if ($state) {
+                $refundreturn_model->editRefundreturn($condition, $refund_array);
+                $this->log('退货确认,退货编号' . $return['refund_sn']);
+
+                // 发送买家消息
+                $param = array();
+                $param['code'] = 'refund_return_notice';
+                $param['member_id'] = $return['buyer_id'];
+                //阿里短信参数
+                $param['ali_param'] = array(
+                    'refund_sn' => $return['refund_sn']
+                );
+                $param['ten_param'] = array(
+                    $return['refund_sn']
+                );
+                $param['param'] = array_merge($param['ali_param'],array(
+                    'refund_url' => HOME_SITE_URL .'/memberreturn/view?return_id='.$return['refund_id'],
+                ));
+                //微信模板消息
+                $param['weixin_param'] = array(
+                    'url' => config('ds_config.h5_site_url').'/member/return_view?refund_id='.$return['refund_id'],
+                    'data'=>array(
+                        "keyword1" => array(
+                            "value" => $return['order_sn'],
+                            "color" => "#333"
+                        ),
+                        "keyword2" => array(
+                            "value" => $return['refund_amount'],
+                            "color" => "#333"
+                        )
+                    ),
+                );
+                model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
+
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+        View::assign('trade_no', $order['trade_no']);
+        View::assign('return', $return);
+        $info['buyer'] = array();
+        if (!empty($return['pic_info'])) {
+            $info = unserialize($return['pic_info']);
+        }
+        View::assign('pic_list', $info['buyer']);
+        return View::fetch('edit');
+    }
+
+    /**
+     * 退货记录查看页
+     *
+     */
+    public function view() {
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+        $condition[] = array('refund_id','=',intval(input('param.refund_id')));
+        $return = $refundreturn_model->getRefundreturnInfo($condition);
+        if(empty($return)){
+            $this->error(lang('param_error'));
+        }
+        View::assign('return', $return);
+        $info['buyer'] = array();
+        if (!empty($return['pic_info'])) {
+            $info = unserialize($return['pic_info']);
+        }
+        View::assign('pic_list', $info['buyer']);
+        return View::fetch('view');
+    }
+
+
+    /**
+     * 导出
+     *
+     */
+    public function export_step1() {
+
+        $refundreturn_model = model('refundreturn');
+        $condition = array();
+
+        $keyword_type = array('order_sn', 'refund_sn', 'store_name', 'buyer_name', 'goods_name');
+        $key = input('get.key');
+        $type = input('get.type');
+        if (trim($key) != '' && in_array($type, $keyword_type)) {
+            $condition[]=array($type,'like', '%' . $key . '%');
+        }
+        $add_time_from = input('get.add_time_from');
+        $add_time_to = input('get.add_time_to');
+        if (trim($add_time_from) != '') {
+            $add_time_from = strtotime(trim($add_time_from));
+            if ($add_time_from !== false) {
+                $condition[] = array('add_time','>=', $add_time_from);
+            }
+        }
+        if (trim($add_time_to) != '') {
+            $add_time_to = strtotime(trim($add_time_to))+86399;
+            if ($add_time_to !== false) {
+                $condition[] = array('add_time','<=', $add_time_to);
+            }
+        }
+        if (!is_numeric(input('param.page'))) {
+            $count = $refundreturn_model->getReturnCount($condition);
+            $export_list = array();
+            if ($count > self::EXPORT_SIZE) { //显示下载链接
+                $page = ceil($count / self::EXPORT_SIZE);
+                for ($i = 1; $i <= $page; $i++) {
+                    $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
+                    $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
+                    $export_list[$i] = $limit1 . ' ~ ' . $limit2;
+                }
+                View::assign('export_list', $export_list);
+                return View::fetch('/public/excel');
+            } else { //如果数量小,直接下载
+                $data = $refundreturn_model->getReturnList($condition, '', '*', 'refund_id desc', self::EXPORT_SIZE);
+                $this->createExcel($data);
+            }
+        } else { //下载
+            $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
+            $limit2 = self::EXPORT_SIZE;
+            $data = $refundreturn_model->getReturnList($condition, $limit2, '*', 'refund_id desc');
+            $this->createExcel($data);
+        }
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param array $data
+     */
+    private function createExcel($data = array()) {
+        Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
+        $excel_obj = new \excel\Excel();
+        $excel_data = array();
+        //设置样式
+        $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+        //header
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_order_sn'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_th_order_returnsn'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_store_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_goods_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_buyer_name'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_th_add_time'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_th_refund_amount'));
+        $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_th_goods_num'));
+        //data
+        foreach ((array) $data as $k => $v) {
+            $tmp = array();
+            $tmp[] = array('data' => 'DS' . $v['order_sn']);
+            $tmp[] = array('data' => $v['refund_sn']);
+            $tmp[] = array('data' => $v['store_name']);
+            $tmp[] = array('data' => $v['goods_name']);
+            $tmp[] = array('data' => $v['buyer_name']);
+            $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
+            $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['refund_amount']));
+            $tmp[] = array('data' => $v['goods_num']);
+            $excel_data[] = $tmp;
+        }
+        $excel_data = $excel_obj->charset($excel_data, CHARSET);
+        $excel_obj->addArray($excel_data);
+        $excel_obj->addWorksheet($excel_obj->charset(lang('exp_th_return'), CHARSET));
+        $excel_obj->generateXML($excel_obj->charset(lang('exp_th_return'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'return_manage',
+                'text' => lang('refund_state_confirm'),
+                'url' => (string)url('Returnmanage/return_manage')
+            ),
+            array(
+                'name' => 'return_all',
+                'text' => lang('refund_all'),
+                'url' => (string)url('Returnmanage/return_all')
+            ),
+        );
+        if(request()->action() == 'edit') {
+            $menu_array[] = array(
+                'name' => 'edit', 'text' => lang('ds_verify'), 'url' => 'javascript:void(0)',
+            );
+        }
+        return $menu_array;
+    }
+
+}
+
+?>

+ 53 - 0
app/admin/controller/Seo.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Seo extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/seo.lang.php');
+    }
+
+    function index() {
+        if (!request()->isPost()) {
+            //读取SEO信息
+            $list = Db::name('seo')->select()->toArray();
+            $seo = array();
+            foreach ((array) $list as $value) {
+                $seo[$value['seo_type']] = $value;
+            }
+            View::assign('seo', $seo);
+//            $category = model('goodsclass')->getGoodsclassForCacheModel();
+//            View::assign('category', $category);
+            return View::fetch('index');
+        } else {
+            $update = array();
+            $seo = input('post.SEO/a');#获取数组
+            if (is_array($seo)) {
+                foreach ($seo as $key => $value) {
+                    Db::name('seo')->where(array('seo_type' => $key))->update($value);
+                }
+                dkcache('seo');
+                ds_json_encode('10000', lang('ds_common_save_succ'));
+            }
+        }
+    }
+
+}
+
+?>

+ 167 - 0
app/admin/controller/Snsmalbum.php

@@ -0,0 +1,167 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Snsmalbum extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/snsmalbum.lang.php');
+    }
+
+    /**
+     * 相册设置
+     */
+    public function setting() {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            //构造更新数据数组
+            $update_array = array();
+            $update_array['malbum_max_sum'] = intval(input('post.malbum_max_sum'));
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                dsLayerOpenSuccess(lang('ds_common_save_succ'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            View::assign('list_setting', $list_setting);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 相册列表
+     */
+    public function index()
+    {
+        $snsmalbum_model = model('snsalbum');
+        // 相册总数量
+        $where = array();
+        if (input('param.class_name') != '') {
+            $where[]=array('ac_name','like', '%' . trim(input('param.class_name')) . '%');
+        }
+        if (input('param.user_name') != '') {
+            $where[]=array('member_name','like', '%' . trim(input('param.user_name')) . '%');
+        }
+        $ac_lists = $snsmalbum_model->getSnsalbumclassList($where,10,'a.*,m.member_name');
+        if (!empty($ac_lists)) {
+            $ac_list= $ac_lists;
+            $acid_array = array();
+            foreach ($ac_list as $val) {
+                $acid_array[] = $val['ac_id'];
+            }
+            // 相册中商品数量
+            $ap_count = $snsmalbum_model->getSnsalbumpicCountList(array(array('ac_id','in', $acid_array)),'count(ap_id) as count,ac_id','ac_id');
+            $ap_count = array_under_reset($ap_count, 'ac_id', 1);
+            foreach ($ac_list as $key => $val) {
+                if (isset($ap_count[$val['ac_id']])) {
+                    $ac_list[$key]['count'] = $ap_count[$val['ac_id']]['count'];
+                }
+                else {
+                    $ac_list[$key]['count'] = 0;
+                }
+            }
+            View::assign('ac_list', $ac_list);
+        }
+        View::assign('showpage', $snsmalbum_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch('index');
+    }
+
+    /**
+     * 图片列表
+     */
+    public function pic_list() {
+        $snsmalbum_model = model('snsalbum');
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $where = array();
+        $where[]=array('ac_id','=',$id);
+        if (input('param.pic_name') != '') {
+            $where[]=array('ap_name|ap_cover','like', '%' . input('param.pic_name') . '%');
+        }
+        $pic_list = $snsmalbum_model->getSnsalbumpicList($where, 10);
+        View::assign('id', $id);
+        View::assign('showpage', $snsmalbum_model->page_info->render());
+        View::assign('pic_list', $pic_list);
+        $this->setAdminCurItem('pic_list');
+        return View::fetch();
+    }
+
+    /**
+     * 删除图片
+     */
+    public function del_pic()
+    {
+        $id = input('param.ap_id');
+        if ($id <= 0) {
+            ds_json_encode(10001, lang('param_error'));
+        }        
+        $id_array = ds_delete_param($id);
+        if($id_array === FALSE){
+            ds_json_encode(10001, lang('param_error'));
+        }
+        $condition = array(array('ap_id' ,'in', $id_array));
+        $snsmalbum_model = model('snsalbum');
+        $ap_list = $snsmalbum_model->getSnsalbumpicList($condition);
+            if (empty($ap_list)) {
+                ds_json_encode(10001, lang('snsalbum_choose_need_del_img'));
+            }
+            foreach ($ap_list as $val) {
+                @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . $val['ap_cover']);
+                @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . str_ireplace('.', '_240.', $val['ap_cover']));
+                @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . $val['member_id'] . DIRECTORY_SEPARATOR . str_ireplace('.', '_1280.', $val['ap_cover']));
+            }
+            $result = $snsmalbum_model->delSnsalbumpic($condition);
+            if($result){
+                $this->log(lang('ds_del') . lang('ds_member_album_manage') . '[ID:' . $id . ']', 1);
+                ds_json_encode(10000, lang('ds_common_del_succ'));
+            } else {
+                ds_json_encode(10001, lang('ds_common_del_fail'));
+            }
+            
+    }
+
+    protected function getAdminItemList($curitem = '')
+    {
+        $menu_array = array(
+            array(
+                'name' => 'index', 
+                'text' => lang('snsalbum_class_list'),
+                'url' => (string)url('Snsmalbum/index')
+            ), array(
+                'name' => 'setting', 
+                'text' => lang('snsalbum_album_setting'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Snsmalbum/setting')."','".lang('snsalbum_album_setting')."')"
+            ),
+        );
+        if(request()->action()=='pic_list'){
+            $menu_array[]=array(
+                'name' => 'pic_list', 
+                'text' => lang('snsalbum_pic_list'),
+                'url' => (string)url('Snsmalbum/pic_list',['id'=>input('param.id')])
+            );
+        }
+        return $menu_array;
+    }
+}

+ 266 - 0
app/admin/controller/Snsmember.php

@@ -0,0 +1,266 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Snsmember extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/snsmember.lang.php');
+    }
+
+    /**
+     * 标签列表
+     */
+    public function index() {
+        // 实例化模型
+        $snsmember_model = model('snsmember');
+        $tag_list = $snsmember_model->getSnsmembertagList('mtag_sort asc', 10);
+        View::assign('showpage', $snsmember_model->page_info->render());
+        View::assign('tag_list', $tag_list);
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /**
+     * 添加标签
+     */
+    public function tag_add() {
+        if (request()->isPost()) {
+            /**
+             * 验证
+             */
+            $data = [
+                'membertag_name' => input('post.membertag_name'), 'membertag_sort' => input('post.membertag_sort'),
+            ];
+
+            $snsmember_validate = ds_validate('snsmember');
+            if (!$snsmember_validate->scene('tag_add')->check($data)) {
+                $this->error($snsmember_validate->getError());
+            } else {
+                /**
+                 * 上传图片
+                 */
+                $img = '';
+                if (!empty($_FILES['membertag_img']['name'])) {
+                    $res = ds_upload_pic(ATTACH_PATH . '/membertag', 'membertag_img');
+                    if ($res['code']) {
+                        $img = $res['data']['file_name'];
+                    } else {
+                        $this->error($res['msg']);
+                    }
+                }
+                $insert = array(
+                    'mtag_name' => input('post.membertag_name'),
+                    'mtag_sort' => intval(input('post.membertag_sort')),
+                    'mtag_recommend' => intval(input('post.membertag_recommend')),
+                    'mtag_desc' => trim(input('post.membertag_desc')),
+                    'mtag_img' => $img
+                );
+                $snsmember_model = model('snsmember');
+                $result = $snsmember_model->addSnsmembertag($insert);
+                if ($result) {
+                    $this->log(lang('ds_add') . lang('sns_member_tag') . '[' . input('post.membertag_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('ds_common_op_succ'));
+                } else {
+                    $this->error(lang('ds_common_op_fail'));
+                }
+            }
+        } else {
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 编辑标签
+     */
+    public function tag_edit() {
+        // 实例化模型
+        if (request()->isPost()) {
+            /**
+             * 验证
+             */
+            $data = [
+                'membertag_name' => input('post.membertag_name'), 'membertag_sort' => input('post.membertag_sort'),
+            ];
+            $snsmember_validate = ds_validate('snsmember');
+            if (!$snsmember_validate->scene('tag_edit')->check($data)) {
+                $this->error($snsmember_validate->getError());
+            } else {
+                /**
+                 * 上传图片
+                 */
+
+                $input = '';
+                if (!empty($_FILES['membertag_img']['name'])) {
+                    $res = ds_upload_pic(ATTACH_PATH . '/membertag', 'membertag_img');
+                    if ($res['code']) {
+                        $input = $res['data']['file_name'];
+                    } else {
+                        $this->error($res['msg']);
+                    }
+                }
+                $update = array();
+                $update['mtag_id'] = intval(input('post.id'));
+                $update['mtag_name'] = trim(input('post.membertag_name'));
+                $update['mtag_sort'] = intval(input('post.membertag_sort'));
+                $update['mtag_recommend'] = intval(input('post.membertag_recommend'));
+                $update['mtag_desc'] = trim(input('post.membertag_desc'));
+                $update['mtag_img'] = $input;
+
+                $snsmember_model = model('snsmember');
+                $result = $snsmember_model->editSnsmembertag($update);
+                if ($result >= 0) {
+                    $this->log(lang('ds_edit') . lang('sns_member_tag') . '[' . input('post.membertag_name') . ']', 1);
+                    dsLayerOpenSuccess(lang('ds_common_op_succ'));
+                } else {
+                    $this->error(lang('ds_common_op_fail'));
+                }
+            }
+        } else {
+            // 验证
+            $mtag_id = intval(input('param.id'));
+            if ($mtag_id <= 0) {
+                $this->error(lang('param_error'));
+            }
+            $snsmember_model = model('snsmember');
+            $mtag_info = $snsmember_model->getOneSnsmembertag($mtag_id);
+            if (empty($mtag_info)) {
+                $this->error(lang('param_error'));
+            }
+            $this->setAdminCurItem('tag_edit');
+            //halt($mtag_info);
+            View::assign('mtag_info', $mtag_info);
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 删除标签
+     */
+    public function tag_del() {
+        $mtag_id = input('param.id');
+        $mtag_id_array = ds_delete_param($mtag_id);
+        if ($mtag_id_array == FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[] = array('mtag_id', 'in', $mtag_id_array);
+        $snsmember_model = model('snsmember');
+        $result = $snsmember_model->delSnsmembertag($condition);
+        if ($result) {
+            $this->log(lang('ds_del') . lang('sns_member_tag') . '[ID:' . $mtag_id . ']', 1);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 标签所属会员列表
+     */
+    public function tag_member() {
+        // 验证
+        $mtag_id = intval(input('param.id'));
+        if ($mtag_id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $snsmember_model = model('snsmember');
+        $count = $snsmember_model->getSnstagmemberCount(array('mtag_id' => $mtag_id));
+        $tagmember_list = $snsmember_model->getSnsmtagmemberList(array('s.mtag_id' => $mtag_id), 's.*,m.member_avatar,m.member_name', 10, 's.recommend desc, s.member_id asc', $count);
+        View::assign('tagmember_list', $tagmember_list);
+        View::assign('showpage', $snsmember_model->page_info->render());
+        $this->setAdminCurItem('tag_member');
+        return View::fetch();
+    }
+
+    /**
+     * 删除添加标签会员
+     */
+    public function mtag_del() {
+        $snsmember_model = model('snsmember');
+        $mtag_id = intval(input('param.id'));
+        $member_id = intval(input('param.mid'));
+        if ($mtag_id <= 0 || $member_id <= 0) {
+            $this->error(lang('miss_argument'));
+        }
+        // 条件
+        $condition = array();
+        $condition[] = array('mtag_id', '=', $mtag_id);
+        $condition[] = array('member_id', '=', $member_id);
+        $result = $snsmember_model->delSnsmtagmember($condition);
+        if ($result) {
+            $this->log(lang('ds_del') . lang('sns_member_tag') . '[ID:' . $mtag_id . ']', 1);
+            $this->success(lang('ds_common_del_succ'));
+        } else {
+            $this->error(lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * ajax修改
+     */
+    public function ajax() {
+        // 实例化模型
+        $snsmember_model = model('snsmember');
+        switch (input('param.branch')) {
+            /**
+             * 更新名称、排序、推荐
+             */
+            case 'membertag_name':
+            case 'membertag_sort':
+            case 'membertag_recommend':
+                $update = array(
+                    'mtag_id' => intval(input('param.id')), input('param.column') => input('param.value')
+                );
+                $snsmember_model->editSnsmembertag($update);
+                echo 'true';
+                break;
+            /**
+             * sns_mtagmember表推荐
+             */
+            case 'mtagmember_recommend':
+                list($where['mtag_id'], $where['member_id']) = explode(',', input('param.id'));
+                $update = array(
+                    input('param.column') => input('param.value')
+                );
+                $snsmember_model->editSnsmtagmember($where, $update);
+                echo 'true';
+                break;
+        }
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index', 'text' => lang('sns_member_tag_manage'), 'url' => (string) url('Snsmember/index')
+            ), array(
+                'name' => 'tag_add',
+                'text' => lang('ds_new'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Snsmember/tag_add') . "','" . lang('ds_new') . "')"
+            ),
+        );
+        if (request()->action() == 'tag_member') {
+            $menu_array[] = array(
+                'name' => 'tag_member', 'text' => lang('sns_member_member_list'), 'url' => ('#')
+            );
+        }
+        return $menu_array;
+    }
+
+}

+ 157 - 0
app/admin/controller/Spec.php

@@ -0,0 +1,157 @@
+<?php
+
+/*
+ * 规格管理
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Spec extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/spec.lang.php');
+    }
+
+    public function index() {
+        
+         /**
+         * 查询条件
+         */
+        $where = array();
+        
+        $sp_name = trim(input('param.sp_name'));
+        if ($sp_name != '') {
+            $where[]=array('sp_name','like', '%' . $sp_name . '%');
+        }
+        $gc_name = trim(input('param.gc_name'));
+        if ($gc_name != '') {
+            $where[]=array('gc_name','like', '%' . $gc_name . '%');
+        }
+        
+        $spec_model = model('spec');
+        $spec_list	= $spec_model->getSpecList($where, 10);
+        View::assign('spec_list', $spec_list);
+        View::assign('show_page', $spec_model->page_info->render());
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    public function spec_add() {
+        if (!(request()->isPost())) {
+            $spec = [
+                'gc_id' => 0,
+            ];
+            View::assign('spec', $spec);
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            return View::fetch('spec_form');
+        } else {
+            $data = array(
+                'sp_name' => input('post.sp_name'),
+                'sp_sort' => input('post.sp_sort'),
+                'gc_id' => input('post.gc_id'),
+                'gc_name' => input('post.gc_name'),
+            );
+            $spec_validate = ds_validate('spec');
+            if (!$spec_validate->scene('spec_add')->check($data)) {
+                $this->error($spec_validate->getError());
+            }
+
+            $spec_model= model('spec');
+            $result=$spec_model->addSpec($data);
+            if ($result) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('error'));
+            }
+        }
+    }
+
+    public function spec_edit() {
+        //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
+        $sp_id = input('param.sp_id');
+        if (empty($sp_id)) {
+            $this->error(lang('param_error'));
+        }
+        if (!request()->isPost()) {
+            $spec_model= model('spec');
+            $spec=$spec_model->getSpecInfo($sp_id);
+            View::assign('spec', $spec);
+            $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
+            View::assign('gc_list', $gc_list);
+            return View::fetch('spec_form');
+        } else {
+            $data = array(
+                'sp_name' => input('post.sp_name'),
+                'sp_sort' => input('post.sp_sort'),
+                'gc_id' => input('post.gc_id'),
+                'gc_name' => input('post.gc_name'),
+            );
+            $spec_validate = ds_validate('spec');
+            if (!$spec_validate->scene('spec_edit')->check($data)) {
+                $this->error($spec_validate->getError());
+            }
+
+            $spec_model= model('spec');
+            $condition=array();
+            $condition[] = array('sp_id','=',$sp_id);
+            $result=$spec_model->editSpec($data, $condition);
+            if ($result>=0) {
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    public function spec_drop() {
+        //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
+        $sp_id = intval(input('param.sp_id'));
+        // sp_id 值为1 不能删除,用于处理前台显示图片的规格
+        if ($sp_id<=1) {
+            $this->error(lang('param_error'));
+        }
+        $spec_model = model('spec');
+        $result=$spec_model->delSpec(array('sp_id' => $sp_id));
+        if ($result) {
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode(10001, lang('ds_common_del_fail'));
+        }
+    }
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('ds_spec'),
+                'url' => (string)url('Spec/index')
+            ),
+            array(
+                'name' => 'spec_add',
+                'text' => lang('ds_new'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Spec/spec_add')."','".lang('ds_new')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}
+
+?>

+ 296 - 0
app/admin/controller/Stataftersale.php

@@ -0,0 +1,296 @@
+<?php
+/**
+ * 售后统计分析
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Stataftersale extends AdminControl
+{
+    private $search_arr;//处理后的参数
+
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(),array('refund'))){
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+    }
+
+    /**
+     * 退款统计
+     */
+    public function refund(){
+        $where = array();
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+
+        $field = ' SUM(refund_amount) as amount ';
+        if($this->search_arr['search_type'] == 'day'){
+            //构造横轴数据
+            for($i=0; $i<24; $i++){
+                $stat_arr['xAxis']['categories'][] = "$i";
+                $statlist[$i] = 0;
+            }
+            $field .= ' ,HOUR(FROM_UNIXTIME(add_time)) as timeval ';
+        }
+        if($this->search_arr['search_type'] == 'week'){
+            //构造横轴数据
+            for($i=1; $i<=7; $i++){
+                $tmp_weekarr = getSystemWeekArr();
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+                $statlist[$i] = 0;
+            }
+            $field .= ' ,WEEKDAY(FROM_UNIXTIME(add_time))+1 as timeval ';
+        }
+        if($this->search_arr['search_type'] == 'month'){
+            //计算横轴的最大量(由于每个月的天数不同)
+            $dayofmonth = date('t',$searchtime_arr[0]);
+            //构造横轴数据
+            for($i=1; $i<=$dayofmonth; $i++){
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+                $statlist[$i] = 0;
+            }
+            $field .= ' ,day(FROM_UNIXTIME(add_time)) as timeval ';
+        }
+        $where = array();
+        $where[] = array('add_time','between',$searchtime_arr);
+        $statlist_tmp = $stat_model->statByRefundreturn($where, $field, 0, 0, 'timeval asc', 'timeval');
+        if ($statlist_tmp){
+            foreach((array)$statlist_tmp as $k=>$v){
+                $statlist[$v['timeval']] = floatval($v['amount']);
+            }
+        }
+        //得到统计图数据
+        $stat_arr['legend']['enabled'] = false;
+        $stat_arr['series'][0]['name'] = lang('stattrade_refund_total');
+        $stat_arr['series'][0]['data'] = array_values($statlist);
+        $stat_arr['title'] = lang('refund_amount_statis');
+        $stat_arr['yAxis'] = lang('stattrade_refund_total');
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json',$stat_json);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('refund');
+        return View::fetch('aftersale_refund');
+    }
+    /**
+     * 退款统计
+     */
+    public function refundlist(){
+        $refundreturn_model = model('refundreturn');
+        $refundstate_arr = $this->getRefundStateArray();
+        $where = array();
+        $statlist= array();
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('add_time','between',$searchtime_arr);
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
+            $refundlist_tmp = $refundreturn_model->getRefundreturnList($where, 0);
+        } else {
+            $refundlist_tmp = $refundreturn_model->getRefundreturnList($where, 10);
+        }
+        $statheader = array();
+        $statheader[] = array('text'=>lang('ds_order_sn'),'key'=>'order_sn');
+        $statheader[] = array('text'=>lang('ds_refund_sn'),'key'=>'refund_sn');
+        $statheader[] = array('text'=>lang('ds_store_name'),'key'=>'store_name','class'=>'alignleft');
+        $statheader[] = array('text'=>lang('ds_goods_name'),'key'=>'goods_name','class'=>'alignleft');
+        $statheader[] = array('text'=>lang('ds_member_name'),'key'=>'buyer_name');
+        $statheader[] = array('text'=>lang('apply_time'),'key'=>'add_time');
+        $statheader[] = array('text'=>lang('stattrade_refund_total'),'key'=>'refund_amount');
+        $statheader[] = array('text'=>lang('seller_state'),'key'=>'seller_state');
+        $statheader[] = array('text'=>lang('admin_state'),'key'=>'refund_state');
+        foreach ((array)$refundlist_tmp as $k=>$v){
+            $tmp = $v;
+            foreach ((array)$statheader as $h_k=>$h_v){
+                $tmp[$h_v['key']] = $v[$h_v['key']];
+                if ($h_v['key'] == 'add_time'){
+                    $tmp[$h_v['key']] = @date('Y-m-d',$v['add_time']);
+                }
+                if ($h_v['key'] == 'refund_state'){
+                    $tmp[$h_v['key']] = $v['seller_state']==2 ? $refundstate_arr['admin'][$v['refund_state']]:lang('none');
+                }
+                if ($h_v['key'] == 'seller_state'){
+                    $tmp[$h_v['key']] = $refundstate_arr['seller'][$v['seller_state']];
+                }
+                if ($h_v['key'] == 'goods_name'){
+                    $tmp[$h_v['key']] = '<a href="'.(string)url('Goods/index', array('goods_id' => $v['goods_id'])).'" target="_blank">'.$v['goods_name'].'</a>';
+                }
+            }
+            $statlist[] = $tmp;
+        }
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            foreach ((array)$statheader as $k=>$v){
+                $excel_data[0][] = array('styleid'=>'s_title','data'=>$v['text']);
+            }
+            //data
+            foreach ((array)$statlist as $k=>$v){
+                foreach ((array)$statheader as $h_k=>$h_v){
+                    $excel_data[$k+1][] = array('data'=>$v[$h_v['key']]);
+                }
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('refund_log'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('refund_log'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        } else {
+            View::assign('statheader',$statheader);
+            View::assign('statlist',$statlist);
+            View::assign('show_page',$refundreturn_model->page_info->render());
+            View::assign('searchtime',input('param.t'));
+            View::assign('actionurl',(string)url('Stataftersale/refundlist',['t'=>$this->search_arr['t']]));
+            echo View::fetch('stat_listandorder');
+        }
+    }
+    /**
+     * 店铺动态评分统计
+     */
+    public function evalstore(){
+        //店铺分类
+        View::assign('class_list', rkcache('storeclass', true));
+
+        $stat_model = model('stat');
+        $where = array();
+        $statlist=array();
+        if(intval(input('param.store_class')) > 0){
+            $where[]=array('storeclass_id','=',intval(input('param.store_class')));
+        }
+        if (isset($this->search_arr['storename'])){
+            $where[]=array('seval_storename','like',"%".trim($this->search_arr['storename'])."%");
+        }
+        $field = ' seval_storeid, seval_storename';
+        $field .= ' ,(SUM(seval_desccredit)/COUNT(*)) as avgdesccredit';
+        $field .= ' ,(SUM(seval_servicecredit)/COUNT(*)) as avgservicecredit';
+        $field .= ' ,(SUM(seval_deliverycredit)/COUNT(*)) as avgdeliverycredit';
+
+        $orderby_arr = array('avgdesccredit asc','avgdesccredit desc','avgservicecredit asc','avgservicecredit desc','avgdeliverycredit asc','avgdeliverycredit desc');
+        if (!isset($this->search_arr['orderby'])||!in_array(trim($this->search_arr['orderby']),$orderby_arr)){
+            $this->search_arr['orderby'] = 'avgdesccredit desc';
+        }
+        $orderby = trim($this->search_arr['orderby']).',seval_storeid';
+        //查询评论的店铺总数
+        $count_arr = $stat_model->statByStoreAndEvaluatestore($where, 'count(DISTINCT evaluatestore.seval_storeid) as countnum');
+        $countnum = intval($count_arr[0]['countnum']);
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
+            $statlist_tmp = $stat_model->statByStoreAndEvaluatestore($where, $field, 0, 0, $orderby, 'seval_storeid');
+        } else {
+            $statlist_tmp = $stat_model->statByStoreAndEvaluatestore($where, $field, 10, 0, $orderby, 'seval_storeid');
+        }
+        foreach((array)$statlist_tmp as $k=>$v){
+            $tmp = $v;
+            $tmp['avgdesccredit'] = round($v['avgdesccredit'],2);
+            $tmp['avgservicecredit'] = round($v['avgservicecredit'],2);
+            $tmp['avgdeliverycredit'] = round($v['avgdeliverycredit'],2);
+            $statlist[] = $tmp;
+        }
+        //导出Excel
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_store_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgdesccredit'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgservicecredit'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('avgdeliverycredit'));
+            //data
+            foreach ((array)$statlist as $k=>$v){
+                $excel_data[$k+1][] = array('data'=>$v['seval_storename']);
+                $excel_data[$k+1][] = array('data'=>$v['avgdesccredit']);
+                $excel_data[$k+1][] = array('data'=>$v['avgservicecredit']);
+                $excel_data[$k+1][] = array('data'=>$v['avgdeliverycredit']);
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('store_dynamic_score_statis'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('store_dynamic_score_statis'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        }
+        View::assign('statlist',$statlist);
+        View::assign('orderby',$this->search_arr['orderby']);
+        View::assign('show_page',$stat_model->page_info->render());
+        $this->setAdminCurItem('evalstore');
+        return View::fetch('aftersale_evalstore');
+    }
+    function getRefundStateArray($type = 'all') {
+        $state_array = array(
+            '1' => lang('refund_state_confirm'),
+            '2' => lang('refund_state_yes'),
+            '3' => lang('refund_state_no')
+        ); //卖家处理状态:1为待审核,2为同意,3为不同意
+        View::assign('state_array', $state_array);
+
+        $admin_array = array(
+            '1' => lang('admin_state_1'),
+            '2' => lang('admin_state_2'),
+            '3' => lang('admin_state_3')
+        ); //确认状态:1为买家或卖家处理中,2为待平台管理员处理,3为退款退货已完成
+        View::assign('admin_array', $admin_array);
+
+        $state_data = array(
+            'seller' => $state_array,
+            'admin' => $admin_array
+        );
+        if ($type == 'all') {
+            return $state_data; //返回所有
+        }
+        return $state_data[$type];
+    }
+
+    protected function getAdminItemList()
+    {
+       $menu_array=array(
+           array('name'=>'refund','text'=>lang('stat_refund'),'url'=>(string)url('Stataftersale/refund')),
+           array('name'=>'evalstore','text'=>lang('stat_evalstore'),'url'=>(string)url('Stataftersale/evalstore')),
+       );
+       return $menu_array;
+    }
+}

+ 273 - 0
app/admin/controller/Statgeneral.php

@@ -0,0 +1,273 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statgeneral extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        include_once root_path(). 'extend/mall/statistics.php';
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+    }
+
+    /**
+     * 促销分析
+     */
+    public function general()
+    {
+        $stat_model = model('stat');
+        //统计的日期0点
+        $stat_time = strtotime(date('Y-m-d', TIMESTAMP)) - 86400;
+        /*
+         * 昨日最新情报
+         */
+        $stime = $stat_time;
+        $etime = $stat_time + 86400 - 1;
+
+        $statnew_arr = array();
+
+        //查询订单表下单量、下单金额、下单客户数、平均客单价
+        $where = array();
+        $where[] = array('order_isvalid','=',1); //计入统计的有效订单
+        $where[] = array('order_add_time','between',array($stime, $etime));
+        $field = ' COUNT(*) as ordernum, SUM(order_amount) as orderamount, COUNT(DISTINCT buyer_id) as ordermembernum, AVG(order_amount) as orderavg ';
+        $stat_order = $stat_model->getoneByStatorder($where, $field);
+        $statnew_arr['ordernum'] = ($t = $stat_order['ordernum']) ? $t : 0;
+        $statnew_arr['orderamount'] = ds_price_format(($t = $stat_order['orderamount']) ? $t : (0));
+        $statnew_arr['ordermembernum'] = ($t = $stat_order['ordermembernum']) ? $t : 0;
+        $statnew_arr['orderavg'] = ds_price_format(($t = $stat_order['orderavg']) ? $t : 0);
+        unset($stat_order);
+
+        //查询订单商品表下单商品数
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',array($stime, $etime));
+        $field = ' SUM(goods_num) as ordergoodsnum,AVG(goods_pay_price/goods_num) as priceavg ';
+        $stat_ordergoods = $stat_model->getoneByStatordergoods($where, $field);
+        $statnew_arr['ordergoodsnum'] = ($t = $stat_ordergoods['ordergoodsnum']) ? $t : 0;
+        $statnew_arr['priceavg'] = ds_price_format(($t = $stat_ordergoods['priceavg']) ? $t : 0);
+        unset($stat_ordergoods);
+
+        //新增会员数
+        $where = array();
+        $where[] = array('member_addtime','between',array($stime, $etime));
+        $field = ' COUNT(*) as newmember ';
+        $stat_member = $stat_model->getOneByMember($where, $field);
+        $statnew_arr['newmember'] = ($t = $stat_member['newmember']) ? $t : 0;
+        unset($stat_member);
+
+        //会员总数
+        $where = array();
+        $field = ' COUNT(*) as membernum ';
+        $stat_member = $stat_model->getOneByMember($where, $field);
+        $statnew_arr['membernum'] = ($t = $stat_member['membernum']) ? $t : 0;
+        unset($stat_member);
+
+        //新增店铺
+        $where = array();
+        $where[] = array('store_addtime','between',array($stime, $etime));
+        $field = ' COUNT(*) as newstore ';
+        $stat_store = $stat_model->getOneByStore($where, $field);
+        $statnew_arr['newstore'] = ($t = $stat_store['newstore']) ? $t : 0;
+        unset($stat_store);
+
+        //店铺总数
+        $where = array();
+        $field = ' COUNT(*) as storenum ';
+        $stat_store = $stat_model->getOneByStore($where, $field);
+        $statnew_arr['storenum'] = ($t = $stat_store['storenum']) ? $t : 0;
+        unset($stat_store);
+
+        //新增商品,商品总数
+        $goods_list = $stat_model->statByGoods(array('is_virtual' => 0), "COUNT(*) as goodsnum, SUM(IF(goods_addtime>=$stime and goods_addtime<=$etime,'1',0)) as newgoods");
+        $statnew_arr['goodsnum'] = ($t = $goods_list[0]['goodsnum']) > 0 ? $t : 0;
+        $statnew_arr['newgoods'] = ($t = $goods_list[0]['newgoods']) > 0 ? $t : 0;
+
+        /*
+         * 昨日销售走势
+         */
+        //构造横轴数据
+        for ($i = 0; $i < 24; $i++) {
+            //统计图数据
+            $curr_arr[$i] = 0;//今天
+            $up_arr[$i] = 0;//昨天
+            //横轴
+            $stat_arr['xAxis']['categories'][] = "$i";
+        }
+        $stime = $stat_time - 86400;//昨天0点
+        $etime = $stat_time + 86400 - 1;//今天24点
+        $yesterday_day = @date('d', $stime);//昨天日期
+        $today_day = @date('d', $etime);//今天日期
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',array($stime, $etime));
+        $field = ' SUM(order_amount) as orderamount,DAY(FROM_UNIXTIME(order_add_time)) as dayval,HOUR(FROM_UNIXTIME(order_add_time)) as hourval ';
+        $stat_order = $stat_model->statByStatorder($where, $field, 0, 0, '', 'dayval,hourval');
+        if ($stat_order) {
+            foreach ($stat_order as $k => $v) {
+                if ($today_day == $v['dayval']) {
+                    $curr_arr[$v['hourval']] = intval($v['orderamount']);
+                }
+                if ($yesterday_day == $v['dayval']) {
+                    $up_arr[$v['hourval']] = intval($v['orderamount']);
+                }
+            }
+        }
+        $stat_arr['series'][0]['name'] = lang('yestoday');
+        $stat_arr['series'][0]['data'] = array_values($up_arr);
+        $stat_arr['series'][1]['name'] = lang('today');
+        $stat_arr['series'][1]['data'] = array_values($curr_arr);
+        //得到统计图数据
+        $stat_arr['title'] = date('Y-m-d', $stat_time) . lang('sale_trend');
+        $stat_arr['yAxis'] = lang('stattrade_order_amount');
+        $stattoday_json = getStatData_LineLabels($stat_arr);
+        unset($stat_arr);
+
+        /*
+         * 7日内店铺销售TOP30
+         */
+        $stime = $stat_time - 86400 * 6;//7天前0点
+        $etime = $stat_time + 86400 - 1;//今天24点
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',array($stime, $etime));
+        $field = ' SUM(order_amount) as orderamount, store_id, store_name ';
+        $storetop30_arr = $stat_model->statByStatorder($where, $field, 0, 0, 'orderamount desc', 'store_id');
+
+        /*
+         * 7日内商品销售TOP30
+         */
+        $stime = $stat_time - 86400 * 6;//7天前0点
+        $etime = $stat_time + 86400 - 1;//今天24点
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',array($stime, $etime));
+        $field = ' sum(goods_num) as ordergoodsnum, goods_id, goods_name ';
+        $goodstop30_arr = $stat_model->statByStatordergoods($where, $field, 0, 30, 'ordergoodsnum desc', 'goods_id');
+        View::assign('goodstop30_arr', $goodstop30_arr);
+        View::assign('storetop30_arr', $storetop30_arr);
+        View::assign('stattoday_json', $stattoday_json);
+        View::assign('statnew_arr', $statnew_arr);
+        View::assign('stat_time', $stat_time);
+        $this->setAdminCurItem('general');
+        return View::fetch();
+    }
+
+    /**
+     * 统计设置
+     */
+    public function setting()
+    {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $update_array = array();
+            
+            $pricerange_temp_array = input('post.pricerange/a');
+            if (is_array($pricerange_temp_array)) {
+                foreach ($pricerange_temp_array as $k => $v) {
+                    if(!is_numeric($v['s']) || !is_numeric($v['e'])){
+                      $this->error(lang('is_numeric_error'));
+                    }
+                    if($v['s']<0 || $v['e']<0){
+                      $this->error(lang('is_zero_error'));
+                    }
+                    if($v['s']>$v['e']){
+                      $this->error(lang('amount_set_error'));
+                    }
+                    $pricerange_arr[] = $v;
+                }
+                $update_array['stat_pricerange'] = serialize($pricerange_arr);
+            } else {
+                $update_array['stat_pricerange'] = '';
+            }
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit') . lang('stat_setting'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            } else {
+                $this->log(lang('ds_edit') . lang('stat_setting'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            $list_setting['stat_pricerange'] = unserialize($list_setting['stat_pricerange']);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('setting');
+            return View::fetch();
+        }
+    }
+
+    /**
+     * 统计设置
+     */
+    public function orderprange()
+    {
+        $config_model = model('config');
+        if (request()->isPost()) {
+            $update_array = array();
+            $pricerange_temp_array = input('post.pricerange/a');
+            if (is_array($pricerange_temp_array)) {
+                foreach ($pricerange_temp_array as $k => $v) {
+                    if(!is_numeric($v['s']) || !is_numeric($v['e'])){
+                      $this->error(lang('is_numeric_error'));
+                    }
+                    if($v['s']<0 || $v['e']<0){
+                      $this->error(lang('is_zero_error'));
+                    }
+                    if($v['s']>$v['e']){
+                      $this->error(lang('amount_set_error'));
+                    }
+                    $pricerange_arr[] = $v;
+                }
+                $update_array['stat_orderpricerange'] = serialize($pricerange_arr);
+            }
+            else {
+                $update_array['stat_orderpricerange'] = '';
+            }
+            $result = $config_model->editConfig($update_array);
+            if ($result === true) {
+                $this->log(lang('ds_edit').lang('stat_setting'), 1);
+                $this->success(lang('ds_common_save_succ'));
+            }
+            else {
+                $this->log(lang('ds_edit').lang('stat_setting'), 0);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        } else {
+            $list_setting = rkcache('config', true);
+            $list_setting['stat_orderpricerange'] = unserialize($list_setting['stat_orderpricerange']);
+            View::assign('list_setting', $list_setting);
+            $this->setAdminCurItem('orderprange');
+            return View::fetch();
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'general', 'text' => lang('stat_generalindex'), 'url' => (string)url('Statgeneral/general')
+            ), array(
+                'name' => 'setting', 'text' => lang('stat_goodspricerange'), 'url' => (string)url('Statgeneral/setting')
+            ), array(
+                'name' => 'orderprange', 'text' => lang('stat_orderpricerange'), 'url' => (string)url('Statgeneral/orderprange')
+            )
+        );
+        return $menu_array;
+    }
+}

+ 316 - 0
app/admin/controller/Statgoods.php

@@ -0,0 +1,316 @@
+<?php
+/**
+ * 商品统计分析
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statgoods extends AdminControl
+{
+    private $search_arr;//处理后的参数
+    private $gc_arr;//分类数组
+    private $choose_gcid;//选择的分类ID
+
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(),array('pricerange','hotgoods','goods_sale'))){
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+        /**
+         * 处理商品分类
+         */
+        $this->choose_gcid = ($t = intval(input('param.choose_gcid')))>0?$t:0;
+        $gccache_arr = model('goodsclass')->getGoodsclassCache($this->choose_gcid,3);
+        $this->gc_arr = $gccache_arr['showclass'];
+        View::assign('gc_json',json_encode($gccache_arr['showclass']));
+        View::assign('gc_choose_json',json_encode($gccache_arr['choose_gcid']));
+    }
+
+    /**
+     * 价格区间统计
+     */
+    public function pricerange(){
+        if(!isset($this->search_arr['search_type']) || !$this->search_arr['search_type']){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        //商品分类
+        if ($this->choose_gcid > 0){
+            //获得分类深度
+            $depth = $this->gc_arr[$this->choose_gcid]['depth'];
+            $where[] = array('gc_parentid_'.$depth,'=',$this->choose_gcid);
+        }
+        $field = '1';
+        $pricerange_arr = ($t = trim(cache('config')['stat_pricerange']))?unserialize($t):'';
+        if ($pricerange_arr){
+            $stat_arr['series'][0]['name'] = lang('statstore_ordernum');
+            //设置价格区间最后一项,最后一项只有开始值没有结束值
+            $pricerange_count = count($pricerange_arr);
+            if ($pricerange_arr[$pricerange_count-1]['e']){
+                $pricerange_arr[$pricerange_count]['s'] = $pricerange_arr[$pricerange_count-1]['e'] + 1;
+                $pricerange_arr[$pricerange_count]['e'] = '';
+            }
+            foreach ((array)$pricerange_arr as $k=>$v){
+                $v['s'] = intval($v['s']);
+                $v['e'] = intval($v['e']);
+                //构造查询字段
+                if ($v['e']){
+                    $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']} and goods_pay_price/goods_num <= {$v['e']},goods_num,0)) as goodsnum_{$k}";
+                } else {
+                    $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']},goods_num,0)) as goodsnum_{$k}";
+                }
+            }
+
+            $ordergooods_list = Db::query('SELECT '.$field.' FROM '.config('database.connections.mysql.prefix').'statordergoods WHERE order_isvalid=1 AND order_add_time BETWEEN '.$searchtime_arr[0].' AND '.$searchtime_arr[1].($this->choose_gcid > 0?(' AND gc_parentid_'.$depth.'='.$this->choose_gcid):''));
+            if($ordergooods_list){
+                $ordergooods_list= current($ordergooods_list);
+                foreach ((array)$pricerange_arr as $k=>$v){
+                    //横轴
+                    if($v['e']){
+                        $stat_arr['xAxis']['categories'][] = $v['s'].'-'.$v['e'];
+                    } else {
+                        $stat_arr['xAxis']['categories'][] = $v['s'].lang('above');
+                    }
+                    //统计图数据
+                    if (isset($ordergooods_list['goodsnum_'.$k])){
+                        $stat_arr['series'][0]['data'][] = intval($ordergooods_list['goodsnum_'.$k]);
+                    } else {
+                        $stat_arr['series'][0]['data'][] = 0;
+                    }
+                }
+            }
+            //得到统计图数据
+            $stat_arr['title'] = lang('statgoods_price_distribution');
+            $stat_arr['legend']['enabled'] = false;
+            $stat_arr['yAxis'] = lang('ds_order_sn');
+            $pricerange_statjson = getStatData_LineLabels($stat_arr);
+        } else {
+            $pricerange_statjson = '';
+        }
+
+        View::assign('pricerange_statjson',$pricerange_statjson);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('pricerange');
+        return View::fetch('stat_goods_prange');
+    }
+    /**
+     * 热卖商品
+     */
+    public function hotgoods(){
+        if(!isset($this->search_arr['search_type']) || !$this->search_arr['search_type']){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('hotgoods');
+        return View::fetch('stat_goods_hotgoods');
+    }
+    /**
+     * 热卖商品列表
+     */
+    public function hotgoods_list(){
+        $stat_model = model('stat');
+        $type=input('param.type');
+        switch ($type){
+            case 'goodsnum':
+                $sort_text = lang('statstore_ordernum');
+                break;
+            default:
+                $type = 'orderamount';
+                $sort_text = lang('statstore_orderamount');
+                break;
+        }
+        //构造横轴数据
+        for($i=1; $i<=50; $i++){
+            //数据
+            $stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
+            //横轴
+            $stat_arr['xAxis']['categories'][] = "$i";
+        }
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        //商品分类
+        if ($this->choose_gcid > 0){
+            //获得分类深度
+            $depth = $this->gc_arr[$this->choose_gcid]['depth'];
+            $where[] = array('gc_parentid_'.$depth,'=',$this->choose_gcid);
+        }
+        //查询统计数据
+        $field = ' goods_id,goods_name ';
+        switch ($type){
+            case 'goodsnum':
+                $field .= ' ,SUM(goods_num) as goodsnum ';
+                $orderby = 'goodsnum desc';
+                break;
+            default:
+                $type = 'orderamount';
+                $field .= ' ,SUM(goods_pay_price) as orderamount ';
+                $orderby = 'orderamount desc';
+                break;
+        }
+        $orderby .= ',goods_id';
+        $statlist = $stat_model->statByStatordergoods($where, $field, 0, 50, $orderby, 'goods_id');
+        foreach ((array)$statlist as $k=>$v){
+            switch ($type){
+                case 'goodsnum':
+                    $stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>intval($v[input('get.type')]));
+                    break;
+                case 'orderamount':
+                    $stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>floatval($v[input('get.type')]));
+                    break;
+            }
+            $statlist[$k]['sort'] = $k+1;
+        }
+        $stat_arr['series'][0]['name'] = $sort_text;
+        $stat_arr['legend']['enabled'] = false;
+        //得到统计图数据
+        $stat_arr['title'] = lang('statgoods_hot_top_50');
+        $stat_arr['yAxis'] = $sort_text;
+        $stat_json = getStatData_Column2D($stat_arr);
+        View::assign('stat_json',$stat_json);
+        View::assign('statlist',$statlist);
+        View::assign('sort_text',$sort_text);
+        View::assign('stat_field',$type);
+        echo View::fetch('stat_hotgoods_list');
+    }
+
+    /**
+     * 商品销售明细
+     */
+    public function goods_sale(){
+        if(!isset($this->search_arr['search_type']) || !$this->search_arr['search_type']){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        //获取相关数据
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        //品牌
+        $brand_id = intval(input('param.b_id'));
+        if ($brand_id > 0){
+            $where[] = array('brand_id','=',$brand_id);
+        }
+        //商品分类
+        if ($this->choose_gcid > 0){
+            //获得分类深度
+            $depth = $this->gc_arr[$this->choose_gcid]['depth'];
+            $where[]=array('gc_parentid_'.$depth,'=',$this->choose_gcid);
+        }
+        if(trim(input('param.goods_name'))){
+            $where[]=array('goods_name','like','%'.trim(input('param.goods_name')).'%');
+        }
+        if(trim(input('param.store_name'))){
+            $where[]=array('store_name','like','%'.trim(input('param.store_name')).'%');
+        }
+        $field = 'goods_id,goods_name,store_id,store_name,goods_commonid,SUM(goods_num) as goodsnum,COUNT(DISTINCT order_id) as ordernum,SUM(goods_pay_price) as goodsamount';
+        //排序
+        $orderby_arr = array('goodsnum asc','goodsnum desc','ordernum asc','ordernum desc','goodsamount asc','goodsamount desc');
+        if (!isset($this->search_arr['orderby']) || !in_array(trim($this->search_arr['orderby']),$orderby_arr)){
+            $this->search_arr['orderby'] = 'goodsnum desc';
+        }
+        $orderby = trim($this->search_arr['orderby']).',goods_id asc';
+        //查询记录总条数
+        $count_arr = $stat_model->getoneByStatordergoods($where, 'COUNT(DISTINCT goods_id) as countnum');
+        $countnum = intval($count_arr['countnum']);
+        if (input('param.exporttype') == 'excel'){
+            $goods_list = $stat_model->statByStatordergoods($where, $field, 0, 0, $orderby, 'goods_id');
+        } else {
+            $goods_list = $stat_model->statByStatordergoods($where, $field, 10, 0, $orderby, 'goods_id');
+        }
+        //导出Excel
+        if (input('param.exporttype') == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_goods_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('goods_commonid'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_store_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('goodsnum'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('statstore_ordernum'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('statstore_orderamount'));
+            //data
+            foreach ($goods_list as $k=>$v){
+                $excel_data[$k+1][] = array('data'=>$v['goods_name']);
+                $excel_data[$k+1][] = array('data'=>$v['goods_commonid']);
+                $excel_data[$k+1][] = array('data'=>$v['store_name']);
+                $excel_data[$k+1][] = array('data'=>$v['goodsnum']);
+                $excel_data[$k+1][] = array('data'=>$v['ordernum']);
+                $excel_data[$k+1][] = array('data'=>$v['goodsamount']);
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('stat_goods_sale'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('stat_goods_sale'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        } else {
+            //查询品牌
+            $brand_list = model('brand')->getBrandList(array('brand_apply'=>1));
+            View::assign('brand_list',$brand_list);
+            View::assign('goods_list',$goods_list);
+            View::assign('show_page',$stat_model->page_info->render());
+            View::assign('orderby',$this->search_arr['orderby']);
+            $this->setAdminCurItem('goods_sale');
+            return View::fetch('stat_goodssale');
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array('name' => 'pricerange', 'text' => lang('stat_goods_pricerange'), 'url' => (string)url('Statgoods/pricerange')),
+            array('name' => 'hotgoods', 'text' => lang('stat_hotgoods'), 'url' => (string)url('Statgoods/hotgoods')),
+            array('name' => 'goods_sale', 'text' => lang('stat_goods_sale'), 'url' => (string)url('Statgoods/goods_sale')),
+        );
+        return $menu_array;
+    }
+}

+ 494 - 0
app/admin/controller/Statindustry.php

@@ -0,0 +1,494 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statindustry extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(),array('scale','rank','price'))){
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+        /**
+         * 处理商品分类
+         */
+        $show_depth = 3;//select需要展示的深度
+        if (in_array(request()->action(),array('scale','general'))){//仅显示前两级分类
+            $show_depth = 2;
+        }
+        $gcid=input('param.choose_gcid');
+        $this->choose_gcid = $gcid >0 ? $gcid : 0;
+        $gccache_arr = model('goodsclass')->getGoodsclassCache($this->choose_gcid,$show_depth);
+        $this->gc_arr = $gccache_arr['showclass'];
+        View::assign('gc_json',json_encode($gccache_arr['showclass']));
+        View::assign('gc_choose_json',json_encode($gccache_arr['choose_gcid']));
+    }
+    /**
+     * 行业规模
+     */
+    public function scale(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('scale');
+        return View::fetch();
+    }
+    /**
+     * 行业规模列表
+     */
+    public function scale_list(){
+        //获得子分类ID
+        $gc_childid = $gc_childarr = array();
+        if (input('param.choose_gcid') > 0){//如果进行了分类搜索,则统计该分类下的子分类
+            $gc_childdepth = $this->gc_arr[input('param.choose_gcid')]['depth'] + 1;
+            $gc_childid = explode(',',$this->gc_arr[input('param.choose_gcid')]['child']);
+            if ($gc_childid){
+                foreach ((array)$this->gc_arr as $k=>$v){
+                    if (in_array($v['gc_id'],$gc_childid)){
+                        $gc_childarr[$v['gc_id']] = $v;
+                    }
+                }
+            }
+        } else {//如果没有搜索分类,则默认统计一级分类
+            $gc_childdepth = 1;
+            foreach ((array)$this->gc_arr as $k=>$v){
+                if ($v['depth'] == 1){
+                    $gc_childarr[$v['gc_id']] = $v;
+                }
+            }
+        }
+        if($gc_childarr){
+            $stat_model = model('stat');
+            $stat_list = array();
+            //构造横轴数据
+            foreach($gc_childarr as $k=>$v){
+                $stat_list[$k]['gc_name'] = $v['gc_name'];
+                $stat_list[$k]['y'] = 0;
+            }
+            $where = array();
+            $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+            $searchtime_arr_tmp = explode('|',input('param.t'));
+            foreach ((array)$searchtime_arr_tmp as $k=>$v){
+                $searchtime_arr[] = intval($v);
+            }
+            $where[] = array('order_add_time','between',$searchtime_arr);
+            if ($this->choose_gcid > 0){
+                $where[] = array('gc_parentid_'.($gc_childdepth-1),'=',$this->choose_gcid);
+            }
+            $field = 'gc_parentid_'.$gc_childdepth.' as statgc_id';
+            $stattype = input('param.stattype');
+            
+            switch ($stattype){
+                case 'ordernum':
+                    $caption = lang('statstore_ordernum');
+                    $field .= ',COUNT(DISTINCT order_id) as ordernum';
+                    $orderby = 'ordernum desc';
+                    break;
+                case 'goodsnum':
+                    $caption = lang('goodsnum');
+                    $field .= ',SUM(goods_num) as goodsnum';
+                    $orderby = 'goodsnum desc';
+                    break;
+                default:
+                    $stattype = 'orderamount';
+                    $caption = lang('statstore_orderamount');
+                    $field .= ',SUM(goods_pay_price) as orderamount';
+                    $orderby = 'orderamount desc';
+                    break;
+            }
+            $orderby .= ',statgc_id asc';
+
+            $goods_list = $stat_model->statByStatordergoods($where, $field, 0, 0, $orderby, 'statgc_id');
+            foreach ((array)$goods_list as $k=>$v){
+                $statgc_id = intval($v['statgc_id']);
+                if (in_array($statgc_id,array_keys($gc_childarr))){
+                    $stat_list[$statgc_id]['gc_name'] = strval($gc_childarr[$v['statgc_id']]['gc_name']);
+                } else {
+                    $stat_list[$statgc_id]['gc_name'] = lang('other');
+                }
+                switch ($stattype){
+                    case 'orderamount':
+                        $stat_list[$statgc_id]['y'] = floatval($v[$stattype]);
+                        break;
+                    default:
+                        $stat_list[$statgc_id]['y'] = intval($v[$stattype]);
+                        break;
+                }
+            }
+            //构造横轴数据
+            foreach($stat_list as $k=>$v){
+                //数据
+                $stat_arr['series'][0]['data'][] = array('name'=>strval($v['gc_name']),'y'=>$v['y']);
+                //横轴
+                $stat_arr['xAxis']['categories'][] = strval($v['gc_name']);
+            }
+            //得到统计图数据
+            $stat_arr['series'][0]['name'] = $caption;
+            $stat_arr['title'] = sprintf(lang('industry_statis'),$caption);
+            $stat_arr['legend']['enabled'] = false;
+            $stat_arr['yAxis']['title']['text'] = $caption;
+            $stat_arr['yAxis']['title']['align'] = 'high';
+            $statjson = getStatData_Basicbar($stat_arr);
+            View::assign('stat_json',$statjson);
+            View::assign('stattype',$stattype);
+            echo View::fetch('stat_linelabels');
+        }
+    }
+    /**
+     * 行业排行
+     */
+    public function rank(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        if ($this->choose_gcid > 0){
+            $gc_id_depth = $this->gc_arr[$this->choose_gcid]['depth'];
+            $where[] = array('gc_parentid_'.$gc_id_depth,'=',$this->choose_gcid);
+        }
+        /**
+         * 商品排行
+         */
+        $goods_stat_arr = array();
+        //构造横轴数据
+        for($i=1; $i<=50; $i++){
+            //数据
+            $goods_stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
+            //横轴
+            $goods_stat_arr['xAxis']['categories'][] = "$i";
+        }
+        $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
+        $goods_list = $stat_model->statByStatordergoods($where, $field, 0, 50, 'goodsnum desc,goods_id asc', 'goods_id');
+        foreach ((array)$goods_list as $k=>$v){
+            $goods_stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>floatval($v['goodsnum']));
+        }
+        //得到统计图数据
+        $goods_stat_arr['series'][0]['name'] = lang('goodsnum');
+        $goods_stat_arr['title'] = lang('statindustry_top_50');
+        $goods_stat_arr['legend']['enabled'] = false;
+        $goods_stat_arr['yAxis'] = lang('goodsnum');
+        $goods_statjson = getStatData_Column2D($goods_stat_arr);
+        /**
+         * 店铺排行
+         */
+        $store_stat_arr = array();
+        //构造横轴数据
+        for($i=1; $i<=30; $i++){
+            //数据
+            $store_stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
+            //横轴
+            $store_stat_arr['xAxis']['categories'][] = "$i";
+        }
+        $field = 'store_id,store_name,COUNT(DISTINCT order_id) as ordernum';
+        $store_list = $stat_model->statByStatordergoods($where, $field, 0, 30, 'ordernum desc,store_id asc', 'store_id');
+        foreach ((array)$store_list as $k=>$v){
+            $store_stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['store_name']),'y'=>floatval($v['ordernum']));
+        }
+        //得到统计图数据
+        $store_stat_arr['series'][0]['name'] = lang('statstore_ordernum');
+        $store_stat_arr['title'] = lang('statindustry_top_30');
+        $store_stat_arr['legend']['enabled'] = false;
+        $store_stat_arr['yAxis'] = lang('statstore_ordernum');
+        $store_statjson = getStatData_Column2D($store_stat_arr);
+
+        View::assign('goods_statjson',$goods_statjson);
+        View::assign('goods_list',$goods_list);
+        View::assign('store_statjson',$store_statjson);
+        View::assign('store_list',$store_list);
+        $this->setAdminCurItem('rank');
+        return View::fetch();
+    }
+    /**
+     * 价格分布
+     */
+    public function price(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        if ($this->choose_gcid > 0){
+            $gc_id_depth = $this->gc_arr[$this->choose_gcid]['depth'];
+            $where[] = array('gc_parentid_'.$gc_id_depth,'=',$this->choose_gcid);
+        }
+
+$field='1';
+        $pricerange_arr = ($t = trim(config('ds_config.stat_orderpricerange')))?unserialize($t):'';
+
+        if ($pricerange_arr){
+            $goodsnum_stat_arr['series'][0]['name'] = lang('goodsnum');
+            $orderamount_stat_arr['series'][0]['name'] = lang('statstore_orderamount');
+            //设置价格区间最后一项,最后一项只有开始值没有结束值
+            $pricerange_count = count($pricerange_arr);
+            if ($pricerange_arr[$pricerange_count-1]['e']){
+                $pricerange_arr[$pricerange_count]['s'] = $pricerange_arr[$pricerange_count-1]['e'] + 1;
+                $pricerange_arr[$pricerange_count]['e'] = '';
+            }
+        
+            foreach ((array)$pricerange_arr as $k=>$v){
+                $v['s'] = intval($v['s']);
+                $v['e'] = intval($v['e']);
+                //构造查询字段
+               if ($v['e']){
+                    $field .= ",SUM(IF(goods_pay_price/goods_num > {$v['s']} and goods_pay_price/goods_num <= {$v['e']},goods_num,0)) as goodsnum_{$k}";
+                    $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']} and goods_pay_price/goods_num <= {$v['e']},goods_pay_price,0)) as orderamount_{$k}";
+                } else {//由于最后一个区间没有结束值,所以需要单独构造sql
+                    $field .= ",SUM(IF(goods_pay_price/goods_num > {$v['s']},goods_num,0)) as goodsnum_{$k}";
+                    $field .= " ,SUM(IF(goods_pay_price/goods_num > {$v['s']},goods_pay_price,0)) as orderamount_{$k}";
+                }
+            }
+
+            $ordergooods_list = Db::query('SELECT '.$field.' FROM '.config('database.connections.mysql.prefix').'statordergoods WHERE order_isvalid=1 AND order_add_time BETWEEN '.$searchtime_arr[0].' AND '.$searchtime_arr[1].($this->choose_gcid > 0?(' AND gc_parentid_'.$gc_id_depth.'='.$this->choose_gcid):''));
+            if($ordergooods_list){
+                $ordergooods_list= current($ordergooods_list);
+                foreach ((array)$pricerange_arr as $k=>$v){
+                    //横轴
+                    if($v['e']){
+                        $goodsnum_stat_arr['xAxis']['categories'][] = $v['s'].'-'.$v['e'];
+                        $orderamount_stat_arr['xAxis']['categories'][] = $v['s'].'-'.$v['e'];
+                    } else {
+                        $goodsnum_stat_arr['xAxis']['categories'][] = $v['s'].lang('above');
+                        $orderamount_stat_arr['xAxis']['categories'][] = $v['s'].lang('above');
+                    }
+                    //统计图数据
+                    $goodsnum_stat_arr['series'][0]['data'][$k] = 0;
+                    $orderamount_stat_arr['series'][0]['data'][$k] = 0;
+                    if (isset($ordergooods_list['goodsnum_'.$k])){
+                        $goodsnum_stat_arr['series'][0]['data'][$k] = intval($ordergooods_list['goodsnum_'.$k]);
+                    }
+                    if (isset($ordergooods_list['orderamount_'.$k])){
+                        $orderamount_stat_arr['series'][0]['data'][$k] = intval($ordergooods_list['orderamount_'.$k]);
+                    }
+                }
+            }
+            //得到统计图数据
+            $goodsnum_stat_arr['legend']['enabled'] = false;
+            $goodsnum_stat_arr['title'] = lang('industry_goods_number');
+            $goodsnum_stat_arr['yAxis'] = '';
+
+            $orderamount_stat_arr['legend']['enabled'] = false;
+            $orderamount_stat_arr['title'] = lang('industry_order_amount');
+            $orderamount_stat_arr['yAxis'] = '';
+            $goodsnum_stat_json = getStatData_LineLabels($goodsnum_stat_arr);
+            $orderamount_stat_json = getStatData_LineLabels($orderamount_stat_arr);
+        } else {
+            $goodsnum_stat_json = '';
+            $orderamount_stat_json = '';
+        }
+
+        View::assign('goodsnum_stat_json',$goodsnum_stat_json);
+        View::assign('orderamount_stat_json',$orderamount_stat_json);
+        $this->setAdminCurItem('price');
+        return View::fetch();
+    }
+
+    /**
+     * 销售统计
+     */
+    public function general(){
+        $this->setAdminCurItem('general');
+        return View::fetch();
+    }
+
+    /**
+     * 概况总览
+     */
+    public function general_list(){
+        $ordergoods_list=array();
+        //获得子分类ID
+        $gc_childid = $gc_childarr = array();
+        if ($this->choose_gcid > 0){
+            $gc_childdepth = $this->gc_arr[$this->choose_gcid]['depth'] + 1;
+            $gc_childid = explode(',',$this->gc_arr[$this->choose_gcid]['child']);
+            if ($gc_childid){
+                foreach ((array)$this->gc_arr as $k=>$v){
+                    if (in_array($v['gc_id'],$gc_childid)){
+                        $gc_childarr[$v['gc_id']] = $v;
+                    }
+                }
+            }
+        } else {//如果没有搜索分类,则默认统计一级分类
+            $gc_childdepth = 1;
+            foreach ((array)$this->gc_arr as $k=>$v){
+                if ($v['depth'] == 1){
+                    $gc_childarr[$v['gc_id']] = $v;
+                }
+            }
+        }
+
+        $statlist = array();
+
+        if ($gc_childarr){
+            $stat_model = model('stat');
+            //查询订单商品信息
+            $where = array();
+            $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+            //计算开始时间和结束时间
+            $searchtime_arr[1] = strtotime(date('Y-m-d',TIMESTAMP)) - 1;//昨天23:59点
+            $searchtime_arr[0] = $searchtime_arr[1] - (86400 * 30) + 1; //从昨天开始30天前
+            $where[] = array('order_add_time','between',$searchtime_arr);
+            //halt($this->choose_gcid);
+            if ($this->choose_gcid > 0){
+                $where[] = array('gc_parentid_'.($gc_childdepth-1),'=',$this->choose_gcid);
+            }
+
+            $field = 'gc_parentid_'.$gc_childdepth.' as statgc_id,COUNT(DISTINCT goods_id) as ordergcount,SUM(goods_num) as ordergnum,SUM(goods_pay_price) as orderamount';
+            
+            $ordergoods_list_tmp = $stat_model->statByStatordergoods($where, $field, 0, 0, '', 'gc_parentid_'.$gc_childdepth);
+
+            foreach ((array)$ordergoods_list_tmp as $k=>$v){
+                $ordergoods_list[$v['statgc_id']] = $v;
+            }
+            
+            //查询商品信息
+            $field = 'gc_id_'.$gc_childdepth.' as statgc_id,COUNT(*) as goodscount,AVG(goods_price) as priceavg';
+            $goods_list_tmp = $stat_model->statByGoods(array('is_virtual'=>0), $field, 0, 0, '', 'gc_id_'.$gc_childdepth);
+
+            foreach ((array)$goods_list_tmp as $k=>$v){
+                $goods_list[$v['statgc_id']] = $v;
+            }
+            //将订单和商品数组合并
+            $statlist_tmp = array();
+            foreach ($gc_childarr as $k=>$v){
+                $tmp = array();
+                $tmp['statgc_id'] = $v['gc_id'];
+                $tmp['gc_name'] = $v['gc_name'];
+                $tmp['ordergcount'] = isset($ordergoods_list[$v['gc_id']]['ordergcount'])?$ordergoods_list[$v['gc_id']]['ordergcount']:0;
+                $tmp['ordergnum'] = isset($ordergoods_list[$v['gc_id']]['ordergnum'])?$ordergoods_list[$v['gc_id']]['ordergnum']:0;
+                $tmp['orderamount'] = isset($ordergoods_list[$v['gc_id']]['orderamount'])?$ordergoods_list[$v['gc_id']]['orderamount']:0;
+                $tmp['goodscount'] = isset($goods_list[$v['gc_id']]['goodscount'])?$goods_list[$v['gc_id']]['goodscount']:0;
+                $tmp['priceavg'] = ds_price_format(isset($goods_list[$v['gc_id']]['priceavg'])?$goods_list[$v['gc_id']]['priceavg']:0);
+                $tmp['unordergcount'] = intval($tmp['goodscount']) - intval($tmp['ordergcount']);//计算无销量商品数
+                $statlist_tmp[]= $tmp;
+            }
+            $statlist = array();
+            //整理排序
+            $orderby = isset($this->search_arr['orderby'])?trim($this->search_arr['orderby']):'';
+            if (!$orderby){
+                $orderby = 'orderamount desc';
+            }
+            $orderkeys = explode(' ',$orderby);
+            $keysvalue = $new_array = array();
+            foreach ($statlist_tmp as $k=>$v){
+                $keysvalue[$k] = $v[$orderkeys[0]];
+            }
+            if($orderkeys[1] == 'asc'){
+                asort($keysvalue);
+            }else{
+                arsort($keysvalue);
+            }
+            reset($keysvalue);
+            foreach ($keysvalue as $k=>$v){
+                $statlist[$k] = $statlist_tmp[$k];
+            }
+            //导出Excel
+            if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel'){
+                //列表header
+                $statheader = array();
+                $statheader[] = array('text'=>lang('ds_goodsclass'),'key'=>'gc_name');
+                $statheader[] = array('text'=>lang('average_price').'('.lang('ds_yuan').')','key'=>'priceavg','isorder'=>1);
+                $statheader[] = array('text'=>lang('have_sale_goods_number'),'key'=>'ordergcount','isorder'=>1);
+                $statheader[] = array('text'=>lang('ds_order_sn'),'key'=>'ordergnum','isorder'=>1);
+                $statheader[] = array('text'=>lang('stattrade_order_amount').'('.lang('ds_yuan').')','key'=>'orderamount','isorder'=>1);
+                $statheader[] = array('text'=>lang('industry_goods_total'),'key'=>'goodscount','isorder'=>1);
+                $statheader[] = array('text'=>lang('no_sale_goods_number'),'key'=>'unordergcount','isorder'=>1);
+                //导出Excel
+                $excel_obj = new \excel\Excel();
+                $excel_data = array();
+                //设置样式
+                $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+                //header
+                foreach ($statheader as $k=>$v){
+                    $excel_data[0][] = array('styleid'=>'s_title','data'=>$v['text']);
+                }
+                //data
+                foreach ($statlist as $k=>$v){
+                    foreach ($statheader as $h_k=>$h_v){
+                        $excel_data[$k+1][] = array('data'=>$v[$h_v['key']]);
+                    }
+                }
+                $excel_data = $excel_obj->charset($excel_data,CHARSET);
+                $excel_obj->addArray($excel_data);
+                $excel_obj->addWorksheet($excel_obj->charset(lang('industry_state_view'),CHARSET));
+                $excel_obj->generateXML($excel_obj->charset(lang('industry_state_view'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+                exit();
+            }
+        }
+        //列表header
+        $statheader = array();
+        $statheader[] = array('text'=>lang('ds_goodsclass'),'key'=>'gc_name');
+        $statheader[] = array('text'=>'<span title="'.lang('goods_class_average_goods_price').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('average_price').'('.lang('ds_yuan').')','key'=>'priceavg','isorder'=>1);
+        $statheader[] = array('text'=>'<span title="'.lang('have_sale_goods_number_recent').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('have_sale_goods_number'),'key'=>'ordergcount','isorder'=>1);
+        $statheader[] = array('text'=>'<span title="'.lang('industry_goods_total_recent').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('ds_order_sn'),'key'=>'ordergnum','isorder'=>1);
+        $statheader[] = array('text'=>'<span title="'.lang('have_sale_goods_amount_recent').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('stattrade_order_amount').'('.lang('ds_yuan').')','key'=>'orderamount','isorder'=>1);
+        $statheader[] = array('text'=>'<span title="'.lang('goods_class_goods_number').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('industry_goods_total'),'key'=>'goodscount','isorder'=>1);
+        $statheader[] = array('text'=>'<span title="'.lang('have_sale_goods_number_recent').'" class="tip iconfont">&#xe71c;</span>&nbsp;'.lang('no_sale_goods_number'),'key'=>'unordergcount','isorder'=>1);
+        View::assign('statheader',$statheader);
+        View::assign('statlist',$statlist);
+        View::assign('orderby',$orderby);
+        View::assign('actionurl',(string)url('Statindustry'.'/'.request()->action(),['choose_gcid'=>$this->choose_gcid]));
+        echo View::fetch('listandorder');exit;
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array = array(
+            array(
+                'name' => 'scale', 'text' => lang('stat_industryscale'), 'url' => (string)url('Statindustry/scale')
+            ), array(
+                'name' => 'rank', 'text' => lang('stat_industryrank'), 'url' => (string)url('Statindustry/rank')
+            ), array(
+                'name' => 'price', 'text' => lang('stat_industryprice'), 'url' => (string)url('Statindustry/price')
+            ),array(
+                'name' => 'general', 'text' => lang('stat_industrygeneral'), 'url' => (string)url('Statindustry/general')
+            )
+        );
+        return $menu_array;
+    }
+}

+ 367 - 0
app/admin/controller/Statmarketing.php

@@ -0,0 +1,367 @@
+<?php
+/**
+ * 市场统计分析
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use think\facade\Lang;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statmarketing extends AdminControl
+{
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(),array('promotion','group'))){
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+    }
+    /**
+     * 促销分析
+     */
+    public function promotion(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        $where[]=array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $where[]=array('goods_type','in',array(2,3,4));
+        //下单量
+        $field = ' goods_type,count(DISTINCT order_id) as ordernum,SUM(goods_num) as goodsnum,SUM(goods_pay_price) as orderamount';
+        $statlist_tmp = $stat_model->statByStatordergoods($where, $field, 0, 0,'', 'goods_type');
+        //优惠类型数组
+        $goodstype_arr = array(2=>lang('goodstype_2'),3=>lang('goodstype_3'),4=>lang('goodstype_4'));
+        $statlist = array();
+        $statcount = array('ordernum'=>0,'goodsnum'=>0,'orderamount'=>0.00);
+        $stat_arr = array();
+        $stat_json = array('ordernum'=>'','goodsnum'=>'','orderamount'=>'');
+        if ($statlist_tmp){
+            foreach((array)$statlist_tmp as $k=>$v){
+                $statcount['ordernum'] += intval($v['ordernum']);
+                $statcount['goodsnum'] += intval($v['goodsnum']);
+                $statcount['orderamount'] += floatval($v['orderamount']);
+            }
+            foreach((array)$statlist_tmp as $k=>$v){
+                $v['ordernumratio'] = round($v['ordernum']/$statcount['ordernum'],4)*100;
+                $v['goodsnumratio'] = round($v['goodsnum']/$statcount['goodsnum'],4)*100;
+                $v['orderamountratio'] = round($v['orderamount']/$statcount['orderamount'],4)*100;
+                $statlist_tmp2[$v['goods_type']] = $v;
+                $stat_arr['ordernum'][] = array('p_name'=>$goodstype_arr[$v['goods_type']],'allnum'=>$v['ordernumratio']);
+                $stat_arr['goodsnum'][] = array('p_name'=>$goodstype_arr[$v['goods_type']],'allnum'=>$v['goodsnumratio']);
+                $stat_arr['orderamount'][] = array('p_name'=>$goodstype_arr[$v['goods_type']],'allnum'=>$v['orderamountratio']);
+            }
+            foreach ($goodstype_arr as $k=>$v){
+                if (isset($statlist_tmp2[$k])){
+                    $statlist_tmp2[$k]['goodstype_text'] = $v;
+                    $statlist[] = $statlist_tmp2[$k];
+                } else {
+                    $statlist[] = array('goodstype_text'=>$k,'goodstype_text'=>$v,'ordernum'=>0,'goodsnum'=>0,'orderamount'=>0.00);
+                }
+            }
+            $stat_json['ordernum'] = getStatData_Pie(array('title'=>lang('statstore_ordernum'),'name'=>lang('statstore_ordernum').'(%)','label_show'=>false,'series'=>$stat_arr['ordernum']));
+            $stat_json['goodsnum'] = getStatData_Pie(array('title'=>lang('goodsnum'),'name'=>lang('goodsnum').'(%)','label_show'=>false,'series'=>$stat_arr['goodsnum']));
+            $stat_json['orderamount'] = getStatData_Pie(array('title'=>lang('statstore_orderamount'),'name'=>lang('statstore_orderamount').'(%)','label_show'=>false,'series'=>$stat_arr['orderamount']));
+        }
+        View::assign('statcount',$statcount);
+        View::assign('statlist',$statlist);
+        View::assign('stat_json',$stat_json);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('promotion');
+        return View::fetch('marketing_promotion');
+    }
+    /**
+     * 促销销售趋势分析
+     */
+    public function promotiontrend(){
+        //优惠类型数组
+        $goodstype_arr = array(2=>lang('goodstype_2'),3=>lang('goodstype_3'),4=>lang('goodstype_4'));
+
+        $stat_model = model('stat');
+        $where = array();
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where[]=array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $where[]=array('goods_type','in',array(2,3,4));
+        $field = ' goods_type';
+        switch ($this->search_arr['stattype']){
+            case 'orderamount':
+                $field .= " ,SUM(goods_pay_price) as orderamount";
+                $caption = lang('statstore_orderamount');
+                break;
+            case 'goodsnum':
+                $field .= " ,SUM(goods_num) as goodsnum";
+                $caption = lang('goodsnum');
+                break;
+            default:
+                $field .= " ,count(DISTINCT order_id) as ordernum";
+                $caption = lang('statstore_ordernum');
+                break;
+        }
+        if($this->search_arr['search_type'] == 'day'){
+            //构造横轴数据
+            for($i=0; $i<24; $i++){
+                //横轴
+                $stat_arr['xAxis']['categories'][] = "$i";
+                foreach ($goodstype_arr as $k=>$v){
+                    $statlist[$k][$i] = 0;
+                }
+            }
+            $field .= ' ,HOUR(FROM_UNIXTIME(order_add_time)) as timeval ';
+        }
+        if($this->search_arr['search_type'] == 'week'){
+            //构造横轴数据
+            for($i=1; $i<=7; $i++){
+                $tmp_weekarr = getSystemWeekArr();
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+                foreach ($goodstype_arr as $k=>$v){
+                    $statlist[$k][$i] = 0;
+                }
+            }
+            $field .= ' ,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as timeval ';
+        }
+        if($this->search_arr['search_type'] == 'month'){
+            //计算横轴的最大量(由于每个月的天数不同)
+            $dayofmonth = date('t',$searchtime_arr[0]);
+            //构造横轴数据
+            for($i=1; $i<=$dayofmonth; $i++){
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+                foreach ($goodstype_arr as $k=>$v){
+                    $statlist[$k][$i] = 0;
+                }
+            }
+            $field .= ' ,day(FROM_UNIXTIME(order_add_time)) as timeval ';
+        }
+        //查询数据
+        $statlist_tmp = $stat_model->statByStatordergoods($where, $field, 0, 0, '','goods_type');
+        //整理统计数组
+        if($statlist_tmp){
+            foreach($statlist_tmp as $k => $v){
+                //将数据按照不同的促销方式分组
+                foreach ($goodstype_arr as $t_k=>$t_v){
+                    if ($t_k == $v['goods_type']){
+                        switch ($this->search_arr['stattype']){
+                            case 'orderamount':
+                                $statlist[$t_k][$v['timeval']] = round($v[$this->search_arr['stattype']],2);
+                                break;
+                            case 'goodsnum':
+                                $statlist[$t_k][$v['timeval']] = intval($v[$this->search_arr['stattype']]);
+                                break;
+                            default:
+                                $statlist[$t_k][$v['timeval']] = intval($v[$this->search_arr['stattype']]);
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+        foreach ($goodstype_arr as $k=>$v){
+            $tmp = array();
+            $tmp['name'] = $v;
+            $tmp['data'] = array_values($statlist[$k]);
+            $stat_arr['series'][] = $tmp;
+        }
+        //得到统计图数据
+        $stat_arr['title'] = $caption.lang('ds_stat');
+        $stat_arr['yAxis'] = $caption;
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json',$stat_json);
+        View::assign('stattype',input('param.stattype'));
+        echo View::fetch('stat_linelabels');
+    }
+
+    /**
+     * 抢购统计
+     */
+    public function group(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+        $this->setAdminCurItem('group');
+        return View::fetch('marketing_group');
+    }
+    /**
+     * 抢购统计
+     */
+    public function grouplist(){
+        $groupbuy_model = model('groupbuy');
+        $where = array();
+        $where[]=array('groupbuy_is_vr','=',0);//不统计虚拟抢购
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+       $where[] = array('groupbuy_starttime','between',"$searchtime_arr[0],$searchtime_arr[1]");
+        $where[]=array('groupbuy_state','in',array(10,20,30));
+        $gname = trim(input('param.gname'));
+        if ($gname){
+            $where[]=array('groupbuy_name','like',"%{$gname}%");
+        }
+        $grouplist_tmp = $groupbuy_model->getGroupbuyExtendList($where,10,'groupbuy_starttime asc');
+        $grouplist=array();
+        if ($grouplist_tmp){
+            foreach ((array)$grouplist_tmp as $k=>$v){
+                $v['goodsnum'] = 0;
+                $v['ordernum'] = 0;
+                $v['orderrate'] = round(0,2);
+                $v['goodsamount'] = ds_price_format(0);
+                $grouplist[$v['groupbuy_id']] = $v;
+            }
+            //查询抢购的订单
+            $where = array();
+            $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+            $where[]=array('goods_type','=',2);//抢购
+            $where[]=array('promotions_id','in',array_keys($grouplist));
+            $field = 'promotions_id,SUM(goods_num) as goodsnum,COUNT(DISTINCT order_id) as ordernum,SUM(goods_pay_price) as goodsamount';
+            $order_list = model('stat')->statByStatordergoods($where, $field, 0, 0, '', 'promotions_id');
+            foreach ((array)$order_list as $k=>$v){
+                $grouplist[$v['promotions_id']]['goodsnum'] = $v['goodsnum'];
+                $grouplist[$v['promotions_id']]['ordernum'] = $v['ordernum'];
+                if (intval($grouplist[$v['promotions_id']]['groupbuy_views']) > 0){
+                    $grouplist[$v['promotions_id']]['orderrate'] = round(($v['ordernum']/$grouplist[$v['promotions_id']]['views'])*100,2);
+                }
+                $grouplist[$v['promotions_id']]['goodsamount'] = $v['goodsamount'];
+            }
+        }
+        View::assign('grouplist',$grouplist);
+        View::assign('show_page',$groupbuy_model->page_info->render());
+        View::assign('searchtime',input('param.t'));
+        echo View::fetch('marketing_grouplist');
+    }
+    /**
+     * 抢购商品统计
+     */
+    public function groupgoods(){
+        $stat_model = model('stat');
+        $where = array();
+        $statlist= array();
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $where[] = array('goods_type','=',2);//抢购
+        $field = " goods_id,goods_name";
+        $field .= " ,SUM(goods_num) as goodsnum";
+        $field .= " ,SUM(goods_pay_price) as goodsamount";
+        $field .= " ,SUM(IF(order_state='".ORDER_STATE_CANCEL."',goods_num,0)) as cancelgoodsnum";
+        $field .= " ,SUM(IF(order_state='".ORDER_STATE_CANCEL."',goods_pay_price,0)) as cancelgoodsamount";
+        $field .= " ,SUM(IF(order_state<>'".ORDER_STATE_CANCEL."' and order_state<>'".ORDER_STATE_NEW."',goods_num,0)) as finishgoodsnum";
+        $field .= " ,SUM(IF(order_state<>'".ORDER_STATE_CANCEL."' and order_state<>'".ORDER_STATE_NEW."',goods_pay_price,0)) as finishgoodsamount";
+        $orderby_arr = array('goodsnum asc','goodsnum desc','goodsamount asc','goodsamount desc','cancelgoodsnum asc','cancelgoodsnum desc','cancelgoodsamount asc','cancelgoodsamount desc','finishgoodsnum asc','finishgoodsnum desc','finishgoodsamount asc','finishgoodsamount desc');
+        if (!in_array(trim(@$this->search_arr['orderby']),$orderby_arr)){
+            $this->search_arr['orderby'] = 'goodsnum desc';
+        }
+        $orderby = trim($this->search_arr['orderby']).',goods_id desc';
+
+        //统计记录总条数
+        $count_arr = $stat_model->getoneByStatordergoods($where, 'count(DISTINCT goods_id) as countnum');
+        $countnum = intval($count_arr['countnum']);
+        if (@$this->search_arr['exporttype'] == 'excel'){
+            $statlist_tmp = Db::query('SELECT '.$field.' FROM '.config('database.connections.mysql.prefix').'statordergoods WHERE goods_type=2 AND order_add_time BETWEEN '.$searchtime_arr[0].' AND '.$searchtime_arr[1].' GROUP BY goods_id'.' ORDER BY '.$orderby);
+ 
+        } else {
+            $statlist_tmp = Db::query('SELECT '.$field.' FROM '.config('database.connections.mysql.prefix').'statordergoods WHERE goods_type=2 AND order_add_time BETWEEN '.$searchtime_arr[0].' AND '.$searchtime_arr[1].' GROUP BY goods_id'.' ORDER BY '.$orderby.' LIMIT '.(input('param.page')?input('param.page'):0).',10');
+
+        }
+        $statheader = array();
+        $statheader[] = array('text'=>lang('ds_goods_name'),'key'=>'goods_name','class'=>'alignleft');
+        $statheader[] = array('text'=>lang('goodsnum'),'key'=>'goodsnum','isorder'=>1);
+        $statheader[] = array('text'=>lang('statstore_orderamount'),'key'=>'goodsamount','isorder'=>1);
+        $statheader[] = array('text'=>lang('cancel_goods_number'),'key'=>'cancelgoodsnum','isorder'=>1);
+        $statheader[] = array('text'=>lang('cancel_amount'),'key'=>'cancelgoodsamount','isorder'=>1);
+        $statheader[] = array('text'=>lang('finish_goods_number'),'key'=>'finishgoodsnum','isorder'=>1);
+        $statheader[] = array('text'=>lang('finish_amount'),'key'=>'finishgoodsamount','isorder'=>1);
+        foreach ((array)$statlist_tmp as $k=>$v){
+            $tmp = $v;
+            foreach ($statheader as $h_k=>$h_v){
+                $tmp[$h_v['key']] = $v[$h_v['key']];
+                if ($h_v['key'] == 'goods_name'){
+                    $tmp[$h_v['key']] = '<a href="'.(string)url('home/Goods/index', array('goods_id' => $v['goods_id'])).'" target="_blank">'.$v['goods_name'].'</a>';
+                }
+            }
+            $statlist[] = $tmp;
+        }
+        if (@$this->search_arr['exporttype'] == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            foreach ($statheader as $k=>$v){
+                $excel_data[0][] = array('styleid'=>'s_title','data'=>$v['text']);
+            }
+            //data
+            foreach ((array)$statlist as $k=>$v){
+                foreach ($statheader as $h_k=>$h_v){
+                    $excel_data[$k+1][] = array('data'=>$v[$h_v['key']]);
+                }
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('groupbuy_goods_statis'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('groupbuy_goods_statis'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        } else {
+            View::assign('statheader',$statheader);
+            View::assign('statlist',$statlist);
+            View::assign('show_page',Db::name('statordergoods')->paginate(10,$countnum)->render());
+            View::assign('searchtime',input('param.t'));
+            View::assign('orderby',$this->search_arr['orderby']);
+            View::assign('actionurl',(string)url('Statmarketing/groupgoods',['t'=>$this->search_arr['t']]));
+            echo View::fetch('stat_listandorder');
+        }
+    }
+
+    protected function getAdminItemList()
+    {
+        $menu_array=array(
+            array('name'=>'promotion','text'=>lang('stat_promotion'),'url'=>(string)url('Statmarketing/promotion')),
+            array('name'=>'group','text'=>lang('stat_group'),'url'=>(string)url('Statmarketing/group'))
+        );
+        return $menu_array;
+    }
+}

+ 889 - 0
app/admin/controller/Statmember.php

@@ -0,0 +1,889 @@
+<?php
+
+/**
+ * 会员统计
+ *
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statmember extends AdminControl {
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/stat.lang.php');
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/member.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(), array('newmember', 'analyze', 'scale', 'area', 'buying'))) {
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+    }
+
+    /**
+     * 新增会员
+     */
+    public function newmember() {
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        $statlist = array(); //统计数据列表
+        //新增总数数组
+        $count_arr = array('up' => 0, 'curr' => 0);
+        $where = array();
+        $field = ' COUNT(*) as allnum ';
+        if ($this->search_arr['search_type'] == 'day') {
+            //构造横轴数据
+            for ($i = 0; $i < 24; $i++) {
+                //统计图数据
+                $curr_arr[$i] = 0; //今天
+                $up_arr[$i] = 0; //昨天
+                //统计表数据
+                $currlist_arr[$i]['timetext'] = $i;
+
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = $this->search_arr['day']['search_time'] + $i * 3600;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 3600;
+
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = "$i";
+            }
+            $stime = $this->search_arr['day']['search_time'] - 86400; //昨天0点
+            $etime = $this->search_arr['day']['search_time'] + 86400 - 1; //今天24点
+            //总计的查询时间
+            $count_arr['seartime'] = ($stime + 86400) . '|' . $etime;
+
+            $today_day = @date('d', $this->search_arr['day']['search_time']); //今天日期
+            $yesterday_day = @date('d', $stime); //昨天日期
+
+            $where[] = array('member_addtime','between',array($stime, $etime));
+            $field .= ' ,DAY(FROM_UNIXTIME(member_addtime)) as dayval,HOUR(FROM_UNIXTIME(member_addtime)) as hourval ';
+            $memberlist = $stat_model->statByMember($where, $field, 0, '', 'dayval,hourval');
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($today_day == $v['dayval']) {
+                        $curr_arr[$v['hourval']] = intval($v['allnum']);
+                        $currlist_arr[$v['hourval']]['val'] = intval($v['allnum']);
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }
+                    if ($yesterday_day == $v['dayval']) {
+                        $up_arr[$v['hourval']] = intval($v['allnum']);
+                        $uplist_arr[$v['hourval']]['val'] = intval($v['allnum']);
+                        $count_arr['up'] += intval($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('yestoday');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('today');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('hour'), lang('yestoday'), lang('today'), lang('compare_to'));
+            View::assign('actionurl', 'statmember/newmember?search_type=day&search_time=' . date('Y-m-d', $this->search_arr['day']['search_time']));
+        }
+
+        if ($this->search_arr['search_type'] == 'week') {
+            $current_weekarr = explode('|', $this->search_arr['week']['current_week']);
+            $stime = strtotime($current_weekarr[0]) - 86400 * 7;
+            $etime = strtotime($current_weekarr[1]) + 86400 - 1;
+            //总计的查询时间
+            $count_arr['seartime'] = ($stime + 86400 * 7) . '|' . $etime;
+
+            $up_week = @date('W', $stime); //上周
+            $curr_week = @date('W', $etime); //本周
+            //构造横轴数据
+            for ($i = 1; $i <= 7; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                $tmp_weekarr = getSystemWeekArr();
+                //统计表数据
+                $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = strtotime($current_weekarr[0]) + ($i - 1) * 86400;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+            }
+            $where[] = array('member_addtime','between',array($stime, $etime));
+            $field .= ',WEEKOFYEAR(FROM_UNIXTIME(member_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(member_addtime))+1 as dayofweekval ';
+            $memberlist = $stat_model->statByMember($where, $field, 0, '', 'weekval,dayofweekval');
+
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($up_week == intval($v['weekval'])) {
+                        $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                        $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                        $count_arr['up'] += intval($v['allnum']);
+                    }
+                    if ($curr_week == $v['weekval']) {
+                        $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                        $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }
+                }
+            }
+
+            $stat_arr['series'][0]['name'] = lang('last_week');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_week');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('week'), lang('last_week'), lang('this_week'), lang('compare_to'));
+            View::assign('actionurl', 'statmember/newmember?search_type=week&searchweek_year=' . $this->search_arr['week']['current_year'] . '&searchweek_month=' . $this->search_arr['week']['current_month'] . '&searchweek_week=' . $this->search_arr['week']['current_week']);
+        }
+
+        if ($this->search_arr['search_type'] == 'month') {
+            $stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01 -1 month");
+            $etime = getMonthLastDay($this->search_arr['month']['current_year'], $this->search_arr['month']['current_month']) + 86400 - 1;
+            //总计的查询时间
+            $count_arr['seartime'] = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01") . '|' . $etime;
+
+            $up_month = date('m', $stime);
+            $curr_month = date('m', $etime);
+            //计算横轴的最大量(由于每个月的天数不同)
+            $up_dayofmonth = date('t', $stime);
+            $curr_dayofmonth = date('t', $etime);
+            $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth;
+
+            //构造横轴数据
+            for ($i = 1; $i <= $x_max; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                //统计表数据
+                $currlist_arr[$i]['timetext'] = $i;
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01") + ($i - 1) * 86400;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1;
+
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+                unset($tmp_montharr);
+            }
+            $where[] = array('member_addtime','between',array($stime, $etime));
+            $field .= ',MONTH(FROM_UNIXTIME(member_addtime)) as monthval,day(FROM_UNIXTIME(member_addtime)) as dayval ';
+            $memberlist = $stat_model->statByMember($where, $field, 0, '', 'monthval,dayval');
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($up_month == $v['monthval']) {
+                        $up_arr[$v['dayval']] = intval($v['allnum']);
+                        $uplist_arr[$v['dayval']]['val'] = intval($v['allnum']);
+                        $count_arr['up'] += intval($v['allnum']);
+                    }
+                    if ($curr_month == $v['monthval']) {
+                        $curr_arr[$v['dayval']] = intval($v['allnum']);
+                        $currlist_arr[$v['dayval']]['val'] = intval($v['allnum']);
+                        $count_arr['curr'] += intval($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_month');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_month');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('date'), lang('last_month'), lang('this_month'), lang('compare_to'));
+            View::assign('actionurl', 'statmember/newmember?search_type=month&searchmonth_year=' . $this->search_arr['month']['current_year'] . '&searchmonth_month=' . $this->search_arr['month']['current_month']);
+        }
+
+        //计算同比
+        foreach ((array) $currlist_arr as $k => $v) {
+            $tmp = array();
+            $tmp['timetext'] = $v['timetext'];
+            $tmp['seartime'] = $v['stime'] . '|' . $v['etime'];
+            $tmp['currentdata'] = $v['val'];
+            $tmp['updata'] = $uplist_arr[$k]['val'];
+            $tmp['tbrate'] = getTb($tmp['updata'], $tmp['currentdata']);
+            $statlist['data'][] = $tmp;
+        }
+        //计算总结同比
+        $count_arr['tbrate'] = getTb($count_arr['up'], $count_arr['curr']);
+
+        //导出Excel
+        if (input('param.exporttype') == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            foreach ($statlist['headertitle'] as $v) {
+                $excel_data[0][] = array('styleid' => 's_title', 'data' => $v);
+            }
+            //data
+            foreach ($statlist['data'] as $k => $v) {
+                $excel_data[$k + 1][] = array('data' => $v['timetext']);
+                $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['updata']);
+                $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['currentdata']);
+                $excel_data[$k + 1][] = array('data' => $v['tbrate']);
+            }
+            $excel_data[count($statlist['data']) + 1][] = array('data' => lang('statstore_total'));
+            $excel_data[count($statlist['data']) + 1][] = array('format' => 'Number', 'data' => $count_arr['up']);
+            $excel_data[count($statlist['data']) + 1][] = array('format' => 'Number', 'data' => $count_arr['curr']);
+            $excel_data[count($statlist['data']) + 1][] = array('data' => $count_arr['tbrate']);
+
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('add_member_statis'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('add_member_statis'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        } else {
+            //得到统计图数据
+            $stat_arr['title'] = lang('add_member_statis');
+            $stat_arr['yAxis'] = lang('add_member_number');
+            $stat_json = getStatData_LineLabels($stat_arr);
+            View::assign('stat_json', $stat_json);
+            View::assign('statlist', $statlist);
+            View::assign('count_arr', $count_arr);
+            $this->setAdminCurItem('newmember');
+            return View::fetch('stat_newmember');
+        }
+    }
+
+    /**
+     * 会员分析
+     */
+    public function analyze() {
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //构造横轴数据
+        for ($i = 1; $i <= 15; $i++) {
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $i;
+        }
+        $stat_arr['title'] = lang('buyer_rank').'Top15';
+        $stat_arr['legend']['enabled'] = false;
+
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+
+        $where = array();
+        $where[] = array('statm_time','between', $searchtime_arr);
+        //下单量
+        $where[]=array('statm_ordernum','>', 0);
+        $field = ' statm_memberid, statm_membername, SUM(statm_ordernum) as ordernum ';
+        $ordernum_listtop15 = $stat_model->statByStatmember($where, $field, 0, 15, 'ordernum desc,statm_memberid desc', 'statm_memberid');
+        $stat_ordernum_arr = $stat_arr;
+        $stat_ordernum_arr['series'][0]['name'] = lang('statstore_ordernum');
+        $stat_ordernum_arr['series'][0]['data'] = array();
+        if (!empty($ordernum_listtop15)) {
+            for ($i = 0; $i < 15; $i++) {
+                if (isset($ordernum_listtop15[$i])) {
+                    $stat_ordernum_arr['series'][0]['data'][] = array(
+                        'name' => strval($ordernum_listtop15[$i]['statm_membername']),
+                        'y' => intval($ordernum_listtop15[$i]['ordernum'])
+                    );
+                }
+            }
+        }
+        $stat_ordernum_arr['yAxis'] = lang('statstore_ordernum');
+        $statordernum_json = getStatData_Column2D($stat_ordernum_arr);
+        unset($stat_ordernum_arr);
+        View::assign('statordernum_json', $statordernum_json);
+        View::assign('ordernum_listtop15', $ordernum_listtop15);
+
+        //下单商品件数
+        $where[]=array('statm_goodsnum','>', 0);
+        $field = ' statm_memberid, statm_membername, SUM(statm_goodsnum) as goodsnum ';
+        $goodsnum_listtop15 = $stat_model->statByStatmember($where, $field, 0, 15, 'goodsnum desc,statm_memberid desc', 'statm_memberid');
+        $stat_goodsnum_arr = $stat_arr;
+        $stat_goodsnum_arr['series'][0]['name'] = lang('goodsnum');
+        $stat_goodsnum_arr['series'][0]['data'] = array();
+        if (!empty($goodsnum_listtop15)) {
+            for ($i = 0; $i < 15; $i++) {
+                if (isset($goodsnum_listtop15[$i])) {
+                    $stat_goodsnum_arr['series'][0]['data'][] = array(
+                        'name' => strval($goodsnum_listtop15[$i]['statm_membername']),
+                        'y' => intval($goodsnum_listtop15[$i]['goodsnum'])
+                    );
+                }
+            }
+        }
+        $stat_goodsnum_arr['yAxis'] = lang('goodsnum');
+        $statgoodsnum_json = getStatData_Column2D($stat_goodsnum_arr);
+        unset($stat_goodsnum_arr);
+        View::assign('statgoodsnum_json', $statgoodsnum_json);
+        View::assign('goodsnum_listtop15', $goodsnum_listtop15);
+
+        //下单金额
+        $where[]=array('statm_orderamount','>', 0);
+        $field = ' statm_memberid, statm_membername, SUM(statm_orderamount) as orderamount ';
+        $orderamount_listtop15 = $stat_model->statByStatmember($where, $field, 0, 15, 'orderamount desc,statm_memberid desc', 'statm_memberid');
+        $stat_orderamount_arr = $stat_arr;
+        $stat_orderamount_arr['series'][0]['name'] = lang('statstore_orderamount');
+        $stat_orderamount_arr['series'][0]['data'] = array();
+        if (!empty($orderamount_listtop15)) {
+            for ($i = 0; $i < 15; $i++) {
+                if (isset($orderamount_listtop15[$i])) {
+                    $stat_orderamount_arr['series'][0]['data'][] = array(
+                        'name' => strval($orderamount_listtop15[$i]['statm_membername']),
+                        'y' => floatval($orderamount_listtop15[$i]['orderamount'])
+                    );
+                }
+            }
+        }
+        $stat_orderamount_arr['yAxis'] = lang('statstore_orderamount');
+        $statorderamount_json = getStatData_Column2D($stat_orderamount_arr);
+        unset($stat_orderamount_arr);
+        View::assign('statorderamount_json', $statorderamount_json);
+        View::assign('orderamount_listtop15', $orderamount_listtop15);
+        View::assign('searchtime', implode('|', $searchtime_arr));
+        $this->setAdminCurItem('analyze');
+        return View::fetch('stat_memberanalyze');
+    }
+
+    /**
+     * 会员分析异步详细列表
+     */
+    public function analyzeinfo() {
+        $stat_model = model('stat');
+        $where = array();
+        $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
+        foreach ((array) $searchtime_arr_tmp as $k => $v) {
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('statm_time','between', $searchtime_arr);
+        $memberlist = array();
+        //查询统计数据
+        $field = ' statm_memberid, statm_membername ';
+        $type = '';
+        switch (input('param.type')) {
+            case 'orderamount':
+                $where[]=array('statm_orderamount','>', 0);
+                $field .= ' ,SUM(statm_orderamount) as orderamount ';
+                $caption = lang('statstore_orderamount');
+                break;
+            case 'goodsnum':
+                $where[]=array('statm_goodsnum','>', 0);
+                $field .= ' ,SUM(statm_goodsnum) as goodsnum ';
+                $caption = lang('goodsnum');
+                break;
+            default:
+                $type = 'ordernum';
+                $where[]=array('statm_ordernum','>', 0);
+                $field .= ' ,SUM(statm_ordernum) as ordernum ';
+                $caption = lang('statstore_ordernum');
+                break;
+        }
+        if (input('param.exporttype') == 'excel') {
+            $memberlist = $stat_model->statByStatmember($where, $field, 0, 0, input('param.type')." desc,statm_memberid desc", 'statm_memberid');
+        } else {
+            $memberlist = $stat_model->statByStatmember($where, $field, 10, 0, input('param.type')." desc,statm_memberid desc", 'statm_memberid');
+        }
+        $curpage = ($t = intval(input('param.curpage'))) ? $t : 1;
+        foreach ((array) $memberlist as $k => $v) {
+            $v['number'] = ($curpage - 1) * 10 + $k + 1;
+            $memberlist[$k] = $v;
+        }
+        //导出Excel
+        if (input('param.exporttype') == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('statstore_number'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_name'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => $caption);
+            //data
+            foreach ($memberlist as $k => $v) {
+                $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['number']);
+                $excel_data[$k + 1][] = array('data' => $v['statm_membername']);
+                $excel_data[$k + 1][] = array('data' => $v[$type]);
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('ds_member') . $caption . lang('ds_stat'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('ds_member') . $caption . lang('ds_stat'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        } else {
+            View::assign('caption', $caption);
+            View::assign('stat_field', $type);
+            View::assign('memberlist', $memberlist);
+            View::assign('show_page', $stat_model->page_info->render());
+            echo View::fetch('stat_memberanalyze_info');
+        }
+    }
+
+    /**
+     * 查看会员列表
+     */
+    public function showmember() {
+        $stat_model = model('stat');
+        $where = array();
+        $actionurl = '';
+        if (in_array(input('param.type'), array('newbyday', 'newbyweek', 'newbymonth'))) {
+            $actionurl = (string)url('Statmember/showmember', ['type' => 'newbyday', 't' => input('param.t')]);
+            $searchtime_arr_tmp = explode('|', input('param.t'));
+            foreach ((array) $searchtime_arr_tmp as $k => $v) {
+                $searchtime_arr[] = intval($v);
+            }
+            $where[] = array('member_addtime','between',$searchtime_arr);
+        }
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel') {
+            $member_list = $stat_model->getMemberList($where);
+        } else {
+            $member_list = $stat_model->getMemberList($where, '*', 10);
+        }
+        if (is_array($member_list)) {
+            foreach ($member_list as $k => $v) {
+                $member_list[$k]['member_addtime'] = isset($v['member_addtime']) ? date('Y-m-d H:i:s', $v['member_addtime']) : '';
+                $member_list[$k]['member_logintime'] = $v['member_logintime'] ? date('Y-m-d H:i:s', $v['member_logintime']) : '';
+            }
+        }
+        //导出Excel
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_name'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('member_addtime'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('member_loginnum'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('member_logintime'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_points'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_predeposit'));
+            //data
+            foreach ($member_list as $k => $v) {
+                $excel_data[$k + 1][] = array('data' => $v['member_name'] . '(' . lang('member_truename') . lang('ds_colon') . $v['member_truename'] . ')');
+                $excel_data[$k + 1][] = array('data' => $v['member_addtime']);
+                $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['member_loginnum']);
+                $excel_data[$k + 1][] = array('data' => $v['member_logintime'] . '(IP:' . $v['member_login_ip'] . ')');
+                $excel_data[$k + 1][] = array('data' => $v['member_points']);
+                $excel_data[$k + 1][] = array('data' => lang('member_index_available') . lang('ds_colon') . $v['available_predeposit'] . lang('ds_yuan') . '(' . lang('member_index_frozen') . lang('ds_colon') . $v['freeze_predeposit'] . lang('ds_yuan') . ')');
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('stat_newmember'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('stat_newmember'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        }
+        View::assign('actionurl', $actionurl);
+        View::assign('member_list', $member_list);
+        View::assign('show_page', $stat_model->page_info->render());
+        $this->setAdminCurItem('showmember');
+        return View::fetch('memberlist');
+    }
+
+    /**
+     * 会员规模
+     */
+    public function scale() {
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        $statlist = array(); //统计数据列表
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        $where[] = array('statm_time','between', $searchtime_arr);
+        if (trim(isset($this->search_arr['membername']))) {
+            $where[]=array('statm_membername','like', "%" . trim($this->search_arr['membername']) . "%");
+        }
+        $field = ' statm_memberid, statm_membername, statm_time, SUM(statm_orderamount) as orderamount, SUM(statm_predincrease) as predincrease, -SUM(statm_predreduce) as predreduce, SUM(statm_pointsincrease) as pointsincrease, -SUM(statm_pointsreduce) as pointsreduce ';
+        //排序
+        $orderby_arr = array('orderamount asc', 'orderamount desc', 'predincrease asc', 'predincrease desc', 'predreduce asc', 'predreduce desc', 'pointsincrease asc', 'pointsincrease desc', 'pointsreduce asc', 'pointsreduce desc');
+        if (!in_array(trim(isset($this->search_arr['orderby'])), $orderby_arr)) {
+            $this->search_arr['orderby'] = 'orderamount desc';
+        }
+        $orderby = trim($this->search_arr['orderby']) . ',statm_memberid desc';
+
+        if (input('param.exporttype') == 'excel') {
+            $statlist = $stat_model->statByStatmember($where, $field, 0, 0, $orderby, 'statm_memberid');
+        } else {
+            $statlist = $stat_model->statByStatmember($where, $field, 10, 0, $orderby, 'statm_memberid');
+        }
+        //导出Excel
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_name'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('statstore_orderamount'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('predincrease'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('predreduce'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('pointsincrease'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('pointsreduce'));
+            //data
+            foreach ($statlist as $k => $v) {
+                $excel_data[$k + 1][] = array('data' => $v['statm_membername']);
+                $excel_data[$k + 1][] = array('data' => $v['orderamount']);
+                $excel_data[$k + 1][] = array('data' => $v['predincrease']);
+                $excel_data[$k + 1][] = array('data' => $v['predreduce']);
+                $excel_data[$k + 1][] = array('data' => $v['pointsincrease']);
+                $excel_data[$k + 1][] = array('data' => $v['pointsreduce']);
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('stat_scaleanalyze'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('stat_scaleanalyze'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        }
+        View::assign('statlist', $statlist);
+        View::assign('show_page', $stat_model->page_info->render());
+        View::assign('orderby', $this->search_arr['orderby']);
+        $this->setAdminCurItem('scale');
+        return View::fetch('stat_memberscale');
+    }
+
+    /**
+     * 区域分析
+     */
+    public function area() {
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime', implode('|', $searchtime_arr));
+        $this->setAdminCurItem('area');
+        return View::fetch('stat_memberarea');
+    }
+
+    /**
+     * 区域分析之详细列表
+     */
+    public function area_list() {
+        $stat_model = model('stat');
+        $where = array();
+        $where[] = array('order_isvalid','=',1); //计入统计的有效订单
+        $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
+        foreach ((array) $searchtime_arr_tmp as $k => $v) {
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $field = ' reciver_province_id, COUNT(*) as ordernum,SUM(order_amount) as orderamount, COUNT(DISTINCT buyer_id) as membernum ';
+
+        $orderby_arr = array('membernum asc', 'membernum desc', 'orderamount asc', 'orderamount desc', 'ordernum asc', 'ordernum desc');
+        if (!isset($this->search_arr['orderby']) || !in_array(trim($this->search_arr['orderby']), $orderby_arr)) {
+            $this->search_arr['orderby'] = 'membernum desc';
+        }
+        $orderby = trim($this->search_arr['orderby']) . ',reciver_province_id';
+
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel') {
+            $statlist_tmp = $stat_model->statByStatorder($where, $field, 0, 0, $orderby, 'reciver_province_id');
+        } else {
+            $statlist_tmp = $stat_model->statByStatorder($where, $field, 10, 0, $orderby, 'reciver_province_id');
+        }
+        // 地区
+        $province_array = model('area')->getTopLevelAreas();
+        $statheader = array();
+        $statheader[] = array('text' => lang('statestore_province'), 'key' => 'provincename');
+        $statheader[] = array('text' => lang('membernum'), 'key' => 'membernum', 'isorder' => 1);
+        $statheader[] = array('text' => lang('statstore_orderamount'), 'key' => 'orderamount', 'isorder' => 1);
+        $statheader[] = array('text' => lang('statstore_ordernum'), 'key' => 'ordernum', 'isorder' => 1);
+        $statlist = array();
+        foreach ((array) $statlist_tmp as $k => $v) {
+            $province_id = intval($v['reciver_province_id']);
+            $tmp = array();
+            $tmp['provincename'] = ($t = $province_array[$province_id]) ? $t : lang('other');
+            $tmp['membernum'] = $v['membernum'];
+            $tmp['orderamount'] = $v['orderamount'];
+            $tmp['ordernum'] = $v['ordernum'];
+            $statlist[] = $tmp;
+        }
+        //导出Excel
+        if (isset($this->search_arr['exporttype']) && $this->search_arr['exporttype'] == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            foreach ($statheader as $k => $v) {
+                $excel_data[0][] = array('styleid' => 's_title', 'data' => $v['text']);
+            }
+            //data
+            foreach ($statlist as $k => $v) {
+                foreach ($statheader as $h_k => $h_v) {
+                    $excel_data[$k + 1][] = array('data' => $v[$h_v['key']]);
+                }
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('stat_areaanalyze'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('stat_areaanalyze'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        }
+        View::assign('statlist', $statlist);
+        View::assign('statheader', $statheader);
+        View::assign('orderby', $this->search_arr['orderby']);
+        View::assign('actionurl', (string)url('Statmember/area_list', ['t' => $this->search_arr['t']]));
+        View::assign('show_page', $stat_model->page_info->render());
+        $this->setAdminCurItem('area');
+        echo View::fetch('stat_listandorder');
+    }
+
+    /**
+     * 区域分析之地图数据
+     */
+    public function area_map() {
+        $stat_model = model('stat');
+        $where = array();
+        $where[] = array('order_isvalid','=',1); //计入统计的有效订单
+        $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
+        foreach ((array) $searchtime_arr_tmp as $k => $v) {
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $memberlist = array();
+        //查询统计数据
+        $field = ' reciver_province_id ';
+        $type = input('param.type');
+        switch ($type) {
+            case 'orderamount':
+                $field .= ' ,SUM(order_amount) as orderamount ';
+                $orderby = 'orderamount desc';
+                break;
+            case 'ordernum':
+                $field .= ' ,COUNT(*) as ordernum ';
+                $orderby = 'ordernum desc';
+                break;
+            default:
+                $type = 'membernum';
+                $field .= ' ,COUNT(DISTINCT buyer_id) as membernum ';
+                $orderby = 'membernum desc';
+                break;
+        }
+        $orderby .= ',reciver_province_id';
+        $statlist_tmp = $stat_model->statByStatorder($where, $field, 10, 0, $orderby, 'reciver_province_id');
+        // 地区
+        $province_array = model('area')->getTopLevelAreas();
+        //地图显示等级数组
+        $level_arr = array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9), array(10, 11, 12));
+        $statlist = array();
+        foreach ((array) $statlist_tmp as $k => $v) {
+            $v['level'] = 4; //排名
+            foreach ($level_arr as $lk => $lv) {
+                if (in_array($k + 1, $lv)) {
+                    $v['level'] = $lk; //排名
+                }
+            }
+            $province_id = intval($v['reciver_province_id']);
+            $statlist[$province_id] = $v;
+        }
+        $stat_arr = array();
+        foreach ((array) $province_array as $k => $v) {
+            if (!empty($statlist[$k])) {
+                switch ($type) {
+                    case 'orderamount':
+                        $des = ",下单金额:{$statlist[$k]['orderamount']}";
+                        break;
+                    case 'ordernum':
+                        $des = ",下单量:{$statlist[$k]['ordernum']}";
+                        break;
+                    default:
+                        $des = ",下单会员数:{$statlist[$k]['membernum']}";
+                        break;
+                }
+                $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => $des, 'level' => $statlist[$k]['level']);
+            } else {
+                $des = ",无订单数据";
+                $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => $des, 'level' => 4);
+            }
+        }
+        $stat_json = getStatData_Map($stat_arr);
+        View::assign('stat_field', $type);
+        View::assign('stat_json', $stat_json);
+        echo View::fetch('stat_map');
+    }
+
+    /**
+     * 购买分析
+     */
+    public function buying() {
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        /*
+         * 客单价分布
+         */
+        $where = array();
+        $where[] = array('order_isvalid','=',1); //计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+
+        $field = '1';
+        $pricerange_arr = ($t = trim(config('ds_config.stat_orderpricerange'))) ? unserialize($t) : '';
+        if ($pricerange_arr) {
+            $stat_arr['series'][0]['name'] = lang('statstore_ordernum');
+            //设置价格区间最后一项,最后一项只有开始值没有结束值
+            $pricerange_count = count($pricerange_arr);
+            if ($pricerange_arr[$pricerange_count - 1]['e']) {
+                $pricerange_arr[$pricerange_count]['s'] = $pricerange_arr[$pricerange_count - 1]['e'] + 1;
+                $pricerange_arr[$pricerange_count]['e'] = '';
+            }
+            foreach ((array) $pricerange_arr as $k => $v) {
+                $v['s'] = intval($v['s']);
+                $v['e'] = intval($v['e']);
+                //构造查询字段
+                if ($v['e']) {
+                    $field .= " ,SUM(IF(order_amount > {$v['s']} and order_amount <= {$v['e']},1,0)) as ordernum_{$k}";
+                } else {
+                    $field .= " ,SUM(IF(order_amount > {$v['s']},1,0)) as ordernum_{$k}";
+                }
+            }
+            $orderlist = Db::query('SELECT ' . $field . ' FROM ' . config('database.connections.mysql.prefix') . 'statorder WHERE order_isvalid=1 AND order_add_time BETWEEN ' . $searchtime_arr[0] . ' AND ' . $searchtime_arr[1]);
+            if ($orderlist) {
+                $orderlist = current($orderlist);
+                foreach ((array) $pricerange_arr as $k => $v) {
+                    //横轴
+                    if ($v['e']) {
+                        $stat_arr['xAxis']['categories'][] = $v['s'] . '-' . $v['e'];
+                    } else {
+                        $stat_arr['xAxis']['categories'][] = $v['s'] . lang('above');
+                    }
+                    //统计图数据
+                    if (isset($orderlist['ordernum_' . $k])) {
+                        $stat_arr['series'][0]['data'][] = intval($orderlist['ordernum_' . $k]);
+                    } else {
+                        $stat_arr['series'][0]['data'][] = 0;
+                    }
+                }
+            }
+            //得到统计图数据
+            $stat_arr['title'] = lang('statmember_per_member_price_distribution');
+            $stat_arr['legend']['enabled'] = false;
+            $stat_arr['yAxis'] = lang('statstore_ordernum');
+            $guestprice_statjson = getStatData_LineLabels($stat_arr);
+        } else {
+            $guestprice_statjson = '';
+        }
+        unset($stat_arr);
+
+        /*
+         * 购买频次分析
+         */
+        //统计期间会员下单量
+        $where = array();
+        $where[] = array('statm_time','between', $searchtime_arr);
+        $where[] = array('statm_ordernum','>', 0);
+        $field = 'COUNT(*) as countnum';
+        $countnum_arr = $stat_model->getOneStatmember($where, $field);
+        $countnum = intval($countnum_arr['countnum']);
+        $member_arr = array();
+        for ($i = 0; $i < $countnum; $i += 1000) {//由于数据库底层的限制,所以每次查询1000条
+            $statmember_list = Db::name('statmember')->field('statm_memberid,statm_ordernum')->where($where)->page($i,1000)->group('statm_id')->select()->toArray();
+            foreach ((array) $statmember_list as $k => $v) {
+                $member_arr[$v['statm_memberid']] = isset($member_arr[$v['statm_memberid']])?intval($member_arr[$v['statm_memberid']]):0 + intval($v['statm_ordernum']);
+            }
+        }
+        $stattimes_arr = array();
+        if ($member_arr) {
+            //整理期间各个频次的下单客户数
+            for ($i = 1; $i <= 10; $i++) {
+                $stattimes_arr[$i] = array('num' => 0, 'rate' => 0.00);
+                if ($i >= 10) {
+                    $stattimes_arr[$i]['text'] = sprintf(lang('buy_time_info'),10);
+                } else {
+                    $stattimes_arr[$i]['text'] = sprintf(lang('buy_time_info'),$i);
+                }
+            }
+            foreach ($member_arr as $k => $v) {
+                if ($v >= 10) {
+                    $stattimes_arr[10]['num'] = intval($stattimes_arr[10]['num']) + 1;
+                } else {
+                    $stattimes_arr[$v]['num'] = intval($stattimes_arr[$v]['num']) + 1;
+                }
+            }
+            //计算期间各个频次的下单客户数占总数比例
+            foreach ($stattimes_arr as $k => $v) {
+                $stattimes_arr[$k]['rate'] = round(intval($v['num']) / count($member_arr) * 100, 2);
+            }
+        }
+
+        //购买时段分布
+        $where = array();
+        $where[] = array('order_isvalid','=',1); //计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $field = ' HOUR(FROM_UNIXTIME(order_add_time)) as hourval,COUNT(*) as ordernum ';
+        $orderlist = $stat_model->statByStatorder($where, $field, 0, 0, '', 'hourval');
+        $stat_arr = array();
+        $stat_arr['series'][0]['name'] = lang('statstore_ordernum');
+        //构造横轴坐标
+        for ($i = 0; $i < 24; $i++) {
+            //横轴
+            $stat_arr['xAxis']['categories'][] = $i;
+            $stat_arr['series'][0]['data'][$i] = 0;
+        }
+        foreach ((array) $orderlist as $k => $v) {
+            //统计图数据
+            $stat_arr['series'][0]['data'][$v['hourval']] = intval($v['ordernum']);
+        }
+        //得到统计图数据
+        $stat_arr['title'] = lang('statmember_time_distribution');
+        $stat_arr['legend']['enabled'] = false;
+        $stat_arr['yAxis'] = lang('statstore_ordernum');
+        $hour_statjson = getStatData_LineLabels($stat_arr);
+
+        View::assign('hour_statjson', $hour_statjson);
+        View::assign('stattimes_arr', $stattimes_arr);
+        View::assign('guestprice_statjson', $guestprice_statjson);
+        $this->setAdminCurItem('buying');
+        return View::fetch('stat_buying');
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array('name' => 'newmember', 'text' => lang('stat_newmember'), 'url' => (string)url('Statmember/newmember')),
+            array('name' => 'analyze', 'text' => lang('stat_memberanalyze'), 'url' => (string)url('Statmember/analyze')),
+            array('name' => 'scale', 'text' => lang('stat_scaleanalyze'), 'url' => (string)url('Statmember/scale')),
+            array('name' => 'area', 'text' => lang('stat_areaanalyze'), 'url' => (string)url('Statmember/area')),
+            array('name' => 'buying', 'text' => lang('stat_buying'), 'url' => (string)url('Statmember/buying')),
+            array('name' => 'showmember', 'text' => lang('stat_memberlist'), 'url' => (string)url('Statmember/showmember'))
+        );
+        return $menu_array;
+    }
+
+}

+ 932 - 0
app/admin/controller/Statstore.php

@@ -0,0 +1,932 @@
+<?php
+/**
+ * 店铺统计
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Db;
+use excel\Excel;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Statstore extends AdminControl
+{
+    private $search_arr;//处理后的参数
+    private $store_class;//店铺分类
+
+    public function initialize()
+    {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        if (in_array(request()->action(),array('hotrank','storesales'))){
+            $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+            //获得系统年份
+            $year_arr = getSystemYearArr();
+            //获得系统月份
+            $month_arr = getSystemMonthArr();
+            //获得本月的周时间段
+            $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+            View::assign('year_arr', $year_arr);
+            View::assign('month_arr', $month_arr);
+            View::assign('week_arr', $week_arr);
+        }
+        View::assign('search_arr', $this->search_arr);
+        //店铺分类
+        $this->store_class = rkcache('storeclass', true);
+        View::assign('store_class', $this->store_class);
+    }
+
+    /**
+     * 新增店铺
+     */
+    public function newstore(){
+        //导出excel连接地址
+        $actionurl = (string)url('Statstore/newstore');
+        $where = array();
+        //所属店铺分类
+        $search_sclass = intval(input('param.search_sclass'));
+        if ($search_sclass > 0){
+            $where[] = array('storeclass_id','=',$search_sclass);;
+            $actionurl .= "&search_sclass=$search_sclass";
+        }
+        $field = ' count(*) as allnum ';
+        if(!input('param.search_type')){
+            $search_type = 'day';
+        }
+        else{
+            $search_type = input('param.search_type');
+        }
+        //初始化时间
+        //天
+
+        if(!input('param.search_time')) {
+            $search_times = date('Y-m-d', TIMESTAMP - 86400);
+        }else {
+            $search_times = input('param.search_time');
+        }
+        $search_time = strtotime($search_times);//搜索的时间
+        View::assign('search_time',$search_times);
+        //周
+        if(!input('param.search_time_year')) {
+            $search_time_year = date('Y', TIMESTAMP);
+        }else {
+            $search_time_year = input('param.search_time_year');
+        }
+        if(!input('param.search_time_month')) {
+            $search_time_month = date('m', TIMESTAMP);
+        }else {
+            $search_time_month = input('param.search_time_month');
+        }
+        if(!input('param.search_time_week')) {
+            $search_time_week = implode('|', getWeek_SdateAndEdate(TIMESTAMP));
+        }else {
+            $search_time_week = input('param.search_time_week');
+        }
+        $current_year =$search_time_year;
+        $current_month =$search_time_month;
+        $current_week = $search_time_week;
+
+        $year_arr = getSystemYearArr();
+        $month_arr = getSystemMonthArr();
+        $week_arr = getMonthWeekArr($current_year, $current_month);
+
+        View::assign('current_year', $current_year);
+        View::assign('current_month', $current_month);
+        View::assign('current_week', $current_week);
+        View::assign('year_arr', $year_arr);
+        View::assign('month_arr', $month_arr);
+        View::assign('week_arr', $week_arr);
+
+        $stat_model = model('stat');
+        $statlist = array();//统计数据列表
+        if($search_type == 'day'){
+            //构造横轴数据
+            for($i=0; $i<24; $i++){
+                //统计图数据
+                $curr_arr[$i] = 0;//今天
+                $up_arr[$i] = 0;//昨天
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $i;
+                $currlist_arr[$i]['timetext'] = $i;
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = $search_time+$i*3600;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime']+3600;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = "$i";
+            }
+            $stime = $search_time - 86400;//昨天0点
+            $etime = $search_time + 86400 - 1;//今天24点
+
+            $today_day = @date('d', $search_time);//今天日期
+            $yesterday_day = @date('d', $stime);//昨天日期
+
+            $where[] = array('store_addtime','between',array($stime,$etime));
+            $field .= ' ,DAY(FROM_UNIXTIME(store_addtime)) as dayval,HOUR(FROM_UNIXTIME(store_addtime)) as hourval ';
+            $memberlist = $stat_model->getNewStoreStatList($where, $field, 0, '', 0, 'dayval,dayval');
+            if($memberlist){
+                foreach($memberlist as $k => $v){
+                    if($today_day == $v['dayval']){
+                        $curr_arr[$v['hourval']] = intval($v['allnum']);
+                        $currlist_arr[$v['hourval']]['val'] = intval($v['allnum']);
+                    }
+                    if($yesterday_day == $v['dayval']){
+                        $up_arr[$v['hourval']] = intval($v['allnum']);
+                        $uplist_arr[$v['hourval']]['val'] = intval($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('yestoday');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('today');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('hour'),lang('yestoday'),lang('today'),lang('compare_to'));
+            View::assign('actionurl',$actionurl.'&search_type=day&search_time='.date('Y-m-d',$search_time));
+        }
+
+        if($search_type == 'week'){
+            $current_weekarr = explode('|', $current_week);
+            $stime = strtotime($current_weekarr[0])-86400*7;
+            $etime = strtotime($current_weekarr[1])+86400-1;
+            $up_week = @date('W', $stime);//上周
+            $curr_week = @date('W', $etime);//本周
+            //构造横轴数据
+            for($i=1; $i<=7; $i++){
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                $tmp_weekarr = getSystemWeekArr();
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = strtotime($current_weekarr[0])+($i-1)*86400;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime']+86400 - 1;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+            }
+            $where[] = array('store_addtime','between',array($stime,$etime));
+            $field .= ',WEEKOFYEAR(FROM_UNIXTIME(store_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(store_addtime))+1 as dayofweekval ';
+            $memberlist = $stat_model->getNewStoreStatList($where, $field, 0, '', 0, 'weekval,dayofweekval');
+            if($memberlist){
+                foreach($memberlist as $k=>$v){
+                    if ($up_week == $v['weekval']){
+                        $up_arr[$v['dayofweekval']] = intval($v['allnum']);
+                        $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    }
+                    if ($curr_week == $v['weekval']){
+                        $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
+                        $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_week');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_week');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('week'),lang('last_week'),lang('this_week'),lang('compare_to'));
+            View::assign('actionurl',$actionurl.'&search_type=week&search_time_year='.$current_year.'&search_time_month='.$current_month.'&search_time_week='.$current_week);
+        }
+
+        if($search_type == 'month'){
+            $stime = strtotime($current_year.'-'.$current_month."-01 -1 month");
+            $etime = getMonthLastDay($current_year,$current_month)+86400-1;
+
+            $up_month = date('m',$stime);
+            $curr_month = date('m',$etime);
+            //计算横轴的最大量(由于每个月的天数不同)
+            $up_dayofmonth = date('t',$stime);
+            $curr_dayofmonth = date('t',$etime);
+            $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth;
+
+            //构造横轴数据
+            for($i=1; $i<=$x_max; $i++){
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $i;
+                $currlist_arr[$i]['timetext'] = $i;
+                //方便搜索会员列表,计算开始时间和结束时间
+                $currlist_arr[$i]['stime'] = strtotime($current_year.'-'.$current_month."-01")+($i-1)*86400;
+                $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime']+86400 - 1;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+            }
+            $where[] = array('store_addtime','between',array($stime,$etime));
+            $field .= ',MONTH(FROM_UNIXTIME(store_addtime)) as monthval,day(FROM_UNIXTIME(store_addtime)) as dayval ';
+            $memberlist = $stat_model->getNewStoreStatList($where, $field, 0, '', 0,'monthval,dayval');
+            if($memberlist){
+                foreach($memberlist as $k=>$v){
+                    if ($up_month == $v['monthval']){
+                        $up_arr[$v['dayval']] = intval($v['allnum']);
+                        $uplist_arr[$v['dayval']]['val'] = intval($v['allnum']);
+                    }
+                    if ($curr_month == $v['monthval']){
+                        $curr_arr[$v['dayval']] = intval($v['allnum']);
+                        $currlist_arr[$v['dayval']]['val'] = intval($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_month');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_month');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('date'),lang('last_month'),lang('this_month'),lang('compare_to'));
+            View::assign('actionurl',$actionurl.'&search_type=month&search_time_year='.$current_year.'&search_time_month='.$current_month);
+        }
+
+        //计算同比
+        foreach ((array)$currlist_arr as $k=>$v){
+            $tmp = array();
+            $tmp['seartime'] = $v['stime'].'|'.$v['etime'];
+            $tmp['timetext'] = $v['timetext'];
+            $tmp['currentdata'] = $v['val'];
+            $tmp['updata'] = $uplist_arr[$k]['val'];
+            $tmp['tbrate'] = getTb($tmp['updata'], $tmp['currentdata']);
+            $statlist['data'][]  = $tmp;
+        }
+
+        //导出Excel
+        if (input('param.exporttype') == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            foreach ($statlist['headertitle'] as $v){
+                $excel_data[0][] = array('styleid'=>'s_title','data'=>$v);
+            }
+            //data
+            foreach ($statlist['data'] as $k=>$v){
+                $excel_data[$k+1][] = array('data'=>$v['timetext']);
+                $excel_data[$k+1][] = array('format'=>'Number','data'=>$v['updata']);
+                $excel_data[$k+1][] = array('format'=>'Number','data'=>$v['currentdata']);
+                $excel_data[$k+1][] = array('data'=>$v['tbrate']);
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('add_store_statis'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('add_store_statis'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        } else {
+            //得到统计图数据
+            $stat_arr['title'] = lang('add_store_statis');
+            $stat_arr['yAxis'] = lang('add_store_number');
+            $stat_json = getStatData_LineLabels($stat_arr);
+            View::assign('stat_json',$stat_json);
+            View::assign('statlist',$statlist);
+            $this->setAdminCurItem('newstore');
+           return View::fetch('stat_newstore');
+        }
+    }
+    /**
+     * 热卖排行
+     */
+    public function hotrank(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+		//周
+        if(!input('param.search_time_year')) {
+            $search_time_year = date('Y', TIMESTAMP);
+        }else {
+            $search_time_year = input('param.search_time_year');
+        }
+        if(!input('param.search_time_month')) {
+            $search_time_month = date('m', TIMESTAMP);
+        }else {
+            $search_time_month = input('param.search_time_month');
+        }
+        if(!input('param.search_time_week')) {
+            $search_time_week = implode('|', getWeek_SdateAndEdate(TIMESTAMP));
+        }else {
+            $search_time_week = input('param.search_time_week');
+        }
+        $current_year =$search_time_year;
+        $current_month =$search_time_month;
+        $current_week = $search_time_week;
+
+
+        View::assign('current_year', $current_year);
+        View::assign('current_month', $current_month);
+        View::assign('current_week', $current_week);
+        $this->setAdminCurItem('hotrank');
+       return View::fetch('store_hotrank');
+    }
+    /**
+     * 热卖排行列表
+     */
+    public function hotrank_list(){
+        $datanum = 30;
+        $stat_model = model('stat');
+        $type = input('param.type');
+        switch ($type){
+            case 'ordernum':
+                $sort_text = lang('statstore_ordernum');
+                break;
+            default:
+                $type = 'orderamount';
+                $sort_text = lang('statstore_orderamount');
+                break;
+        }
+        $where = array();
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        //店铺分类
+        $search_sclass = intval(input('param.search_sclass'));
+        if ($search_sclass){
+            $where[] = array('storeclass_id','=',$search_sclass);
+        }
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        //查询统计数据
+        $field = ' store_id,store_name ';
+        switch ($type){
+            case 'ordernum':
+                $field .= ' ,COUNT(*) as ordernum ';
+                $orderby = 'ordernum desc';
+                break;
+            default:
+               $type = 'orderamount';
+                $field .= ' ,SUM(order_amount) as orderamount ';
+                $orderby = 'orderamount desc';
+                break;
+        }
+        $orderby .= ',store_id';
+        $statlist = $stat_model->statByStatorder($where, $field, 0, $datanum, $orderby, 'store_id');
+        foreach ((array)$statlist as $k=>$v){
+            $statlist[$k]['sort'] = $k+1;
+        }
+        /**
+         * 飙升榜
+         */
+        $soaring_statlist = array();//飙升榜数组
+        //查询期间产生订单的店铺数
+        $where = array();
+        //店铺分类
+        $search_sclass = intval(input('param.search_sclass'));
+        if ($search_sclass){
+            $where[] = array('storeclass_id','=',$search_sclass);
+        }
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        $field = 'COUNT(*) as countnum';
+        $countnum = $stat_model->getoneByStatorder($where, $field);
+        $countnum = $countnum['countnum'];
+        if ($countnum > 0){
+            $store_arr = array();
+            $field = 'store_id,store_name,order_amount';
+            for ($i=0; $i<$countnum; $i+=1000){//由于数据库底层的限制,所以每次查询1000条
+                $order_list = array();
+                $order_list = Db::name('statorder')->field($field)->where($where)->page($i,1000)->order('order_id')->select()->toArray();
+                foreach ((array)$order_list as $k=>$v){
+                    if(!isset($store_arr[$v['store_id']])){
+                      $store_arr[$v['store_id']]=array();
+                      $store_arr[$v['store_id']]['orderamount'] = 0;
+                      $store_arr[$v['store_id']]['ordernum'] = 0;
+                    }
+                    $store_arr[$v['store_id']]['orderamount'] = $store_arr[$v['store_id']]['orderamount'] + $v['order_amount'];
+                    $store_arr[$v['store_id']]['ordernum'] = intval($store_arr[$v['store_id']]['ordernum']) + 1;
+                    $store_arr[$v['store_id']]['store_name'] = $v['store_name'];
+                    $store_arr[$v['store_id']]['store_id'] = $v['store_id'];
+                }
+            }
+            //查询同一时间周期相比的环比数值
+            $where = array();
+            $stime = $searchtime_arr[0] - ($searchtime_arr[1] - $searchtime_arr[0]) - 1;
+            $etime = $searchtime_arr[0] - 1;
+            //店铺分类
+            $search_sclass = intval($_REQUEST['search_sclass']);
+            if ($search_sclass){
+                $where[] = array('storeclass_id','=',$search_sclass);
+            }
+            $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+            $where[] = array('order_add_time','between',array($stime,$etime));
+            $field = 'COUNT(*) as up_countnum';
+            $up_countnum = $stat_model->getoneByStatorder($where, $field);
+            $up_countnum = $up_countnum['up_countnum'];
+            $up_store_arr = array();
+            if ($up_countnum > 0){
+                $field = 'store_id,store_name,order_amount';
+                for ($i=0; $i<$up_countnum; $i+=1000){//由于数据库底层的限制,所以每次查询1000条
+                    $order_list = array();
+                    $order_list = Db::name('statorder')->field($field)->where($where)->page($i,1000)->order('store_id')->select()->toArray();
+                    foreach ((array)$order_list as $k=>$v){
+                        if(!isset($up_store_arr[$v['store_id']])){
+                            $up_store_arr[$v['store_id']]=array('orderamount'=>0,'ordernum'=>0);
+                        }
+                        $up_store_arr[$v['store_id']]['orderamount'] = $up_store_arr[$v['store_id']]['orderamount'] + $v['order_amount'];
+                        $up_store_arr[$v['store_id']]['ordernum'] = intval($up_store_arr[$v['store_id']]['ordernum']) + 1;
+                    }
+                }
+            }
+            //计算环比飙升数值
+            $soaring_arr = array();
+            foreach ((array)$store_arr as $k=>$v){
+                if (isset($up_store_arr[$k][$type]) && $up_store_arr[$k][$type] > 0){//上期数值大于0,则计算飙升值,否则不计入统计
+                    $soaring_arr[$k] = round((($v[$type]-$up_store_arr[$k][$type])/$up_store_arr[$k][$type]*100),2);
+                }
+            }
+            arsort($soaring_arr);//降序排列数组
+            $i = 1;
+            //取出前10名飙升店铺
+            foreach ((array)$soaring_arr as $k=>$v){
+                if ($i <= $datanum){
+                    $tmp = array();
+                    $tmp['sort'] = $i;
+                    $tmp['store_name'] = $store_arr[$k]['store_name'];
+                    $tmp['store_id'] = $store_arr[$k]['store_id'];
+                    $tmp['hb'] = $v;
+                    switch ($type){
+                        case 'ordernum':
+                            $tmp['ordernum'] = $store_arr[$k]['ordernum'];
+                            break;
+                        case 'orderamount':
+                            $tmp['orderamount'] = ds_price_format($store_arr[$k]['orderamount']);
+                            break;
+                    }
+                    $soaring_statlist[] = $tmp;
+                    $i++;
+                } else {
+                    break;
+                }
+            }
+        }
+        View::assign('soaring_statlist',$soaring_statlist);
+        View::assign('statlist',$statlist);
+        View::assign('sort_text',$sort_text);
+        View::assign('stat_field',$type);
+       echo View::fetch('store_hotrank_list');
+    }
+    /**
+     * 店铺等级
+     */
+    public function degree(){
+        $where = array();
+        $field = ' count(*) as allnum,grade_id ';
+        $stat_model = model('stat');
+        //查询店铺分类下的店铺
+        $search_sclass = input('param.search_sclass');
+        if ($search_sclass > 0){
+            $where[] = array('storeclass_id','=',$search_sclass);
+        }
+        $storelist = $stat_model->getNewStoreStatList($where, $field, 0, '', 0, 'grade_id');
+        $sd_list = $stat_model->getStoreDegree();
+        $statlist['headertitle'] = array();
+        $statlist['data'] = array();
+        //处理数组数据
+        if(!empty($storelist)){
+            foreach ($storelist as $k=>$v){
+                $storelist[$k]['p_name'] = isset($sd_list[$v['grade_id']]) > 0 ? $sd_list[$v['grade_id']]:lang('ds_ownshop');
+                $storelist[$k]['allnum'] = intval($v['allnum']);
+                $statlist['headertitle'][] = isset($sd_list[$v['grade_id']]) > 0?$sd_list[$v['grade_id']]:lang('ds_ownshop');
+                $statlist['data'][] = $v['allnum'];
+            }
+            $data = array(
+                'title'=>lang('store_grade_statis'),
+                'name'=>lang('store_number'),
+                'label_show'=>true,
+                'series'=>$storelist
+            );
+            View::assign('stat_json',getStatData_Pie($data));
+        }
+        $this->setAdminCurItem('degree');
+       return View::fetch('stat_storedegree');
+    }
+    /**
+     * 查看店铺列表
+     */
+    public function showstore(){
+        $stat_model = model('stat');
+        $where = array();
+        if (in_array(input('type'),array('newbyday','newbyweek','newbymonth','storearea'))){
+            $actionurl = (string)url('Statstore/showstore',['type'=>input('type'),'t'=>$this->search_arr['t']]);
+            $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+            foreach ((array)$searchtime_arr_tmp as $k=>$v){
+                $searchtime_arr[] = intval($v);
+            }
+            $where[] = array('store_addtime','between',$searchtime_arr);
+        }
+        //商品分类
+        $storeclass_id = intval(input('scid'));
+        if ($storeclass_id > 0){
+            $where[] = array('storeclass_id','=',$storeclass_id);
+            $actionurl .="&scid=$storeclass_id";
+        }
+        //省份
+        if (input('provid')){
+            $province_id = intval(input('param.provid'));
+            $where[] = array('province_id','=',$province_id);
+            $actionurl .="&provid=$province_id";
+        }
+
+        if (input('exporttype') == 'excel'){
+            $store_list = $stat_model->getNewStoreStatList($where);
+        } else {
+            $store_list = $stat_model->getNewStoreStatList($where, '', 10);
+        }
+
+        //店铺等级
+        $storegrade_model = model('storegrade');
+        $grade_list = $storegrade_model->getStoregradeList();
+        if (!empty($grade_list)){
+            $search_grade_list = array();
+            foreach ($grade_list as $k => $v){
+                $search_grade_list[$v['storegrade_id']] = $v['storegrade_name'];
+            }
+        }
+        //导出Excel
+        if (input('exporttype') == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_store_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_member_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_seller_name'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('stat_storedegree'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('statstore_expire'));
+            $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('statstore_addtime'));
+            //data
+            foreach ($store_list as $k=>$v){
+                $excel_data[$k+1][] = array('data'=>$v['store_name']);
+                $excel_data[$k+1][] = array('data'=>$v['member_name']);
+                $excel_data[$k+1][] = array('data'=>$v['seller_name']);
+                $excel_data[$k+1][] = array('data'=>$search_grade_list[$v['grade_id']]);
+                $excel_data[$k+1][] = array('data'=>$v['store_endtime']?date('Y-m-d', $v['store_endtime']):lang('state_no_tile_limit'));
+                $excel_data[$k+1][] = array('data'=>date('Y-m-d', $v['store_addtime']));
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('ds_new').lang('ds_store'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('ds_new').lang('ds_store'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        }
+        View::assign('search_grade_list', $search_grade_list);
+        View::assign('actionurl',$actionurl);
+        View::assign('store_list',$store_list);
+        View::assign('show_page',$stat_model->page_info->render());
+        $this->setAdminCurItem('showstore');
+       return View::fetch('storelist');
+    }
+
+    /**
+     * 销售统计
+     */
+    public function storesales(){
+        if(!isset($this->search_arr['search_type'])){
+            $this->search_arr['search_type'] = 'day';
+        }
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        View::assign('searchtime',implode('|',$searchtime_arr));
+		//周
+        if(!input('param.search_time_year')) {
+            $search_time_year = date('Y', TIMESTAMP);
+        }else {
+            $search_time_year = input('param.search_time_year');
+        }
+        if(!input('param.search_time_month')) {
+            $search_time_month = date('m', TIMESTAMP);
+        }else {
+            $search_time_month = input('param.search_time_month');
+        }
+        if(!input('param.search_time_week')) {
+            $search_time_week = implode('|', getWeek_SdateAndEdate(TIMESTAMP));
+        }else {
+            $search_time_week = input('param.search_time_week');
+        }
+        $current_year =$search_time_year;
+        $current_month =$search_time_month;
+        $current_week = $search_time_week;
+
+
+        View::assign('current_year', $current_year);
+        View::assign('current_month', $current_month);
+        View::assign('current_week', $current_week);
+        $this->setAdminCurItem('storesales');
+       return View::fetch('stat_store_sales');
+    }
+    /**
+     * 店铺销售统计列表
+     */
+    public function storesales_list(){
+        $stat_model = model('stat');
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where = array();
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+        //店铺分类
+        $search_sclass = intval(input('param.search_sclass'));
+        if ($search_sclass){
+            $where[]=array('storeclass_id','=',$search_sclass);
+        }
+        //店铺名称
+        $where[]=array('store_name','like',"%".input('param.search_sname')."%");
+        //查询总条数
+        $count_arr = $stat_model->getoneByStatorder($where, 'COUNT(DISTINCT store_id) as countnum');
+        $countnum = intval($count_arr['countnum']);
+        //列表字段
+        $field = " store_id,store_name,SUM(order_amount) as orderamount, COUNT(*) as ordernum, COUNT(DISTINCT buyer_id) as membernum";
+        //排序
+        $orderby_arr = array('membernum asc','membernum desc','ordernum asc','ordernum desc','orderamount asc','orderamount desc');
+        if (!isset($this->search_arr['orderby'])||!in_array(trim($this->search_arr['orderby']),$orderby_arr)){
+            $this->search_arr['orderby'] = 'membernum desc';
+        }
+        $orderby = trim($this->search_arr['orderby']).',store_id asc';
+
+        if (isset($this->search_arr['exporttype'])&&$this->search_arr['exporttype'] == 'excel'){
+            $statlist = $stat_model->statByStatorder($where, $field, 0, 0, $orderby, 'store_id');
+        } else {
+            $statlist = $stat_model->statByStatorder($where, $field, 20, 0, $orderby, 'store_id');
+            foreach ((array)$statlist as $k=>$v){
+                $v['view'] = "<a href='javascript:void(0);' ds_type='showtrends' data-param='{\"storeid\":\"{$v['store_id']}\"}'>走势图</a>";
+                $statlist[$k] = $v;
+            }
+        }
+
+        //列表header
+        $statheader = array();
+        $statheader[] = array('text'=>lang('ds_store_name'),'key'=>'store_name');
+        $statheader[] = array('text'=>lang('membernum'),'key'=>'membernum','isorder'=>1);
+        $statheader[] = array('text'=>lang('statstore_ordernum'),'key'=>'ordernum','isorder'=>1);
+        $statheader[] = array('text'=>lang('statstore_orderamount'),'key'=>'orderamount','isorder'=>1);
+
+        //导出Excel
+        if (isset($this->search_arr['exporttype'])&&$this->search_arr['exporttype'] == 'excel'){
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
+            //header
+            foreach ($statheader as $k=>$v){
+                $excel_data[0][] = array('styleid'=>'s_title','data'=>$v['text']);
+            }
+            //data
+            foreach ($statlist as $k=>$v){
+                foreach ($statheader as $h_k=>$h_v){
+                    $excel_data[$k+1][] = array('data'=>$v[$h_v['key']]);
+                }
+            }
+            $excel_data = $excel_obj->charset($excel_data,CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('store_sale_statis'),CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('store_sale_statis'),CHARSET).date('Y-m-d-H',TIMESTAMP));
+            exit();
+        }
+
+        View::assign('statlist',$statlist);
+        View::assign('statheader',$statheader);
+        View::assign('orderby',$this->search_arr['orderby']);
+        View::assign('actionurl',(string)url('Statstore/storesales_list',['t'=>$this->search_arr['t'],'search_sclass'=>$search_sclass,'search_sname'=>input('param.search_sname')]));
+        View::assign('show_page',$stat_model->page_info->render());
+       echo  View::fetch('stat_listandorder');
+    }
+    /**
+     * 销售走势
+     */
+    public function storesales_trends(){
+        $storeid = intval(input('param.storeid'));
+        if ($storeid <= 0){
+            View::assign('stat_error',lang('stat_error'));
+           return View::fetch('salestrends');
+            exit();
+        }
+        $search_type=input('param.search_type');
+        if (!$search_type){
+            $search_type= 'day';
+        }
+        $stat_model = model('stat');
+        $where = array();
+        $where[] = array('store_id','=',$storeid);
+        $searchtime_arr_tmp = explode('|',$this->search_arr['t']);
+        foreach ((array)$searchtime_arr_tmp as $k=>$v){
+            $searchtime_arr[] = intval($v);
+        }
+        $where[] = array('order_isvalid','=',1);//计入统计的有效订单
+        $where[] = array('order_add_time','between',$searchtime_arr);
+
+        $field = " store_id,store_name,SUM(order_amount) as orderamount, COUNT(*) as ordernum, COUNT(DISTINCT buyer_id) as membernum";
+        $stat_arr = array('orderamount'=>array(),'ordernum'=>array(),'membernum'=>array());
+        $statlist = array();
+        if($search_type == 'day'){
+            //构造横轴数据
+            for($i=0; $i<24; $i++){
+                //横轴
+                foreach ($stat_arr as $k=>$v){
+                    $stat_arr[$k]['xAxis']['categories'][] = "$i";
+                    $statlist[$k][$i] = 0;
+                }
+            }
+            $field .= ' ,HOUR(FROM_UNIXTIME(order_add_time)) as timeval ';
+        }
+        if($search_type == 'week'){
+            //构造横轴数据
+            for($i=1; $i<=7; $i++){
+                $tmp_weekarr = getSystemWeekArr();
+                //横轴
+                foreach ($stat_arr as $k=>$v){
+                    $stat_arr[$k]['xAxis']['categories'][] = $tmp_weekarr[$i];
+                    $statlist[$k][$i] = 0;
+                }
+                unset($tmp_weekarr);
+            }
+            $field .= ' ,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as timeval ';
+        }
+        if($search_type == 'month'){
+            //计算横轴的最大量(由于每个月的天数不同)
+            $dayofmonth = date('t',$searchtime_arr[0]);
+            //构造横轴数据
+            for($i=1; $i<=$dayofmonth; $i++){
+                //横轴
+                foreach ($stat_arr as $k=>$v){
+                    $stat_arr[$k]['xAxis']['categories'][] = $i;
+                    $statlist[$k][$i] = 0;
+                }
+            }
+            $field .= ' ,day(FROM_UNIXTIME(order_add_time)) as timeval ';
+        }
+        //查询数据
+        $statlist_tmp = $stat_model->statByStatorder($where, $field, 0, '');
+        //整理统计数组
+        $storename = '';
+        if($statlist_tmp){
+            foreach($statlist_tmp as $k => $v){
+                $storename = $v['store_name'];
+                foreach ($stat_arr as $t_k=>$t_v){
+                    if ($k == 'orderamount'){
+                        $statlist[$t_k][$v['timeval']] = round($v[$t_k],2);
+                    } else {
+                        $statlist[$t_k][$v['timeval']] = intval($v[$t_k]);
+                    }
+                }
+            }
+        }
+        foreach ($stat_arr as $k=>$v){
+            $stat_arr[$k]['legend']['enabled'] = false;
+            switch ($k){
+                case 'orderamount':
+                    $caption = lang('statstore_orderamount');
+                    break;
+                case 'ordernum':
+                    $caption = lang('statstore_ordernum');
+                    break;
+                default:
+                    $caption = lang('membernum');
+                    break;
+            }
+            $stat_arr[$k]['series'][0]['name'] = $caption;
+            $stat_arr[$k]['series'][0]['data'] = array_values($statlist[$k]);
+            $stat_arr[$k]['title'] = $caption.lang('sale_trend');
+            $stat_arr[$k]['yAxis'] = $caption;
+            //得到统计图数据
+            $stat_json[$k] = getStatData_LineLabels($stat_arr[$k]);
+        }
+        View::assign('storename',$storename);
+        View::assign('stat_json',$stat_json);
+       echo View::fetch('store_salestrends');
+    }
+    /**
+     * 地区分布
+     */
+    public function storearea(){
+        $stat_model = model('stat');
+        //获得搜索的开始时间和结束时间
+        $searchtime_arr = $stat_model->getStarttimeAndEndtime($this->search_arr);
+        $where = array();
+        if (trim(input('param.search_time'))){
+            $where[]=array('store_addtime','<=',strtotime(input('param.search_time')));
+        }
+        $search_sclass = intval(input('param.search_sclass'));
+        if ($search_sclass > 0){
+            $where[]=array('storeclass_id','=',$search_sclass);
+        }
+        $field = ' region_id, COUNT(*) as storenum ';
+        $statlist_tmp = $stat_model->statByStore($where, $field, 'region_id', 'region_id');
+        // 地区
+        $province_array = model('area')->getTopLevelAreas();
+        //地图显示等级数组
+        $level_arr = array(array(1,2,3),array(4,5,6),array(7,8,9),array(10,11,12));
+        $statlist = array();
+		$temp_list=array();
+        foreach ((array)$statlist_tmp as $k=>$v){
+            $v['level'] = 4;//排名
+            foreach ($level_arr as $lk=>$lv){
+                if (in_array($k+1,$lv)){
+                    $v['level'] = $lk;//排名
+                }
+            }
+            //获取该地区的省
+			if($v['region_id']){
+            if(!isset($temp_list[$v['region_id']])){
+                $temp=Db::name('area')->where('area_id='.$v['region_id'])->value('area_parent_id');
+                if($temp){
+                    $temp_list[$v['region_id']]=$temp;
+                }else{
+                    $temp_list[$v['region_id']]=$v['region_id'];
+                }
+                
+                $index=0;
+                while($temp && $index<4){
+                    $temp_list[$v['region_id']]=$temp;
+                    $temp_0=$temp;
+                    $temp=Db::name('area')->where('area_id='.$temp)->value('area_parent_id');
+                    if($temp){
+                        $temp_list[$temp_0]=$temp;
+                    }else{
+                        $temp_list[$temp_0]=$temp_0;
+                    }
+                    $index++;
+                }
+            }
+            $province_id = $temp_list[$v['region_id']];
+			}else{
+                $province_id=0;
+            }
+            
+            $v['sort'] = $k+1;
+            $v['provincename'] = isset($province_array[$province_id]) ? $province_array[$province_id] : lang('other');
+            if(!isset($statlist[$province_id])){
+                $statlist[$province_id] = $v;
+            }else{
+                $statlist[$province_id]['storenum'] += $v['storenum'];
+            }
+        }
+        $stat_arr = array();
+        foreach ((array)$province_array as $k=>$v){
+            if (isset($statlist[$k])){
+                $stat_arr[] = array('cha'=>$k,'name'=>$v,'des'=>",店铺量:{$statlist[$k]['storenum']}",'level'=>$statlist[$k]['level']);
+            } else {
+                $stat_arr[] = array('cha'=>$k,'name'=>$v,'des'=>',无订单数据','level'=>4);
+            }
+        }
+
+        $stat_json = getStatData_Map($stat_arr);
+        View::assign('stat_json',$stat_json);
+        View::assign('statlist',$statlist);
+        $actionurl = (string)url('Statstore/storearea');
+        if (trim(input('param.search_time'))){
+            $actionurl = $actionurl.'&t=0|'.strtotime(input('param.search_time'));
+        }
+        if ($search_sclass > 0){
+            $actionurl .= "&scid=$search_sclass";
+        }
+        View::assign('actionurl',$actionurl);
+        $this->setAdminCurItem('storearea');
+       return View::fetch('stat_storearea');
+    }
+    protected function getAdminItemList()
+    {
+       $menu_array = array(
+           array('name'=>'newstore','text'=>lang('stat_newstore'),'url'=>(string)url('Statstore/newstore')),
+           array('name'=>'hotrank','text'=>lang('stat_storehotrank'),'url'=>(string)url('Statstore/hotrank')),
+           array('name'=>'storesales','text'=>lang('stat_storesales'),'url'=>(string)url('Statstore/storesales')),
+           array('name'=>'degree','text'=>lang('stat_storedegree'),'url'=>(string)url('Statstore/degree')),
+           array('name'=>'storearea','text'=>lang('stat_storearea'),'url'=>(string)url('Statstore/storearea')),
+       );
+       return $menu_array;
+    }
+}

+ 666 - 0
app/admin/controller/Stattrade.php

@@ -0,0 +1,666 @@
+<?php
+
+/**
+ * Created by ds
+ * 销售分析
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Stattrade extends AdminControl {
+
+    private $search_arr; //处理后的参数
+
+    public function initialize() {
+        parent::initialize(); // TODO: Change the autogenerated stub
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/stat.lang.php');
+        include_once root_path(). 'extend/mall/statistics.php';
+        include_once root_path(). 'extend/mall/datehelper.php';
+    }
+
+    /**
+     * 销售收入统计
+     */
+    public function income() {
+        $stat_model = model('stat');
+        $search_year = input('param.search_year');
+        $search_month = input('param.search_month');
+        if ($search_year == '' || $search_month == '') {
+            $now_year = date('Y', TIMESTAMP);
+            $now_month = date('m', TIMESTAMP);
+            if ($now_month == 1) {
+                $search_year = $now_year - 1;
+                $search_month = 12;
+            } else {
+                $search_year = $now_year;
+                if ($now_month > 10) {
+                    $search_month = $now_month - 1;
+                } else {
+                    $search_month = '0' . ($now_month - 1);
+                }
+            }
+        }
+        $year = intval($search_year);
+        $month = trim($search_month);
+        if (!in_array($month, array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'))) {
+            $month = date('m', TIMESTAMP);
+            $search_month = $month;
+        }
+        $condition = array();
+        $condition[] = array('os_month','=',$year . $month);
+        if (input('param.exporttype') == 'excel') {
+            //获取全部店铺结账数据
+            $bill_list = $stat_model->getBillList(array(array('ob_startdate','>=',strtotime($year .'-'. $month.'-01 0:0:0')),array('ob_enddate','<',strtotime($year .'-'. $month.'-01 23:59:59 +1 month -1 day'))), 'ob', false);
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            $excel_data[0][0] = array('styleid' => 's_title', 'data' => lang('ds_store_name'));
+            $excel_data[0][1] = array('styleid' => 's_title', 'data' => lang('ds_seller_name'));
+            $excel_data[0][2] = array('styleid' => 's_title', 'data' => lang('ds_order_amount'));
+            $excel_data[0][3] = array('styleid' => 's_title', 'data' => lang('ob_commis_totals'));
+            $excel_data[0][4] = array('styleid' => 's_title', 'data' => lang('ob_order_return_totals'));
+            $excel_data[0][5] = array('styleid' => 's_title', 'data' => lang('ob_commis_return_totals'));
+            $excel_data[0][6] = array('styleid' => 's_title', 'data' => lang('ob_store_cost_totals'));
+            $excel_data[0][7] = array('styleid' => 's_title', 'data' => lang('ob_result_totals'));
+            //data
+            foreach ($bill_list as $k => $v) {
+                $excel_data[$k + 1][0] = array('data' => $v['ob_store_name']);
+                $excel_data[$k + 1][1] = array('data' => $v['member_name']);
+                $excel_data[$k + 1][2] = array('data' => $v['ob_order_totals']);
+                $excel_data[$k + 1][3] = array('data' => $v['ob_commis_totals']);
+                $excel_data[$k + 1][4] = array('data' => $v['ob_order_return_totals']);
+                $excel_data[$k + 1][5] = array('data' => $v['ob_commis_return_totals']);
+                $excel_data[$k + 1][6] = array('data' => $v['ob_store_cost_totals']);
+                $excel_data[$k + 1][7] = array('data' => $v['ob_result_totals']);
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('store_commis_statis'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('store_commis_statis'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        } else {
+            //获取平台总数据
+            $plat_data = $stat_model->getBillList($condition, 'os');
+            View::assign('plat_data', $plat_data[0]);
+            //店铺数据
+            View::assign('store_list', $stat_model->getBillList(array(array('ob_startdate','>=',strtotime($year .'-'. $month.'-01 0:0:0')),array('ob_enddate','<',strtotime($year .'-'. $month.'-01 23:59:59 +1 month -1 day'))), 'ob'));
+            View::assign('show_page',$stat_model->page_info->render());
+            $this->setAdminCurItem('income');
+            return View::fetch('stat_income');
+        }
+    }
+
+    /**
+     * 预存款统计
+     */
+    public function predeposit() {
+        $where = array();
+        if (trim(input('param.pd_type')) == 'cash_pay') {
+            $field = 'sum(lg_freeze_amount) as allnum';
+        } else {
+            $field = 'sum(lg_av_amount) as allnum';
+        }
+        $search_type = input('param.search_type');
+        if (!$search_type) {
+            $search_type = 'day';
+        }
+        $pd_type = trim(input('param.pd_type')) == '' ? 'recharge' : trim(input('param.pd_type'));
+        $where[] = array('lg_type','=',$pd_type);
+        //初始化时间
+        //天
+        $search_time = input('param.search_time');
+        if (!$search_time) {
+            $search_time = date('Y-m-d', TIMESTAMP - 86400);
+        }
+        $search_time = strtotime($search_time); //搜索的时间
+        View::assign('search_time', $search_time);
+        //周
+        $search_time_year = input('param.search_time_year');
+        if (!$search_time_year) {
+            $search_time_year = date('Y', TIMESTAMP);
+        }
+        $search_time_month = input('param.search_time_month');
+        if (!$search_time_month) {
+            $search_time_month = date('m', TIMESTAMP);
+        }
+        $search_time_week = input('param.search_time_week');
+        if (!$search_time_week) {
+            $search_time_week = implode('|', getWeek_SdateAndEdate(TIMESTAMP));
+        }
+        $current_year = $search_time_year;
+        $current_month = $search_time_month;
+        $current_week = $search_time_week;
+        $year_arr = getSystemYearArr();
+        $month_arr = getSystemMonthArr();
+        $week_arr = getMonthWeekArr($current_year, $current_month);
+
+        View::assign('current_year', $current_year);
+        View::assign('current_month', $current_month);
+        View::assign('current_week', $current_week);
+        View::assign('year_arr', $year_arr);
+        View::assign('month_arr', $month_arr);
+        View::assign('week_arr', $week_arr);
+
+        $stat_model = model('stat');
+        $statlist = array(); //统计数据列表
+        if ($search_type == 'day') {
+            //构造横轴数据
+            for ($i = 0; $i < 24; $i++) {
+                //统计图数据
+                $curr_arr[$i] = 0; //今天
+                $up_arr[$i] = 0; //昨天
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $i;
+                $currlist_arr[$i]['timetext'] = $i;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = "$i";
+            }
+            $stime = $search_time - 86400; //昨天0点
+            $etime = $search_time + 86400 - 1; //今天24点
+
+            $today_day = @date('d', $search_time); //今天日期
+            $yesterday_day = @date('d', $stime); //昨天日期
+
+            $where[] = array('lg_addtime','between',array($stime, $etime));
+            $field .= ' ,DAY(FROM_UNIXTIME(lg_addtime)) as dayval,HOUR(FROM_UNIXTIME(lg_addtime)) as hourval ';
+            $memberlist = $stat_model->getPredepositInfo($where, $field, 0, '', 0, 'dayval,hourval');
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($today_day == $v['dayval']) {
+                        $curr_arr[$v['hourval']] = abs($v['allnum']);
+                        $currlist_arr[$v['hourval']]['val'] = abs($v['allnum']);
+                    }
+                    if ($yesterday_day == $v['dayval']) {
+                        $up_arr[$v['hourval']] = abs($v['allnum']);
+                        $uplist_arr[$v['hourval']]['val'] = abs($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('yestoday');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('today');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('hour'), lang('yestoday'), lang('today'), lang('compare_to'));
+            View::assign('actionurl', (string)url('Stattrade/predeposit', ['search_type' => 'day', 'search_time' => date('Y-m-d', $search_time)]));
+        }
+
+        if ($search_type == 'week') {
+            $current_weekarr = explode('|', $current_week);
+            $stime = strtotime($current_weekarr[0]) - 86400 * 7;
+            $etime = strtotime($current_weekarr[1]) + 86400 - 1;
+            $up_week = @date('W', $stime); //上周
+            $curr_week = @date('W', $etime); //本周
+            //构造横轴数据
+            for ($i = 1; $i <= 7; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                $tmp_weekarr = getSystemWeekArr();
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+            }
+            $where[] = array('lg_addtime','between',array($stime, $etime));
+            $field .= ',WEEKOFYEAR(FROM_UNIXTIME(lg_addtime)) as weekval,WEEKDAY(FROM_UNIXTIME(lg_addtime))+1 as dayofweekval ';
+            $memberlist = $stat_model->getPredepositInfo($where, $field, 0, '', 0,'weekval,dayofweekval');
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($up_week == $v['weekval']) {
+                        $up_arr[$v['dayofweekval']] = abs($v['allnum']);
+                        $uplist_arr[$v['dayofweekval']]['val'] = abs($v['allnum']);
+                    }
+                    if ($curr_week == $v['weekval']) {
+                        $curr_arr[$v['dayofweekval']] = abs($v['allnum']);
+                        $currlist_arr[$v['dayofweekval']]['val'] = abs($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_week');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_week');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('week'), lang('last_week'), lang('this_week'), lang('compare_to'));
+            View::assign('actionurl', (string)url('Stattrade/predeposit', ['search_type' => 'week', 'search_time_year' => $current_year, 'search_time_month' => '$current_month', 'search_time_week' => $current_week]));
+        }
+
+        if ($search_type == 'month') {
+            $stime = strtotime($current_year . '-' . $current_month . "-01 -1 month");
+            $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1;
+
+            $up_month = date('m', $stime);
+            $curr_month = date('m', $etime);
+            //计算横轴的最大量(由于每个月的天数不同)
+            $up_dayofmonth = date('t', $stime);
+            $curr_dayofmonth = date('t', $etime);
+            $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth;
+
+            //构造横轴数据
+            for ($i = 1; $i <= $x_max; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $i;
+                $currlist_arr[$i]['timetext'] = $i;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+            }
+            $where[] = array('lg_addtime','between',array($stime, $etime));
+            $field .= ',MONTH(FROM_UNIXTIME(lg_addtime)) as monthval,day(FROM_UNIXTIME(lg_addtime)) as dayval ';
+            $memberlist = $stat_model->getPredepositInfo($where, $field, 0, '', 0, 'monthval,dayval');
+            if ($memberlist) {
+                foreach ($memberlist as $k => $v) {
+                    if ($up_month == $v['monthval']) {
+                        $up_arr[$v['dayval']] = abs($v['allnum']);
+                        $uplist_arr[$v['dayval']]['val'] = abs($v['allnum']);
+                    }
+                    if ($curr_month == $v['monthval']) {
+                        $curr_arr[$v['dayval']] = abs($v['allnum']);
+                        $currlist_arr[$v['dayval']]['val'] = abs($v['allnum']);
+                    }
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_month');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_month');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+            //统计数据标题
+            $statlist['headertitle'] = array(lang('date'), lang('last_month'), lang('this_month'), lang('compare_to'));
+            View::assign('actionurl', (string)url('Stattrade/predeposit', ['search_type' => 'month', 'search_time_year' => $current_year, 'search_time_month' => $current_month]));
+        }
+
+        //计算同比
+        foreach ((array) $currlist_arr as $k => $v) {
+            $tmp = array();
+            $tmp['timetext'] = $v['timetext'];
+            $tmp['currentdata'] = $v['val'];
+            $tmp['updata'] = $uplist_arr[$k]['val'];
+            $tmp['tbrate'] = getTb($tmp['updata'], $tmp['currentdata']);
+            $statlist['data'][] = $tmp;
+        }
+        //导出Excel
+        if (input('param.exporttype') == 'excel') {
+            //获取数据
+            $log_list = $stat_model->getPredepositInfo($where, '*', '');
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_name'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('lg_addtime'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('lg_av_amount').'('.lang('元').')');
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('lg_freeze_amount').'('.lang('元').')');
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('lg_admin_name'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('operate_type'));
+            $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_description'));
+            //data
+            foreach ($log_list as $k => $v) {
+                $excel_data[$k + 1][] = array('data' => $v['lg_member_name']);
+                $excel_data[$k + 1][] = array('data' => date('Y-m-d H:i:s', $v['lg_addtime']));
+                $excel_data[$k + 1][] = array('data' => $v['lg_av_amount']);
+                $excel_data[$k + 1][] = array('data' => $v['lg_freeze_amount']);
+                $excel_data[$k + 1][] = array('data' => $v['lg_admin_name']);
+                switch ($v['lg_type']) {
+                    case 'recharge':
+                        $excel_data[$k + 1][] = array('data' => lang('pd_type_recharge'));
+                        break;
+                    case 'order_pay':
+                        $excel_data[$k + 1][] = array('data' => lang('pd_type_order_pay'));
+                        break;
+                    case 'cash_pay':
+                        $excel_data[$k + 1][] = array('data' => lang('pd_type_cash_pay'));
+                        break;
+                    case 'refund':
+                        $excel_data[$k + 1][] = array('data' => lang('pd_type_refund'));
+                        break;
+                }
+                $excel_data[$k + 1][] = array('data' => $v['lg_desc']);
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('predeposit_statis'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('predeposit_statis'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        } else {
+            $log_list = $stat_model->getPredepositInfo($where, '*', 15);
+            View::assign('log_list', $log_list);
+            View::assign('show_page', $stat_model->page_info->render());
+            //总数统计部分
+            $condition = array();
+            $condition[] = array('lg_type','=','recharge');
+            $condition[] = array('lg_addtime','between',array($stime, $etime));
+            $recharge_amount = $stat_model->getPredepositInfo($condition, 'sum(lg_av_amount) as allnum');
+            $condition = array();
+            $condition[] = array('lg_type','=','order_pay');
+            $condition[] = array('lg_addtime','between',array($stime, $etime));
+            $order_amount = $stat_model->getPredepositInfo($condition, 'sum(lg_av_amount) as allnum');
+            $condition = array();
+            $condition[] = array('lg_type','=','cash_pay');
+            $condition[] = array('lg_addtime','between',array($stime, $etime));
+            $cash_amount = $stat_model->getPredepositInfo($condition, 'sum(lg_freeze_amount) as allnum');
+            View::assign('stat_array', array('recharge_amount' => $recharge_amount[0]['allnum'], 'order_amount' => abs($order_amount[0]['allnum']), 'cash_amount' => abs($cash_amount[0]['allnum'])));
+            $user_amount = $stat_model->getPredepositInfo(true, 'distinct lg_member_id');
+            View::assign('user_amount', count($user_amount));
+            $usable_amount = $stat_model->getPredepositInfo(true, 'sum(lg_av_amount+lg_freeze_amount) as allnum');
+            View::assign('usable_amount', $usable_amount[0]['allnum']);
+            //得到统计图数据
+            $stat_arr['title'] = lang('predeposit_statis');
+            $stat_arr['yAxis'] = lang('amount');
+            $stat_json = getStatData_LineLabels($stat_arr);
+            View::assign('stat_json', $stat_json);
+            View::assign('statlist', $statlist);
+            $this->setAdminCurItem('predeposit');
+            return View::fetch('stat_predeposit');
+        }
+    }
+
+    /**
+     * 订单统计
+     */
+    public function sale() {
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //处理搜索时间
+        $this->search_arr = $stat_model->dealwithSearchTime($this->search_arr);
+        //获得系统年份
+        $year_arr = getSystemYearArr();
+        //获得系统月份
+        $month_arr = getSystemMonthArr();
+        //获得本月的周时间段
+        $week_arr = getMonthWeekArr($this->search_arr['week']['current_year'], $this->search_arr['week']['current_month']);
+        View::assign('year_arr', $year_arr);
+        View::assign('month_arr', $month_arr);
+        View::assign('week_arr', $week_arr);
+        View::assign('search_arr', $this->search_arr);
+
+        //默认统计当前数据
+        if (!isset($this->search_arr['search_type'])) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        //计算昨天和今天时间
+        if ($this->search_arr['search_type'] == 'day') {
+            $stime = $this->search_arr['day']['search_time'] - 86400; //昨天0点
+            $etime = $this->search_arr['day']['search_time'] + 86400 - 1; //今天24点
+            $curr_stime = $this->search_arr['day']['search_time']; //今天0点
+        } elseif ($this->search_arr['search_type'] == 'week') {
+            $current_weekarr = explode('|', $this->search_arr['week']['current_week']);
+            $stime = strtotime($current_weekarr[0]) - 86400 * 7;
+            $etime = strtotime($current_weekarr[1]) + 86400 - 1;
+            $curr_stime = strtotime($current_weekarr[0]); //本周0点
+        } elseif ($this->search_arr['search_type'] == 'month') {
+            $stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01 -1 month");
+            $etime = getMonthLastDay($this->search_arr['month']['current_year'], $this->search_arr['month']['current_month']) + 86400 - 1;
+            $curr_stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01");
+            //本月0点
+        }
+
+        $where = array();
+        $where[] = array('order_add_time','between', array($curr_stime, $etime));
+        if (trim(input('param.order_type')) != '') {
+            $where[]=array('order_state','=',trim(input('param.order_type')));
+        }
+        if (trim(input('param.store_name')) != '') {
+            $where[]=array('store_name','like', '%' . trim(input('param.store_name')) . '%');
+        }
+        if (input('param.exporttype') == 'excel') {
+            $order_list = $stat_model->statByStatorder($where, '', 0, 0, 'order_id desc', '');
+        } else {
+            $order_list = $stat_model->statByStatorder($where, '', 10, 0, 'order_id desc', '');
+        }
+        //统计数据标题
+        $statlist = array();
+        $statlist['headertitle'] = array(lang('ds_order_sn'), lang('ds_member_name'), lang('ds_store_name'), lang('order_add_time'), lang('ds_order_amount'), lang('order_state'));
+
+        foreach ((array) $order_list as $k => $v) {
+            switch ($v['order_state']) {
+                case ORDER_STATE_CANCEL:
+                    $v['order_statetext'] = lang('order_state_cancel');
+                    break;
+                case ORDER_STATE_NEW:
+                    $v['order_statetext'] = lang('order_state_new');
+                    break;
+                case ORDER_STATE_PAY:
+                    $v['order_statetext'] = lang('order_state_pay');
+                    break;
+                case ORDER_STATE_SEND:
+                    $v['order_statetext'] = lang('order_state_send');
+                    break;
+                case ORDER_STATE_SUCCESS:
+                    $v['order_statetext'] = lang('order_state_success');
+                    break;
+            }
+            $statlist['data'][$k] = $v;
+        }
+        //导出Excel
+        if (input('param.exporttype') == 'excel') {
+            //导出Excel
+            $excel_obj = new \excel\Excel();
+            $excel_data = array();
+            //设置样式
+            $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
+            //header
+            foreach ($statlist['headertitle'] as $v) {
+                $excel_data[0][] = array('styleid' => 's_title', 'data' => $v);
+            }
+            //data
+            foreach ((array) @$statlist['data'] as $k => $v) {
+                $excel_data[$k + 1][] = array('data' => $v['order_sn']);
+                $excel_data[$k + 1][] = array('data' => $v['buyer_name']);
+                $excel_data[$k + 1][] = array('data' => $v['store_name']);
+                $excel_data[$k + 1][] = array('data' => date('Y-m-d H:i:s', $v['order_add_time']));
+                $excel_data[$k + 1][] = array('data' => ds_price_format($v['order_amount']));
+                $excel_data[$k + 1][] = array('data' => $v['order_statetext']);
+            }
+            $excel_data = $excel_obj->charset($excel_data, CHARSET);
+            $excel_obj->addArray($excel_data);
+            $excel_obj->addWorksheet($excel_obj->charset(lang('stat_sale'), CHARSET));
+            $excel_obj->generateXML($excel_obj->charset(lang('stat_sale'), CHARSET) . date('Y-m-d-H', TIMESTAMP));
+            exit();
+        } else {
+            //总数统计
+            $statcount_arr = $stat_model->getoneByStatorder($where, ' COUNT(*) as ordernum, SUM(order_amount) as orderamount');
+            View::assign('statcount_arr', $statcount_arr);
+            View::assign('searchtime', implode('|', array($stime, $etime)));
+            View::assign('statlist', $statlist);
+            View::assign('show_page', $stat_model->page_info->render());
+            $this->setAdminCurItem('sale');
+            return View::fetch('stat_sale');
+        }
+    }
+
+    /**
+     * 订单走势
+     */
+    public function sale_trend() {
+        $stat_model = model('stat');
+        //存储参数
+        $this->search_arr = input('param.');
+        //默认统计当前数据
+        if (!$this->search_arr['search_type']) {
+            $this->search_arr['search_type'] = 'day';
+        }
+        $where = array();
+        $order_state = input('param.order_state');
+        if (trim($order_state) != '') {
+            $where[]=array('order_state','=',trim($order_state));
+        }
+        $store_name = input('param.store_name');
+        if (trim($store_name) != '') {
+            $where[]=array('store_name','like', '%' . trim($store_name) . '%');
+        }
+        $stattype = trim(input('param.type'));
+        if ($stattype == 'ordernum') {
+            $field = ' COUNT(*) as ordernum ';
+            $stat_arr['title'] = lang('order_number_statis');
+            $stat_arr['yAxis'] = lang('ds_order_sn');
+        } else {
+            $stattype = 'orderamount';
+            $field = ' SUM(order_amount) as orderamount ';
+            $stat_arr['title'] = lang('stattrade_order_amount_statis');
+            $stat_arr['yAxis'] = lang('stattrade_order_amount');
+        }
+        $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
+        foreach ((array) $searchtime_arr_tmp as $k => $v) {
+            $searchtime_arr[] = intval($v);
+        }
+        if ($this->search_arr['search_type'] == 'day') {
+            //构造横轴数据
+            for ($i = 0; $i < 24; $i++) {
+                //统计图数据
+                $curr_arr[$i] = 0; //今天
+                $up_arr[$i] = 0; //昨天
+                //统计表数据
+                $currlist_arr[$i]['timetext'] = $i;
+
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = "$i";
+            }
+
+            $today_day = @date('d', $searchtime_arr[1]); //今天日期
+            $yesterday_day = @date('d', $searchtime_arr[0]); //昨天日期
+
+            $where[] = array('order_add_time','between',$searchtime_arr);
+            $field .= ' ,DAY(FROM_UNIXTIME(order_add_time)) as dayval,HOUR(FROM_UNIXTIME(order_add_time)) as hourval ';
+            $orderlist = $stat_model->statByStatorder($where, $field, 0, 0, '', 'DAY(FROM_UNIXTIME(order_add_time)),HOUR(FROM_UNIXTIME(order_add_time))');
+
+            foreach ((array) $orderlist as $k => $v) {
+                if ($today_day == $v['dayval']) {
+                    $curr_arr[$v['hourval']] = intval($v[$stattype]);
+                    $currlist_arr[$v['hourval']]['val'] = $v[$stattype];
+                }
+                if ($yesterday_day == $v['dayval']) {
+                    $up_arr[$v['hourval']] = intval($v[$stattype]);
+                    $uplist_arr[$v['hourval']]['val'] = $v[$stattype];
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('yestoday');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('today');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+        }
+
+        if ($this->search_arr['search_type'] == 'week') {
+            $up_week = @date('W', $searchtime_arr[0]); //上周
+            $curr_week = @date('W', $searchtime_arr[1]); //本周
+            //构造横轴数据
+            for ($i = 1; $i <= 7; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                $tmp_weekarr = getSystemWeekArr();
+                //统计表数据
+                $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
+                unset($tmp_weekarr);
+            }
+            $where[] = array('order_add_time','between',$searchtime_arr);
+            $field .= ',WEEKOFYEAR(FROM_UNIXTIME(order_add_time)) as weekval,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as dayofweekval ';
+            $orderlist = $stat_model->statByStatorder($where, $field, 0, 0, '', 'weekval,dayofweekval');
+            foreach ((array) $orderlist as $k => $v) {
+                if ($up_week == $v['weekval']) {
+                    $up_arr[$v['dayofweekval']] = intval($v[$stattype]);
+                    $uplist_arr[$v['dayofweekval']]['val'] = intval($v[$stattype]);
+                }
+                if ($curr_week == $v['weekval']) {
+                    $curr_arr[$v['dayofweekval']] = intval($v[$stattype]);
+                    $currlist_arr[$v['dayofweekval']]['val'] = intval($v[$stattype]);
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_week');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_week');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+        }
+
+        if ($this->search_arr['search_type'] == 'month') {
+            $up_month = date('m', $searchtime_arr[0]);
+            $curr_month = date('m', $searchtime_arr[1]);
+            //计算横轴的最大量(由于每个月的天数不同)
+            $up_dayofmonth = date('t', $searchtime_arr[0]);
+            $curr_dayofmonth = date('t', $searchtime_arr[1]);
+            $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth;
+
+            //构造横轴数据
+            for ($i = 1; $i <= $x_max; $i++) {
+                //统计图数据
+                $up_arr[$i] = 0;
+                $curr_arr[$i] = 0;
+                //统计表数据
+                $currlist_arr[$i]['timetext'] = $i;
+                $uplist_arr[$i]['val'] = 0;
+                $currlist_arr[$i]['val'] = 0;
+                //横轴
+                $stat_arr['xAxis']['categories'][] = $i;
+            }
+            $where[] = array('order_add_time','between',array($searchtime_arr[0], $searchtime_arr[1]));
+            $field .= ',MONTH(FROM_UNIXTIME(order_add_time)) as monthval,day(FROM_UNIXTIME(order_add_time)) as dayval ';
+            $orderlist = $stat_model->statByStatorder($where, $field, 0, 0, '', 'monthval,dayval');
+            foreach ($orderlist as $k => $v) {
+                if ($up_month == $v['monthval']) {
+                    $up_arr[$v['dayval']] = intval($v[$stattype]);
+                    $uplist_arr[$v['dayval']]['val'] = intval($v[$stattype]);
+                }
+                if ($curr_month == $v['monthval']) {
+                    $curr_arr[$v['dayval']] = intval($v[$stattype]);
+                    $currlist_arr[$v['dayval']]['val'] = intval($v[$stattype]);
+                }
+            }
+            $stat_arr['series'][0]['name'] = lang('last_month');
+            $stat_arr['series'][0]['data'] = array_values($up_arr);
+            $stat_arr['series'][1]['name'] = lang('this_month');
+            $stat_arr['series'][1]['data'] = array_values($curr_arr);
+        }
+        $stat_json = getStatData_LineLabels($stat_arr);
+        View::assign('stat_json', $stat_json);
+        View::assign('stattype', $stattype);
+        echo View::fetch('stat_linelabels');exit;
+    }
+
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array('name' => 'income', 'text' => lang('stat_sale_income'), 'url' => (string)url('Stattrade/income')),
+            array('name' => 'predeposit', 'text' => lang('stat_predeposit'), 'url' => (string)url('Stattrade/predeposit')),
+            array('name' => 'sale', 'text' => lang('stat_sale'), 'url' => (string)url('Stattrade/sale')),
+        );
+        return $menu_array;
+    }
+
+}

+ 1073 - 0
app/admin/controller/Store.php

@@ -0,0 +1,1073 @@
+<?php
+
+namespace app\admin\controller;
+
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Store extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/store.lang.php');
+    }
+
+    /**
+     * 店铺
+     */
+    public function store() {
+        $store_model = model('store');
+
+        $owner_and_name = input('get.owner_and_name');
+        if (trim($owner_and_name) != '') {
+            $condition[] = array('member_name', 'like', '%' . $owner_and_name . '%');
+        }
+        $store_name = input('get.store_name');
+        if (trim($store_name) != '') {
+            $condition[] = array('store_name', 'like', '%' . trim($store_name) . '%');
+        }
+        $grade_id = input('get.grade_id');
+        if (intval($grade_id) > 0) {
+            $condition[] = array('grade_id', '=', intval($grade_id));
+        }
+        $store_state = input('get.store_state');
+        switch ($store_state) {
+            case 'close':
+                $condition[] = array('store_state', '=', 0);
+                break;
+            case 'open':
+                $condition[] = array('store_state', '=', 1);
+                break;
+            case 'expired':
+                $condition[] = array('store_endtime', 'between', array(1, TIMESTAMP));
+                $condition[] = array('store_state', '=', 1);
+                break;
+            case 'expire':
+                $condition[] = array('store_endtime', 'between', array(TIMESTAMP, TIMESTAMP + 864000));
+                $condition[] = array('store_state', '=', 1);
+                break;
+        }
+
+        // 默认店铺管理不包含自营店铺
+        $condition[] = array('is_platform_store', '=', 0);
+
+        //店铺列表
+        $store_list = $store_model->getStoreList($condition, 10, 'store_id desc');
+        //店铺等级
+        $storegrade_model = model('storegrade');
+        $grade_list = $storegrade_model->getStoregradeList();
+        $search_grade_list = array();
+        if (!empty($grade_list)) {
+            $search_grade_list[0] = lang('no_select_grade');
+            foreach ($grade_list as $k => $v) {
+                $search_grade_list[$v['storegrade_id']] = $v['storegrade_name'];
+            }
+        }
+        View::assign('search_grade_list', $search_grade_list);
+
+        View::assign('grade_list', $grade_list);
+        View::assign('store_list', $store_list);
+        View::assign('store_state_list', $this->_get_store_state_array());
+        View::assign('show_page', $store_model->page_info->render());
+        $this->setAdminCurItem('store');
+        return View::fetch('store');
+    }
+
+    private function _get_store_state_array() {
+        return array(
+            'open' => lang('ds_open'),
+            'close' => lang('ds_close'),
+            'expire' => lang('about_to_expire'),
+            'expired' => lang('has_expired')
+        );
+    }
+
+    /**
+     * 店铺编辑
+     */
+    public function store_edit() {
+        $store_id = input('param.store_id');
+        $store_model = model('store');
+        //取店铺信息
+        $store_array = $store_model->getStoreInfoByID($store_id);
+        if (empty($store_array)) {
+            $this->error(lang('store_no_exist'));
+        }
+        //保存
+        if (!request()->isPost()) {
+
+            //整理店铺内容
+            $store_array['store_endtime'] = $store_array['store_endtime'] ? date('Y-m-d', $store_array['store_endtime']) : '';
+            //店铺分类
+            $storeclass_model = model('storeclass');
+            $parent_list = $storeclass_model->getStoreclassList(array(), '', false);
+
+            //店铺等级
+            $storegrade_model = model('storegrade');
+            $grade_list = $storegrade_model->getStoregradeList();
+            View::assign('grade_list', $grade_list);
+            View::assign('class_list', $parent_list);
+            View::assign('store_array', $store_array);
+
+            $joinin_detail = model('storejoinin')->getOneStorejoinin(array('member_id' => $store_array['member_id']));
+            View::assign('joinin_detail', $joinin_detail);
+            $this->setAdminCurItem('store_edit');
+            return View::fetch('store_edit');
+        } else {
+            //取店铺等级的审核
+            $storegrade_model = model('storegrade');
+            $grade_array = $storegrade_model->getOneStoregrade(intval(input('post.grade_id')));
+            if (empty($grade_array)) {
+                $this->error(lang('please_input_store_level'));
+            }
+            //结束时间
+            $time = '';
+            if (trim(input('post.end_time')) != '') {
+                $time = strtotime(input('post.end_time'));
+            }
+            $update_array = array();
+            $update_array['store_name'] = trim(input('post.store_name'));
+            $update_array['storeclass_id'] = intval(input('post.storeclass_id'));
+            $update_array['grade_id'] = intval(input('post.grade_id'));
+            $update_array['store_endtime'] = $time;
+            $update_array['store_state'] = intval(input('post.store_state'));
+            $update_array['store_baozh'] = trim(input('post.store_baozh')); //保障服务开关
+            $update_array['store_qtian'] = trim(input('post.store_qtian')); //保障服务-七天退换
+            $update_array['store_zhping'] = trim(input('post.store_zhping')); //保障服务-正品保证
+            $update_array['store_erxiaoshi'] = trim(input('post.store_erxiaoshi')); //保障服务-两小时发货
+            $update_array['store_tuihuo'] = trim(input('post.store_tuihuo')); //保障服务-退货承诺
+            $update_array['store_shiyong'] = trim(input('post.store_shiyong')); //保障服务-试用
+            $update_array['store_xiaoxie'] = trim(input('post.store_xiaoxie')); //保障服务-消协
+            $update_array['store_huodaofk'] = trim(input('post.store_huodaofk')); //保障服务-货到付款
+            $update_array['store_shiti'] = trim(input('post.store_shiti')); //保障服务-实体店铺
+            $data['store_type'] = input('post.store_type') == 1 ? 1 : 0;
+            $condition = array();
+            $condition[] = array('member_id', '=', intval(input('post.member_id')));
+            if ($update_array['store_state'] == 0) {
+                //根据店铺状态修改该店铺所有商品状态
+                $goods_model = model('goods');
+                $goods_model->editProducesOffline(array(array('store_id', '=', $store_id)));
+                $update_array['store_close_info'] = trim(input('post.store_close_info'));
+                $update_array['store_recommend'] = 0;
+            } else {
+                //店铺开启后商品不在自动上架,需要手动操作
+                $update_array['store_close_info'] = '';
+            }
+            if ($update_array['store_name'] != $store_array['store_name']) {
+                $goods_model = model('goods');
+                $goods_model->editGoodsCommon(array('store_name' => $update_array['store_name']), array('store_id' => $store_id));
+                $goods_model->editGoods(array('store_name' => $update_array['store_name']), array('store_id' => $store_id));
+            }
+            $result = $store_model->editStore($update_array, array('store_id' => $store_id));
+            $store_type = model('Storejoinin')->editStorejoinin($data, $condition);
+            if ($result || $store_type) {
+                //店铺名称修改处理 
+                $store_name = trim(input('post.store_name'));
+                $store_info = $store_model->getStoreInfoByID($store_id);
+                if (!empty($store_name)) {
+                    $condition = array();
+                    $condition[] = array('store_id', '=', $store_id);
+                    $update = array();
+                    $update['store_name'] = $store_name;
+                    $bllGoods = $store_model->editGoodscommon($condition, $update);
+                    $bllGoods = $store_model->editGoods($condition, $update);
+                }
+
+                $this->log(lang('ds_edit') . lang('ds_store') . '[' . input('post.store_name') . ']', 1);
+                $this->success(lang('ds_common_save_succ'), (string) url('Store/store'));
+            } else {
+                $this->log(lang('ds_edit') . lang('ds_store') . '[' . input('post.store_name') . ']', 1);
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑保存注册信息
+     */
+    public function edit_save_joinin() {
+        if (request()->isPost()) {
+            $member_id = input('post.member_id');
+            if ($member_id <= 0) {
+                $this->error(lang('param_error'));
+            }
+            $param = array();
+            $param['company_name'] = input('post.company_name');
+            $param['company_province_id'] = intval(input('post.province_id'));
+            $param['company_address'] = input('post.company_address');
+            $param['company_address_detail'] = input('post.company_address_detail');
+            $param['company_registered_capital'] = intval(input('post.company_registered_capital'));
+            $param['contacts_name'] = input('post.contacts_name');
+            $param['contacts_phone'] = input('post.contacts_phone');
+            $param['contacts_email'] = input('post.contacts_email');
+            $param['business_licence_number'] = input('post.business_licence_number');
+            $param['business_licence_address'] = input('post.business_licence_address');
+            $param['business_licence_start'] = input('post.business_licence_start');
+            $param['business_licence_end'] = input('post.business_licence_end');
+            $param['business_sphere'] = input('post.business_sphere');
+            if (!empty($_FILES['business_licence_number_electronic']['name'])) {
+                $param['business_licence_number_electronic'] = $this->upload_image('business_licence_number_electronic');
+            }
+
+
+            $param['bank_account_name'] = input('post.bank_account_name');
+            $param['bank_account_number'] = input('post.bank_account_number');
+            $param['bank_name'] = input('post.bank_name');
+            $param['bank_address'] = input('post.bank_address');
+
+            $param['settlement_bank_account_name'] = input('post.settlement_bank_account_name');
+            $param['settlement_bank_account_number'] = input('post.settlement_bank_account_number');
+            $param['settlement_bank_name'] = input('post.settlement_bank_name');
+            $param['settlement_bank_address'] = input('post.settlement_bank_address');
+
+            $result = model('storejoinin')->editStorejoinin($param, array('member_id' => $member_id));
+            if ($result >= 0) {
+                //更新店铺信息
+                $store_update = array();
+                $store_update['store_company_name'] = $param['company_name'];
+                $store_update['area_info'] = $param['company_address'];
+                $store_update['store_address'] = $param['company_address_detail'];
+                $store_model = model('store');
+                $store_info = $store_model->getStoreInfo(array('member_id' => $member_id));
+                if (!empty($store_info)) {
+                    $r = $store_model->editStore($store_update, array('member_id' => $member_id));
+                    $this->log('编辑店铺信息' . '[ID:' . $r . ']', 1);
+                }
+                $this->success(lang('ds_common_op_succ'), (string) url('Store/store'));
+            } else {
+                $this->error(lang('ds_common_op_fail'));
+            }
+        }
+    }
+
+    private function upload_image($file) {
+
+        //上传文件保存路径
+        $pic_name = '';
+
+        if (!empty($_FILES[$file]['name'])) {
+            //设置特殊图片名称
+            $member_id = input('post.member_id');
+            $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
+
+            $res = ds_upload_pic('home' . DIRECTORY_SEPARATOR . 'store_joinin', $file, $file_name);
+            if ($res['code']) {
+                $pic_name = $res['data']['file_name'];
+            } else {
+                $this->error($res['msg']);
+            }
+        }
+        return $pic_name;
+    }
+
+    /**
+     * 店铺经营类目管理
+     */
+    public function store_bind_class() {
+
+        $store_id = intval(input('param.store_id'));
+
+        $store_model = model('store');
+        $storebindclass_model = model('storebindclass');
+        $goodsclass_model = model('goodsclass');
+
+        $gc_list = $goodsclass_model->getGoodsclassListByParentId(0);
+        View::assign('gc_list', $gc_list);
+
+        $store_info = $store_model->getStoreInfoByID($store_id);
+        if (empty($store_info)) {
+            $this->error(lang('param_error'));
+        }
+        View::assign('store_info', $store_info);
+
+        $store_bind_class_list = $storebindclass_model->getStorebindclassList(array(array('store_id', '=', $store_id), array('storebindclass_state', 'in', array(1, 2))), null);
+        $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
+        for ($i = 0, $j = count($store_bind_class_list); $i < $j; $i++) {
+            $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
+            $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
+            $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
+        }
+        View::assign('store_bind_class_list', $store_bind_class_list);
+        $this->setAdminCurItem('store_bind_class');
+        return View::fetch('store_bind_class');
+    }
+
+    /**
+     * 添加经营类目
+     */
+    public function store_bind_class_add() {
+        $store_id = intval(input('post.store_id'));
+        $commis_rate = intval(input('post.commis_rate'));
+        if ($commis_rate < 0 || $commis_rate > 100) {
+            $this->error(lang('param_error'));
+        }
+        @list($class_1, $class_2, $class_3) = explode(',', input('post.goods_class'));
+
+        $storebindclass_model = model('storebindclass');
+
+        $param = array();
+        $param['store_id'] = $store_id;
+        $param['class_1'] = $class_1;
+        $param['storebindclass_state'] = 1;
+        if (!empty($class_2)) {
+            $param['class_2'] = $class_2;
+        }
+        if (!empty($class_3)) {
+            $param['class_3'] = $class_3;
+        }
+
+        // 检查类目是否已经存在
+        $store_bind_class_info = $storebindclass_model->getStorebindclassInfo($param);
+        if (!empty($store_bind_class_info)) {
+            $this->error(lang('storeclass_has_exist'));
+        }
+
+        $param['commis_rate'] = $commis_rate;
+        $result = $storebindclass_model->addStorebindclass($param);
+
+        if ($result) {
+            $this->log('新增店铺经营类目,类目编号:' . $result . ',店铺编号:' . $store_id);
+            $this->success(lang('ds_common_save_succ'));
+        } else {
+            $this->error(lang('ds_common_save_fail'));
+        }
+    }
+
+    /**
+     * 删除经营类目
+     */
+    public function store_bind_class_del() {
+        $bid = intval(input('param.bid'));
+
+
+        $storebindclass_model = model('storebindclass');
+        $goods_model = model('goods');
+
+        $store_bind_class_info = $storebindclass_model->getStorebindclassInfo(array('storebindclass_id' => $bid));
+        if (empty($store_bind_class_info)) {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+
+        // 商品下架
+        $condition = array();
+        $condition[] = array('store_id', '=', $store_bind_class_info['store_id']);
+        $gc_id = $store_bind_class_info['class_1'] . ',' . $store_bind_class_info['class_2'] . ',' . $store_bind_class_info['class_3'];
+        $update = array();
+        $update['goods_stateremark'] = lang('admin_delete_store_bind_class');
+        $condition[] = array('gc_id', 'in', rtrim($gc_id, ','));
+        $goods_model->editProducesLockUp($update, $condition);
+
+        $result = $storebindclass_model->delStorebindclass(array('storebindclass_id' => $bid));
+
+        if (!$result) {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        } else {
+            $this->log('删除店铺经营类目,类目编号:' . $bid . ',店铺编号:' . $store_bind_class_info['store_id']);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        }
+    }
+
+    public function store_bind_class_update() {
+        $bid = intval(input('param.id'));
+        if ($bid <= 0) {
+            echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
+            die;
+        }
+        $new_commis_rate = intval(input('param.value'));
+        if ($new_commis_rate < 0 || $new_commis_rate >= 100) {
+            echo json_encode(array('result' => FALSE, 'message' => lang('param_error')));
+            die;
+        } else {
+            $update = array('commis_rate' => $new_commis_rate);
+            $condition = array('storebindclass_id' => $bid);
+            $storebindclass_model = model('storebindclass');
+            $result = $storebindclass_model->editStorebindclass($update, $condition);
+            if ($result) {
+                $this->log('更新店铺经营类目,类目编号:' . $bid);
+                echo json_encode(array('result' => TRUE));
+                die;
+            } else {
+                echo json_encode(array('result' => FALSE, 'message' => lang('ds_common_op_fail')));
+                die;
+            }
+        }
+    }
+
+    /**
+     * 店铺 待审核列表
+     */
+    public function store_joinin() {
+        $condition = array();
+        //店铺列表
+        if (input('param.owner_and_name')) {
+            $condition[] = array('member_name', 'like', '%' . input('param.owner_and_name') . '%');
+        }
+        if (input('param.store_name')) {
+            $condition[] = array('store_name', 'like', '%' . input('param.store_name') . '%');
+        }
+        if (input('param.grade_id') && intval(input('param.grade_id')) > 0) {
+            $condition[] = array('storegrade_id', '=', input('param.grade_id'));
+        }
+        if (input('param.joinin_state') && intval(input('param.joinin_state')) > 0) {
+            $condition[] = array('joinin_state', '=', input('param.joinin_state'));
+        } else {
+            $condition[] = array('joinin_state', '>', 0);
+        }
+        $storejoinin_model = model('storejoinin');
+        $store_list = $storejoinin_model->getStorejoininList($condition, 10, 'joinin_state asc');
+        View::assign('store_list', $store_list);
+        View::assign('joinin_state_array', $this->get_store_joinin_state());
+
+        //店铺等级
+        $storegrade_model = model('storegrade');
+        $grade_list = $storegrade_model->getStoregradeList();
+        View::assign('grade_list', $grade_list);
+
+        View::assign('show_page', $storejoinin_model->page_info->render());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('store_joinin');
+        return View::fetch('store_joinin');
+    }
+
+    /**
+     * 经营类目申请列表
+     */
+    public function store_bind_class_applay_list() {
+        $condition = array();
+        // 不显示自营店铺绑定的类目
+        $state = input('param.state');
+        if ($state != '') {
+            if (in_array($state, array('0', '1',))) {
+                $condition[] = array('storebindclass_state', '=', intval($state));
+            }
+        } else {
+            $condition[] = array('storebindclass_state', 'in', array('0', '1',));
+        }
+
+        $store_id = input('store_id');
+        if (intval($store_id)) {
+            $condition[] = array('store_id', '=', intval($store_id));
+        }
+
+        $storebindclass_model = model('storebindclass');
+        $store_bind_class_list = $storebindclass_model->getStorebindclassList($condition, 15, 'storebindclass_state asc,storebindclass_id desc');
+        $goods_class = model('goodsclass')->getGoodsclassIndexedListAll();
+        $store_ids = array();
+
+        for ($i = 0; $i < count($store_bind_class_list); $i++) {
+            $store_bind_class_list[$i]['class_1_name'] = @$goods_class[$store_bind_class_list[$i]['class_1']]['gc_name'];
+            $store_bind_class_list[$i]['class_2_name'] = @$goods_class[$store_bind_class_list[$i]['class_2']]['gc_name'];
+            $store_bind_class_list[$i]['class_3_name'] = @$goods_class[$store_bind_class_list[$i]['class_3']]['gc_name'];
+            $store_ids[] = $store_bind_class_list[$i]['store_id'];
+        }
+
+        //取店铺信息
+        $store_model = model('store');
+        $store_list = $store_model->getStoreList(array(array('store_id', 'in', $store_ids)), null);
+        $bind_store_list = array();
+        if (!empty($store_list) && is_array($store_list)) {
+            foreach ($store_list as $k => $v) {
+                $bind_store_list[$v['store_id']]['store_name'] = $v['store_name'];
+                $bind_store_list[$v['store_id']]['seller_name'] = $v['seller_name'];
+            }
+        }
+        View::assign('bind_list', $store_bind_class_list);
+        View::assign('bind_store_list', $bind_store_list);
+
+        View::assign('show_page', $storebindclass_model->page_info->render());
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        $this->setAdminCurItem('store_bind_class_applay_list');
+        return View::fetch('bind_class_applay_list');
+    }
+
+    /**
+     * 审核经营类目申请
+     */
+    public function store_bind_class_applay_check() {
+        $storebindclass_model = model('storebindclass');
+        $condition = array();
+        $condition[] = array('storebindclass_id', '=', intval(input('param.bid')));
+        $condition[] = array('storebindclass_state', '=', 0);
+        $update = $storebindclass_model->editStorebindclass(array('storebindclass_state' => 1), $condition);
+        if ($update) {
+            $this->log('审核新经营类目申请,店铺ID:' . input('param.store_id'), 1);
+            ds_json_encode(10000, lang('ds_common_op_succ'));
+        } else {
+            $this->error(lang('ds_common_op_fail'), get_referer());
+        }
+    }
+
+    /**
+     * 删除经营类目申请
+     */
+    public function store_bind_class_applay_del() {
+        $storebindclass_model = model('storebindclass');
+        $condition = array();
+        $condition[] = array('storebindclass_id', '=', intval(input('param.bid')));
+        $del = $storebindclass_model->delStorebindclass($condition);
+        if ($del) {
+            $this->log('删除经营类目,店铺ID:' . input('param.store_id'), 1);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        } else {
+            $this->error(lang('ds_common_del_fail'), get_referer());
+        }
+    }
+
+    private function get_store_joinin_state() {
+        $joinin_state_array = array(
+            STORE_JOIN_STATE_NEW => lang('store_join_state_new'),
+            STORE_JOIN_STATE_PAY => lang('store_join_state_pay'),
+            STORE_JOIN_STATE_VERIFY_SUCCESS => lang('storereopen_state_0'),
+            STORE_JOIN_STATE_VERIFY_FAIL => lang('store_join_state_verify_fail'),
+            STORE_JOIN_STATE_PAY_FAIL => lang('store_join_state_pay_fail'),
+            STORE_JOIN_STATE_FINAL => lang('store_join_state_final'),
+        );
+        return $joinin_state_array;
+    }
+
+    /**
+     * 店铺续签申请列表
+     */
+    public function reopen_list() {
+        $condition = array();
+        $store_id = input('get.store_id');
+        if (intval($store_id)) {
+            $condition[] = array('storereopen_store_id', '=', intval($store_id));
+        }
+        $store_name = input('get.store_name');
+        if (!empty($store_name)) {
+            $condition[] = array('storereopen_store_name', '=', $store_name);
+        }
+        $storereopen_state = input('get.storereopen_state');
+        if ($storereopen_state != '') {
+            $condition[] = array('storereopen_state', '=', intval($storereopen_state));
+        }
+        $storereopen_model = model('storereopen');
+        $reopen_list = $storereopen_model->getStorereopenList($condition, 15);
+
+        View::assign('reopen_list', $reopen_list);
+
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+
+        View::assign('show_page', $storereopen_model->page_info->render());
+        $this->setAdminCurItem('reopen_list');
+        return View::fetch('store_reopen_list');
+    }
+
+    /**
+     * 审核店铺续签申请
+     */
+    public function reopen_check() {
+        if (intval(input('param.storereopen_id')) <= 0)
+            exit();
+        $storereopen_model = model('storereopen');
+        $condition = array();
+        $condition[] = array('storereopen_id', '=', intval(input('param.storereopen_id')));
+        $condition[] = array('storereopen_state', '=', 1);
+        //取当前申请信息
+        $reopen_info = $storereopen_model->getStorereopenInfo($condition);
+
+        $data = array();
+        $data['storereopen_state'] = 2;
+        $update = $storereopen_model->editStorereopen($data, $condition);
+        //取目前店铺有效截止日期
+        $store_info = model('store')->getStoreInfoByID($reopen_info['storereopen_store_id']);
+        $start_time = strtotime(date('Y-m-d 0:0:0', $store_info['store_endtime'])) + 24 * 3600;
+        $new_store_endtime = strtotime(date('Y-m-d 23:59:59', $start_time) . " +" . intval($reopen_info['storereopen_year']) . " year");
+        if ($update) {
+            //更新店铺有效期
+            model('store')->editStore(array('store_endtime' => $new_store_endtime), array('store_id' => $reopen_info['storereopen_store_id']));
+            $msg = '审核通过店铺续签申请,店铺ID:' . $reopen_info['storereopen_store_id'];
+            $this->log($msg, 1);
+            ds_json_encode('10000', lang('ds_common_op_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_op_fail'));
+        }
+    }
+
+    /**
+     * 删除店铺续签申请
+     */
+    public function reopen_del() {
+        $storereopen_model = model('storereopen');
+        $condition = array();
+        $condition[] = array('storereopen_id', '=', intval(input('param.storereopen_id')));
+        $condition[] = array('storereopen_state', 'in', array(0, 1));
+
+        //取当前申请信息
+        $reopen_info = $storereopen_model->getStorereopenInfo($condition);
+        $cert_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE_JOININ . DIRECTORY_SEPARATOR . $reopen_info['storereopen_pay_cert'];
+        $del = $storereopen_model->delStorereopen($condition);
+        if ($del) {
+            if (is_file($cert_file)) {
+                unlink($cert_file);
+            }
+            $this->log('删除店铺续签目申请,店铺ID:' . input('param.storereopen_store_id'), 1);
+            ds_json_encode('10000', lang('ds_common_del_succ'));
+        } else {
+            ds_json_encode('10001', lang('ds_common_del_fail'));
+        }
+    }
+
+    /**
+     * 审核详细页
+     */
+    public function store_joinin_detail() {
+        $storejoinin_model = model('storejoinin');
+        $member_id = input('param.member_id');
+        $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => $member_id));
+        $joinin_detail_title = lang('ds_view');
+        if (in_array(intval($joinin_detail['joinin_state']), array(STORE_JOIN_STATE_NEW, STORE_JOIN_STATE_PAY))) {
+            $joinin_detail_title = lang('ds_verify');
+        }
+        if (!empty($joinin_detail['sg_info'])) {
+            $store_grade_info = model('storegrade')->getOneStoregrade($joinin_detail['storegrade_id']);
+            $joinin_detail['storegrade_price'] = $store_grade_info['storegrade_price'];
+        } else {
+            $joinin_detail['sg_info'] = @unserialize($joinin_detail['sg_info']);
+            if (is_array($joinin_detail['sg_info'])) {
+                $joinin_detail['storegrade_price'] = $joinin_detail['sg_info']['storegrade_price'];
+            }
+        }
+
+        View::assign('joinin_detail_title', $joinin_detail_title);
+        View::assign('joinin_detail', $joinin_detail);
+        return View::fetch('store_joinin_detail');
+    }
+
+    /**
+     * 审核
+     */
+    public function store_joinin_verify() {
+        $storejoinin_model = model('storejoinin');
+        $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => input('param.member_id')));
+
+        switch (intval($joinin_detail['joinin_state'])) {
+            case STORE_JOIN_STATE_NEW:
+                $this->store_joinin_verify_pass($joinin_detail);
+                break;
+            case STORE_JOIN_STATE_PAY:
+                $this->store_joinin_verify_open($joinin_detail);
+                break;
+            default:
+                $this->error(lang('param_error'));
+                break;
+        }
+    }
+
+    private function store_joinin_verify_pass($joinin_detail) {
+        $param = array();
+        $param['joinin_state'] = input('post.verify_type') === 'pass' ? STORE_JOIN_STATE_VERIFY_SUCCESS : STORE_JOIN_STATE_VERIFY_FAIL;
+        $param['joinin_message'] = input('post.joinin_message');
+        $param['paying_amount'] = abs(floatval(input('post.paying_amount')));
+        $commis_rate_array = input('post.commis_rate/a'); #获取数组
+        $param['store_class_commis_rates'] = is_array($commis_rate_array) ? implode(',', $commis_rate_array) : '';
+        $storejoinin_model = model('storejoinin');
+        $storejoinin_model->editStorejoinin($param, array('member_id' => input('post.member_id')));
+        if ($param['paying_amount'] > 0) {
+            dsLayerOpenSuccess(lang('store_join_verify_final'));
+        } else {
+            //如果开店支付费用为零,则审核通过后直接开通,无需再上传付款凭证
+            $this->store_joinin_verify_open($joinin_detail);
+        }
+    }
+
+    private function store_joinin_verify_open($joinin_detail) {
+        $storejoinin_model = model('storejoinin');
+        $store_model = model('store');
+
+
+        $param = array();
+        $param['joinin_state'] = input('post.verify_type') === 'pass' ? STORE_JOIN_STATE_FINAL : STORE_JOIN_STATE_PAY_FAIL;
+        $param['joinin_message'] = input('post.joinin_message');
+
+        if (input('post.verify_type') === 'pass') {
+            Db::startTrans();
+            try{
+                $store_model->setStoreOpen($joinin_detail,$param);
+            }catch(\Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+            Db::commit();
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        } else {
+            Db::startTrans();
+            try{
+                $predeposit_model = model('predeposit');
+                if($joinin_detail['rcb_amount']>0){
+                            $data_pd = array();
+                            $data_pd['member_id'] = $joinin_detail['member_id'];
+                            $data_pd['member_name'] = $joinin_detail['member_name'];
+                            $data_pd['amount'] = $joinin_detail['rcb_amount'];
+                            $data_pd['order_sn'] = $joinin_detail['pay_sn'];
+                            $predeposit_model->changeRcb('storejoinin_cancel', $data_pd);
+                }
+                if($joinin_detail['pd_amount']>0){
+                            $data_pd = array();
+                            $data_pd['member_id'] = $joinin_detail['member_id'];
+                            $data_pd['member_name'] = $joinin_detail['member_name'];
+                            $data_pd['amount'] = $joinin_detail['pd_amount'];
+                            $data_pd['order_sn'] = $joinin_detail['pay_sn'];
+                            $predeposit_model->changePd('storejoinin_cancel', $data_pd);
+                }
+            //改变店铺状态
+            $storejoinin_model->editStorejoinin($param, array('member_id' => input('param.member_id')));
+            }catch(\Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+            }
+            Db::commit();
+
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+//            $this->error(lang('store_open_reject'));
+        }
+    }
+
+    /**
+     * 提醒续费
+     */
+    public function remind_renewal() {
+        $store_id = intval(input('param.store_id'));
+        $store_info = model('store')->getStoreInfoByID($store_id);
+        if (!empty($store_info) && $store_info['store_endtime'] < (TIMESTAMP + 864000) && cookie('remindRenewal' . $store_id) == null) {
+            // 发送商家消息
+            $param = array();
+            $param['code'] = 'store_expire';
+            $param['store_id'] = intval(input('param.store_id'));
+            $param['param'] = array();
+            $param['ali_param'] = array();
+            $param['ten_param'] = array();
+            //微信模板消息
+            $param['weixin_param'] = array(
+//                    'url' => config('ds_config.h5_site_url').'/seller/complaint_form?complain_id='.$complain_id,
+                'data' => array(
+                    "keyword1" => array(
+                        "value" => $store_info['store_name'],
+                        "color" => "#333"
+                    ),
+                    "keyword2" => array(
+                        "value" => date('Y-m-d', $store_info['store_endtime']),
+                        "color" => "#333"
+                    )
+                ),
+            );
+            model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize($param)));
+
+            cookie('remindRenewal' . $store_id, 1, 86400 * 10);  // 十天
+            $this->success(lang('ds_common_op_succ'));
+        }
+        $this->error(lang('ds_common_op_fail'));
+    }
+
+    /*
+      //删除店铺操作,暂时屏蔽
+      public function del() {
+      $store_id = intval(input('param.id'));
+      $store_model = model('store');
+      $storeArray = $store_model->field('is_platform_store,store_name')->find($store_id);
+      if (empty($storeArray)) {
+      ds_json_encode('10001', lang('外驻店铺不存在'));
+      }
+      if ($storeArray['is_platform_store']) {
+      ds_json_encode('10001', lang('不能在此删除自营店铺'));
+      }
+      $condition = array(
+      'store_id' => $store_id,
+      );
+      if (model('goods')->getGoodsCount($condition) > 0){
+      ds_json_encode('10001', lang('已经发布商品的外驻店铺不能被删除'));
+      }
+      // 完全删除店铺
+      $store_model->delStoreEntirely($condition);
+      //删除入驻相关
+      $member_id = intval(input('param.member_id'));
+      $store_joinin = model('storejoinin');
+      $condition = array(
+      'member_id' => $member_id,
+      );
+      $store_joinin->delStorejoinin($condition);
+      $this->log("删除外驻店铺: {$storeArray['store_name']}");
+      ds_json_encode('10000', lang('ds_common_del_succ'));
+      }
+     * 
+     */
+
+    //删除店铺操作 
+    public function del_join() {
+        $member_id = (int) input('param.member_id');
+        $store_joinin = model('storejoinin');
+        $condition = array(
+            'member_id' => $member_id,
+        );
+        $mm = $store_joinin->getOneStorejoinin($condition);
+        if (empty($mm)) {
+            $this->error(lang('ds_common_op_fail'), get_referer());
+        }
+        if ($mm['joinin_state'] == '20') {
+            
+        }
+        $store_name = $mm['store_name'];
+        $store_model = model('store');
+        $scount = $store_model->getStoreCount($condition);
+        if ($scount > 0) {
+            $this->error(lang('store_exist'), get_referer());
+        }
+        Db::startTrans();
+        try{
+            $predeposit_model = model('predeposit');
+            if($mm['rcb_amount']>0){
+                        $data_pd = array();
+                        $data_pd['member_id'] = $mm['member_id'];
+                        $data_pd['member_name'] = $mm['member_name'];
+                        $data_pd['amount'] = $mm['rcb_amount'];
+                        $data_pd['order_sn'] = $mm['pay_sn'];
+                        $predeposit_model->changeRcb('storejoinin_cancel', $data_pd);
+            }
+            if($mm['pd_amount']>0){
+                        $data_pd = array();
+                        $data_pd['member_id'] = $mm['member_id'];
+                        $data_pd['member_name'] = $mm['member_name'];
+                        $data_pd['amount'] = $mm['pd_amount'];
+                        $data_pd['order_sn'] = $mm['pay_sn'];
+                        $predeposit_model->changePd('storejoinin_cancel', $data_pd);
+            }
+        // 完全删除店铺入驻
+        $store_joinin->delStorejoinin($condition);
+        }catch(\Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+        }
+        Db::commit();
+
+        $this->log(lang('del_store') . ":" . $store_name);
+        ds_json_encode('10000', lang('ds_common_del_succ'));
+    }
+
+    public function newshop_add() {
+        if (!request()->isPost()) {
+            return View::fetch('store_newshop_add');
+        } else {
+
+            $member_name = input('post.member_name');
+            $member_password = input('post.member_password');
+            $seller_name = $member_name;
+            $store_name = input('post.store_name');
+
+            if (strlen($member_name) < 3 || strlen($member_name) > 15)
+                $this->error(lang('name_length_error'));
+
+            if (strlen($member_password) < 6)
+                $this->error(lang('member_password_minlength'));
+
+            if (!$this->checkMemberName($member_name))
+                $this->error(lang('member_name_exist'));
+
+
+            try {
+                $memberId = model('member')->addMember(array(
+                    'member_name' => $member_name,
+                    'member_password' => $member_password,
+                ));
+            } catch (Exception $ex) {
+                $this->error(lang('seller_account_add_fail'));
+            }
+
+            $store_model = model('store');
+
+            $saveArray = array();
+            $saveArray['store_name'] = $store_name;
+            $saveArray['member_id'] = $memberId;
+            $saveArray['member_name'] = $member_name;
+            $saveArray['seller_name'] = $seller_name;
+            $saveArray['bind_all_gc'] = 1;
+            $saveArray['store_state'] = 1;
+            $saveArray['store_addtime'] = TIMESTAMP;
+            $saveArray['is_platform_store'] = 0;
+            $saveArray['grade_id'] = 1;
+
+            $storeId = $store_model->addStore($saveArray);
+
+            model('seller')->addSeller(array(
+                'seller_name' => $seller_name,
+                'member_id' => $memberId,
+                'store_id' => $storeId,
+                'sellergroup_id' => 0,
+                'is_admin' => 1,
+            ));
+            model('storejoinin')->addStorejoinin(array(
+                'seller_name' => $seller_name,
+                'store_name' => $store_name,
+                'member_name' => $member_name,
+                'member_id' => $memberId,
+                'joinin_state' => 40,
+                'company_province_id' => 0,
+                'storeclass_bail' => 0,
+                'joinin_year' => 1,
+            ));
+
+            // 添加相册默认
+            $album_model = model('album');
+            $album_arr = array();
+            $album_arr['aclass_name'] = lang('store_save_defaultalbumclass_name');
+            $album_arr['store_id'] = $storeId;
+            $album_arr['aclass_des'] = '';
+            $album_arr['aclass_sort'] = '255';
+            $album_arr['aclass_cover'] = '';
+            $album_arr['aclass_uploadtime'] = TIMESTAMP;
+            $album_arr['aclass_isdefault'] = '1';
+            $album_model->addAlbumclass($album_arr);
+
+            //插入店铺扩展表
+            $store_model->addStoreextend(array('store_id' => $storeId));
+            // 删除自营店id缓存
+            model('store')->dropCachedOwnShopIds();
+
+            $this->log(lang('add_store') . ": {$saveArray['store_name']}");
+            $this->success(lang('add_store_bind_class'), (string) url('Store/store_bind_class', ['store_id' => $storeId]));
+        }
+    }
+
+    public function check_seller_name() {
+        echo json_encode($this->checkSellerName(input('param.seller_name')));
+        exit;
+    }
+
+    private function checkSellerName($sellerName) {
+        // 判断store_joinin是否存在记录
+        $count = (int) model('storejoinin')->getStorejoininCount(array(
+                    'seller_name' => $sellerName,
+        ));
+        if ($count > 0)
+            return false;
+
+        $seller = model('seller')->getSellerInfo(array(
+            'seller_name' => $sellerName,
+        ));
+        if (!empty($seller)) {
+            return false;
+        }
+        return TRUE;
+    }
+
+    public function check_member_name() {
+        echo json_encode($this->checkMemberName(input('param.member_name')));
+        exit;
+    }
+
+    private function checkMemberName($member_name) {
+        // 判断store_joinin是否存在记录
+        $count = (int) model('storejoinin')->getStorejoininCount(array(
+                    'member_name' => $member_name,
+        ));
+        if ($count > 0)
+            return false;
+
+        return !model('member')->getMemberCount(array(
+                    'member_name' => $member_name,
+        ));
+    }
+
+    /**
+     * 验证店铺名称是否存在
+     */
+    public function ckeck_store_name() {
+        $where = array();
+        $where[] = array('store_name', '=', input('param.store_name'));
+        $where[] = array('store_id', '<>', input('param.store_id'));
+        $store_info = model('store')->getStoreInfo($where);
+        if (!empty($store_info['store_name'])) {
+            echo 'false';
+        } else {
+            echo 'true';
+        }
+    }
+
+    /**
+     * 验证店铺名称是否存在
+     */
+    private function ckeckStoreName($store_name) {
+        $condition = array();
+        $condition[] = array('store_name', '=', $store_name);
+        $store_info = model('store')->getStoreInfo($condition);
+        if (!empty($store_info['store_name'])) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    //ajax操作
+    public function ajax() {
+        $store_model = model('store');
+        switch (input('param.branch')) {
+            /**
+             * 品牌名称
+             */
+            case 'store_sort':
+                $id = intval(input('param.id'));
+                $result = $store_model->editStore(array('store_sort' => trim(input('param.value'))), array('store_id' => $id));
+                if ($result) {
+                    $this->log(lang('ds_edit') . lang('ds_store') . '[' . $id . ']', 1);
+                }
+                echo 'true';
+                exit;
+                break;
+        }
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'store',
+                'text' => lang('ds_manage'),
+                'url' => (string) url('Store/store')
+            ), array(
+                'name' => 'store_joinin',
+                'text' => lang('pending'),
+                'url' => (string) url('Store/store_joinin')
+            ), array(
+                'name' => 'reopen_list',
+                'text' => lang('reopen_list'),
+                'url' => (string) url('Store/reopen_list')
+            ), array(
+                'name' => 'store_bind_class_applay_list',
+                'text' => lang('store_bind_class_apply'),
+                'url' => (string) url('Store/store_bind_class_applay_list')
+            ), array(
+                'name' => 'newshop_add',
+                'text' => lang('add_store'),
+                'url' => "javascript:dsLayerOpen('" . (string) url('Store/newshop_add') . "','" . lang('add_store') . "')"
+            )
+        );
+        if (request()->action() == 'store_bind_class') {
+            $menu_array[] = [
+                'name' => 'store_bind_class', 'text' => lang('ds_edit') . lang('store_bind_class'), 'url' => '#'
+            ];
+        }
+        return $menu_array;
+    }
+
+}
+
+?>

+ 189 - 0
app/admin/controller/Storeclass.php

@@ -0,0 +1,189 @@
+<?php
+
+/**
+ * 店铺分类
+ */
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Storeclass extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storeclass.lang.php');
+    }
+
+    /**
+     * 店铺分类
+     */
+    public function store_class() {
+        $storeclass_model = model('storeclass');
+
+        $store_class_list = $storeclass_model->getStoreclassList(array(), 20);
+        View::assign('class_list', $store_class_list);
+        View::assign('show_page', $storeclass_model->page_info->render());
+        $this->setAdminCurItem('store_class');
+        return View::fetch('index');
+    }
+
+    /**
+     * 商品分类添加
+     */
+    public function store_class_add() {
+        $storeclass_model = model('storeclass');
+
+        if (!request()->isPost()) {
+            $this->setAdminCurItem('store_class_add');
+            return View::fetch('form');
+        } else {
+            $insert_array = array();
+            $insert_array['storeclass_name'] = input('post.storeclass_name');
+            $insert_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
+            $insert_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
+
+            $storeclass_validate = ds_validate('storeclass');
+            if (!$storeclass_validate->scene('store_class_add')->check($insert_array)){
+                $this->error($storeclass_validate->getError());
+            }
+
+
+            $result = $storeclass_model->addStoreclass($insert_array);
+            if ($result) {
+                $this->log(lang('ds_add') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'),(string)url('Storeclass/store_class'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 编辑
+     */
+    public function store_class_edit() {
+        $storeclass_model = model('storeclass');
+
+        if (!request()->isPost()) {
+            $storeclass = $storeclass_model->getStoreclassInfo(array('storeclass_id' => intval(input('param.storeclass_id'))));
+            if (empty($storeclass)) {
+                $this->error(lang('illegal_parameter'));
+            }
+
+            View::assign('storeclass', $storeclass);
+            $this->setAdminCurItem('store_class_edit');
+            return View::fetch('form');
+        } else {
+            $update_array = array();
+            $update_array['storeclass_name'] = input('post.storeclass_name');
+            $update_array['storeclass_bail'] = intval(input('post.storeclass_bail'));
+            $update_array['storeclass_sort'] = intval(input('post.storeclass_sort'));
+
+            $storeclass_validate = ds_validate('storeclass');
+            if (!$storeclass_validate->scene('store_class_edit')->check($update_array)){
+                $this->error($storeclass_validate->getError());
+            }
+
+            $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.storeclass_id'))));
+            if ($result>=0) {
+                $this->log(lang('ds_edit') . lang('store_class') . '[' . input('post.storeclass_name') . ']', 1);
+                dsLayerOpenSuccess(lang('ds_common_save_succ'),(string)url('Storeclass/store_class'));
+            } else {
+                $this->error(lang('ds_common_save_fail'));
+            }
+        }
+    }
+
+    /**
+     * 删除分类
+     */
+    public function store_class_del() {
+        $storeclass_model = model('storeclass');
+        $storeclass_id = input('param.storeclass_id');
+        $storeclass_id_array = ds_delete_param($storeclass_id);
+        if ($storeclass_id_array === FALSE) {
+            ds_json_encode('10001', lang('param_error'));
+        }
+        $condition = array();
+        $condition[]=array('storeclass_id','in', $storeclass_id_array);
+
+        $result = $storeclass_model->delStoreclass($condition);
+        if ($result) {
+            $this->log(lang('ds_del') . lang('store_class') . '[ID:' . $storeclass_id . ']', 1);
+            ds_json_encode(10000, lang('ds_common_del_succ'));
+        }
+    }
+
+    /**
+     * ajax操作
+     */
+    public function ajax() {
+        $storeclass_model = model('storeclass');
+        $update_array = array();
+        $branch = input('param.branch');
+        switch ($branch) {
+            //分类:验证是否有重复的名称
+            case 'store_class_name':
+                $condition = array();
+                $condition[]=array('storeclass_name','=',input('get.value'));
+                $condition[]=array('storeclass_id','<>', intval(input('param.id')));
+                $class_list = $storeclass_model->getStoreclassList($condition);
+                if (empty($class_list)) {
+                    $update_array['storeclass_name'] = input('get.value');
+                    $update = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
+                    $return = 'true';
+                } else {
+                    $return = 'false';
+                }
+                break;
+            //分类: 排序 显示 设置
+            case 'store_class_sort':
+                $update_array['storeclass_sort'] = intval(input('get.value'));
+                $result = $storeclass_model->editStoreclass($update_array, array('storeclass_id' => intval(input('param.id'))));
+                $return = 'true';
+                break;
+            //分类:添加、修改操作中 检测类别名称是否有重复
+            case 'check_class_name':
+                $condition[]=array('storeclass_name','=',input('get.storeclass_name'));
+                $class_list = $storeclass_model->getStoreclassList($condition);
+                $return = empty($class_list) ? 'true' : 'false';
+                break;
+        }
+        exit($return);
+    }
+
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'store_class',
+                'text' => lang('ds_storeclass'),
+                'url' => (string)url('Storeclass/store_class')
+            ),
+            array(
+                'name' => 'store_class_add',
+                'text' => lang('ds_new'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Storeclass/store_class_add')."','".lang('ds_new')."')"
+            )
+        );
+        return $menu_array;
+    }
+
+}
+
+?>

+ 341 - 0
app/admin/controller/Storedeposit.php

@@ -0,0 +1,341 @@
+<?php
+
+namespace app\admin\controller;
+use think\facade\View;
+use think\facade\Lang;
+use think\facade\Db;
+use app\common\model\Storedepositlog;
+use app\common\model\Storemoneylog;
+/**
+ * ============================================================================
+ * DSMall多用户商城
+ * ============================================================================
+ * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
+ * 网站地址: http://www.csdeshang.com
+ * ----------------------------------------------------------------------------
+ * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
+ * 不允许对程序代码以任何形式任何目的的再发布。
+ * ============================================================================
+ * 控制器
+ */
+class Storedeposit extends AdminControl {
+
+    public function initialize() {
+        parent::initialize();
+        Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storedeposit.lang.php');
+    }
+
+
+    /*
+     * 资金明细
+     */
+
+    public function index() {
+        $condition = array();
+        $stime = input('get.stime');
+        $etime = input('get.etime');
+        $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
+        $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
+        $start_unixtime = $if_start_date ? strtotime($stime) : null;
+        $end_unixtime = $if_end_date ? (strtotime($etime)+86399) : null;
+        if ($start_unixtime) {
+            $condition[] = array('storedepositlog_add_time','>=', $start_unixtime);
+        }
+        if ($end_unixtime) {
+            $condition[] = array('storedepositlog_add_time','<=', $end_unixtime);
+        }
+        $mname = input('get.mname');
+        if (!empty($mname)) {
+            $condition[]=array('store_name','like','%'.$mname.'%');
+        }
+        $storedepositlog_model = model('storedepositlog');
+        $list_log = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
+        View::assign('show_page', $storedepositlog_model->page_info->render());
+        View::assign('list_log', $list_log);
+        
+        View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('index');
+        return View::fetch();
+    }
+
+    /*
+     * 提现列表
+     */
+    public function withdraw_list() {
+        $condition = array(array('storedepositlog_type','in',[Storedepositlog::TYPE_WITHDRAW,Storedepositlog::TYPE_RECHARGE]),);
+        $paystate_search = input('param.paystate_search');
+        if (isset($paystate_search) && $paystate_search !== '') {
+            $condition[] = array('storedepositlog_state','=',intval($paystate_search));
+        }
+
+        $storedepositlog_model = model('storedepositlog');
+        $withdraw_list = $storedepositlog_model->getStoredepositlogList($condition, 10, '*', 'storedepositlog_id desc');
+        View::assign('show_page', $storedepositlog_model->page_info->render());
+        View::assign('withdraw_list', $withdraw_list);
+        
+        View::assign('filtered', input('get.') ? 1 : 0); //是否有查询条件
+        
+        $this->setAdminCurItem('withdraw_list');
+        return View::fetch();
+    }
+
+
+
+    /**
+     * 查看提现信息
+     */
+    public function withdraw_view() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $storedepositlog_model = model('storedepositlog');
+        $condition = array();
+        $condition[] = array('storedepositlog_id','=',$id);
+        $info = $storedepositlog_model->getStoredepositlogInfo($condition);
+        if (!is_array($info) || count($info) < 0) {
+            $this->error(lang('admin_storedeposit_record_error'));
+        }
+        if(!request()->isPost()){
+            View::assign('info', $info);
+            return View::fetch();
+        }else{
+            if(!input('param.verify_reason')){
+                $this->error(lang('ds_none_input').lang('admin_storedeposit_remark'));
+            }
+            $data=array(
+                'store_id'=>$info['store_id'],
+                'store_name'=>$info['store_name'],
+                'storedepositlog_type'=>Storedepositlog::TYPE_VERIFY,
+                'storedepositlog_state'=>Storedepositlog::STATE_VALID,
+                'storedepositlog_add_time'=>TIMESTAMP,
+            );
+            if(input('param.verify_state')==1){//通过
+                    $data['store_freeze_deposit']=-$info['store_freeze_deposit'];
+                    $storedepositlog_state=Storedepositlog::STATE_AGREE;
+            }else{
+                $data['store_avaliable_deposit']=$info['store_freeze_deposit'];
+                    $data['store_freeze_deposit']=-$info['store_freeze_deposit'];
+                    $storedepositlog_state=Storedepositlog::STATE_REJECT;
+            }
+            $admininfo = $this->getAdminInfo();
+            $data['storedepositlog_desc']=lang('order_admin_operator')."【" . $admininfo['admin_name'] . "】".((input('param.verify_state')==1)?lang('ds_pass'):lang('ds_refuse')).lang('ds_seller_name')."【" . $info['store_name'] . "】".lang('admin_storedeposit_log_stage_cash').':'.input('param.verify_reason');
+            try {
+                Db::startTrans();
+                $storedepositlog_model->changeStoredeposit($data);
+                //修提现状态
+                if(!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id'=>$id,'storedepositlog_state'=>Storedepositlog::STATE_WAIT),array('storedepositlog_state'=>$storedepositlog_state))){
+                    throw new \think\Exception(lang('admin_storedeposit_cash_edit_fail'), 10006);
+                }
+                //如果是通过取出保证金,则将保证金转换为店铺可用资金
+                if(input('param.verify_state')==1){
+                    $storemoneylog_model = model('storemoneylog');
+                    $data2=array(
+                        'store_id'=>$info['store_id'],
+                        'store_name'=>$info['store_name'],
+                        'storemoneylog_type'=>Storemoneylog::TYPE_DEPOSIT_OUT,
+                        'storemoneylog_state'=>Storemoneylog::STATE_VALID,
+                        'storemoneylog_add_time'=>TIMESTAMP,
+                        'store_avaliable_money'=>$info['store_freeze_deposit'],
+                        'storemoneylog_desc'=>$data['storedepositlog_desc'],
+                    );
+                    $storemoneylog_model->changeStoremoney($data2);
+                }
+                Db::commit();
+                $this->log($data['storedepositlog_desc'], 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->log($data['storedepositlog_desc'], 0);
+                $this->error($e->getMessage());
+            }
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }
+    }
+    
+    
+    public function recharge_view() {
+        $id = intval(input('param.id'));
+        if ($id <= 0) {
+            $this->error(lang('param_error'));
+        }
+        $storedepositlog_model = model('storedepositlog');
+        $condition = array();
+        $condition[] = array('storedepositlog_id','=',$id);
+        $info = $storedepositlog_model->getStoredepositlogInfo($condition);
+        if (!is_array($info) || count($info) < 0) {
+            $this->error(lang('admin_storedeposit_record_error'));
+        }
+        if(!request()->isPost()){
+            View::assign('info', $info);
+            return View::fetch();
+        }else{
+            if(!input('param.verify_reason')){
+                $this->error(lang('ds_none_input').lang('admin_storedeposit_remark'));
+            }
+            $data=array(
+                'store_id'=>$info['store_id'],
+                'store_name'=>$info['store_name'],
+                'storedepositlog_type'=>Storedepositlog::TYPE_VIEW,
+                'storedepositlog_state'=>Storedepositlog::STATE_VALID,
+                'storedepositlog_add_time'=>TIMESTAMP,
+            );
+            if(input('param.verify_state')==1){//通过
+                $data['store_avaliable_deposit']=$info['store_payable_deposit'];
+                    $data['store_payable_deposit']=-$info['store_payable_deposit'];
+                    $storedepositlog_state=Storedepositlog::STATE_PAYED;
+            }else{
+                    $data['store_payable_deposit']=-$info['store_payable_deposit'];
+                    $storedepositlog_state=Storedepositlog::STATE_CANCEL;
+            }
+            $admininfo = $this->getAdminInfo();
+            $data['storedepositlog_desc']=lang('order_admin_operator')."【" . $admininfo['admin_name'] . "】".lang('ds_update').lang('ds_seller_name')."【" . $info['store_name'] . "】".lang('admin_storedeposit_pay_state').((input('param.verify_state')==1)?lang('admin_storedeposit_payed'):lang('admin_storedeposit_cancel')).':'.input('param.verify_reason');
+            try {
+                Db::startTrans();
+                $storedepositlog_model->changeStoredeposit($data);
+                //修提现状态
+                if(!$storedepositlog_model->editStoredepositlog(array('storedepositlog_id'=>$id,'storedepositlog_state'=>Storedepositlog::STATE_PAYING),array('storedepositlog_state'=>$storedepositlog_state))){
+                    throw new \think\Exception(lang('admin_storedeposit_pay_state').lang('ds_update').lang('ds_fail'), 10006);
+                }
+
+                Db::commit();
+                $this->log($data['storedepositlog_desc'], 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->log($data['storedepositlog_desc'], 0);
+                $this->error($e->getMessage());
+            }
+            dsLayerOpenSuccess(lang('ds_common_op_succ'));
+        }
+    }
+
+    /*
+     * 调节资金
+     */
+
+    public function adjust() {
+        if (!(request()->isPost())) {
+            $store_id = intval(input('get.store_id'));
+            if($store_id>0){
+                $condition = array();
+                $condition[] = array('store_id','=',$store_id);
+                $store = model('store')->getStoreInfo($condition);
+                if(!empty($store)){
+                    View::assign('store_info',$store);
+                }
+            }
+            return View::fetch();
+        } else {
+            $data = array(
+                'store_id' => input('post.store_id'),
+                'amount' => input('post.amount'),
+                'operatetype' => input('post.operatetype'),
+                'lg_desc' => input('post.lg_desc'),
+            );
+            $storedeposit_validate = ds_validate('storedeposit');
+            if (!$storedeposit_validate->scene('adjust')->check($data)){
+                $this->error($storedeposit_validate->getError());
+            }
+
+
+            $money = abs(floatval(input('post.amount')));
+            if ($money <= 0) {
+                $this->error(lang('admin_storedeposit_artificial_pricemin_error'));
+            }
+            //查询店主信息
+            $store_mod = model('store');
+            $store_id = intval(input('post.store_id'));
+            $operatetype = input('post.operatetype');
+            $store_info = $store_mod->getStoreInfo(array('store_id' => $store_id));
+
+            if (!is_array($store_info) || count($store_info) <= 0) {
+                $this->error(lang('admin_storedeposit_userrecord_error'), 'Storedeposit/adjust');
+            }
+            $store_avaliable_deposit = floatval($store_info['store_avaliable_deposit']);
+            $store_freeze_deposit = floatval($store_info['store_freeze_deposit']);
+            if ($operatetype == 2 && $money > $store_avaliable_deposit) {
+                $this->error(lang('admin_storedeposit_artificial_shortprice_error') . $store_avaliable_deposit, 'Storedeposit/adjust');
+            }
+
+            $storedepositlog_model = model('storedepositlog');
+            #生成对应订单号
+            $admininfo = $this->getAdminInfo();
+            $data=array(
+                'store_id'=>$store_info['store_id'],
+                'store_name'=>$store_info['store_name'],
+                'storedepositlog_type'=>Storedepositlog::TYPE_ADMIN,
+                'storedepositlog_state'=>Storedepositlog::STATE_VALID,
+                'storedepositlog_add_time'=>TIMESTAMP,
+            );
+            switch ($operatetype) {
+                case 1:
+                    $data['store_avaliable_deposit']=$money;
+                    $log_msg = lang('order_admin_operator')."【" . $admininfo['admin_name'] . "】".lang('ds_handle').lang('ds_seller_name')."【" . $store_info['store_name'] . "】".lang('ds_store_deposit')."【".lang('admin_storedeposit_artificial_operatetype_add')."】,".lang('admin_storedeposit_price') . $money;
+                    break;
+                case 2:
+                    $data['store_avaliable_deposit']=-$money;
+                    $log_msg = lang('order_admin_operator')."【" . $admininfo['admin_name'] . "】".lang('ds_handle').lang('ds_seller_name')."【" . $store_info['store_name'] . "】".lang('ds_store_deposit')."【".lang('admin_storedeposit_artificial_operatetype_reduce')."】,".lang('admin_storedeposit_price') . $money;
+                    break;
+                default:
+                    $this->error(lang('ds_common_op_fail'), 'Storedeposit/index');
+                    break;
+            }
+            $data['storedepositlog_desc']=$log_msg;
+            try {
+                Db::startTrans();
+                $storedepositlog_model->changeStoredeposit($data);
+                Db::commit();
+                $this->log($log_msg, 1);
+                dsLayerOpenSuccess(lang('ds_common_op_succ'));
+            } catch (\Exception $e) {
+                Db::rollback();
+                $this->log($log_msg, 0);
+                $this->error($e->getMessage(), 'Storedeposit/index');
+            }
+        }
+    }
+
+    //取得店主信息
+    public function checkseller() {
+        $name = input('post.name');
+        if (!$name) {
+            exit(json_encode(array('id' => 0)));
+            die;
+        }
+        $obj_store = model('store');
+        $store_info = $obj_store->getStoreInfo(array('seller_name' => $name));
+        if (is_array($store_info) && count($store_info) > 0) {
+            exit(json_encode(array('id' => $store_info['store_id'], 'name' => $store_info['seller_name'], 'store_avaliable_deposit' => $store_info['store_avaliable_deposit'], 'store_freeze_deposit' => $store_info['store_freeze_deposit'])));
+        } else {
+            exit(json_encode(array('id' => 0)));
+        }
+    }
+    
+    /**
+     * 获取卖家栏目列表,针对控制器下的栏目
+     */
+    protected function getAdminItemList() {
+        $menu_array = array(
+            array(
+                'name' => 'index',
+                'text' => lang('admin_storedeposit_loglist'),
+                'url' => (string)url('Storedeposit/index')
+            ),
+            array(
+                'name' => 'withdraw_list',
+                'text' => lang('admin_storedeposit_cashmanage'),
+                'url' => (string)url('Storedeposit/withdraw_list')
+            ),
+            array(
+                'name' => 'adjust',
+                'text' => lang('admin_storedeposit_adjust'),
+                'url' => "javascript:dsLayerOpen('".(string)url('Storedeposit/adjust')."','".lang('admin_storedeposit_adjust')."')"
+            ),
+        );
+        return $menu_array;
+    }
+}
+
+?>

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff