Пример #1
0
 public function register()
 {
     //系统维护检测
     service('user')->checkSystemClose();
     if (IS_POST) {
         Validate::make([['code', 'captcha', '验证码输入错误', 1], ['password', 'confirm:password2', '两次密码输入不一致', 3]]);
         //默认用户组
         $User = new User();
         $User['username'] = Request::post('username');
         //用户组过期时间
         $daylimit = Db::table('user_group')->where('id', v('config.register.groupid'))->pluck('daylimit');
         $User['endtime'] = time() + $daylimit * 3600 * 24;
         //获取密码与加密密钥
         $info = $User->getPasswordAndSecurity();
         $User['password'] = $info['password'];
         $User['security'] = $info['security'];
         $User['email'] = Request::post('email');
         $User['qq'] = Request::post('qq');
         $User['mobile'] = Request::post('mobile');
         $User['groupid'] = v('config.register.groupid');
         $User['status'] = v('config.register.audit');
         if (!$User->save()) {
             message($User->getError(), 'back', 'error');
         }
         message('注册成功,请登录系统', u('login', ['from' => $_GET['from']]));
     }
     return view();
 }
Пример #2
0
 /**
  * 删除用户
  * @return bool
  */
 public function remove()
 {
     foreach ($this->relationDeleteTable as $t) {
         Db::table($t)->where('uid', $this->uid)->delete();
     }
     return TRUE;
 }
Пример #3
0
 public function lists()
 {
     if (!isset($_SESSION['user']['user_id'])) {
         go('Home/User/login');
     }
     //分配模板文件配置
     $tplData['title'] = "购物车";
     $tplData['css'] = "cart|order";
     View::with('tplData', $tplData);
     //购物车列表信息
     $cart = $_SESSION['cart'];
     $price = 0;
     foreach ($cart as $k => $v) {
         $cart[$k]['goods'] = Db::table('goods')->where('goods_id', $v['goods_id'])->first();
         $attrs = explode('-', $v['stock_attr']);
         foreach ($attrs as $key => $value) {
             $attrs[$key] = Db::table('goods_attr')->where('goods_attr_id', $value)->first();
             $attrs[$key]['attr_name'] = Db::table('shop_attr')->where('attr_id', $attrs[$key]['attr_id'])->pluck('attr_name');
         }
         $cart[$k]['attr'] = $attrs;
         $price += $v['goods_price'] * $v['buy_num'];
         //总价
     }
     View::with('cart', $cart);
     View::with('price', $price);
     //收货地址列表
     $address = new \Home\Model\Address();
     $addressData = $address->getAll();
     View::with('addressData', $addressData);
     // p($addressData);
     View::make($this->tpl . 'order.html');
 }
Пример #4
0
 public function doSiteSitePost()
 {
     if (IS_POST) {
         $data = json_decode($_POST['data'], TRUE);
         $data['site_info'] = $_POST['data'];
         $insertId = $this->web->save($data);
         $web['id'] = $this->webid ?: $insertId;
         //添加回复规则
         $rule = [];
         $rule['rid'] = Db::table('reply_cover')->where('web_id', $web['id'])->pluck('rid');
         $rule['module'] = 'cover';
         $rule['name'] = '微站:' . $data['title'];
         $rule['keywords'] = [['content' => $data['keyword']]];
         $rid = service('WeChat')->rule($rule);
         //添加封面回复
         $replyCover = new ReplyCover();
         $replyCover->where('rid', $rid)->delete();
         $data['web_id'] = $web['id'];
         $data['rid'] = $rid;
         $data['module'] = 'article';
         $data['url'] = '?a=entry/home&m=article&t=web&siteid=' . SITEID . '&webid=' . $web['id'];
         $replyCover->save($data);
         message('保存站点数据成功', site_url('site'), 'success');
     }
     if ($this->webid) {
         //编辑数据时
         $web = $this->web->find($this->webid);
         $field = json_decode($web['site_info'], TRUE);
         $field['id'] = $this->webid;
     }
     View::with('field', isset($field) ? json_encode($field, JSON_UNESCAPED_UNICODE) : '');
     return View::make($this->template . '/manage/sitePost.php');
 }
Пример #5
0
 /**
  * 多对多关联
  * @param  [string] $class       [关联类]
  * @param  [string] $middleTabe [中间表]
  * @param  [string] $relationId  [主表字段]
  * @param  [string] $primaryKey  [关联表字段]
  * @return [object]              
  */
 protected function belongsToMany($class, $middleTable, $middlePrimaryKey, $middleRelationId)
 {
     $pKey = $this->primaryKey;
     $middle = Db::table($middleTable)->where($middlePrimaryKey, $this->{$pKey})->lists($middleRelationId);
     $instance = new $class();
     return $instance->whereIn($instance->primaryKey, array_values($middle))->get();
 }
Пример #6
0
 public function post()
 {
     if (IS_POST) {
         $data = json_decode(Request::post('keyword'), TRUE);
         $data['rank'] = $data['istop'] == 1 ? 255 : min(255, intval($data['rank']));
         $data['module'] = v('module.name');
         $data['keywords'] = $data['keyword'];
         $rid = service('WeChat')->rule($data);
         //调用模块的执行方法
         $module = new $this->moduleClass();
         //字段验证
         if ($msg = $module->fieldsValidate($rid)) {
             message($msg, 'back', 'error');
         }
         //使模块保存回复内容
         $module->fieldsSubmit($rid);
         message('规则保存成功', u('post', ['rid' => $rid, 'm' => v('module.name')]));
     }
     //获取关键词回复
     if ($rid = Request::get('rid')) {
         $data = Db::table('rule')->find($rid);
         if (empty($data)) {
             message('回复规则不存在', 'back', 'error');
         }
         $data['keyword'] = Db::table('rule_keyword')->orderBy('id', 'asc')->where('rid', $rid)->get();
         View::with('rule', $data);
     }
     $module = new $this->moduleClass();
     $moduleForm = $module->fieldsDisplay($rid);
     return view()->with('moduleForm', $moduleForm);
 }
Пример #7
0
 public function doWebLists()
 {
     $Model = new CreditsRecord();
     //会员信息
     $user = Db::table('member')->where('uid', Session::get('member.uid'))->first();
     if ($timerange = q('get.timerange')) {
         //有筛选时间的
         $timerange = explode('至', $timerange);
         $total = $Model->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->where('createtime', '>=', strtotime($timerange[0]))->where('createtime', '<=', strtotime($timerange[1]))->count();
         $page = Page::row(8)->make($total);
         $data = $Model->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->where('createtime', '>=', strtotime($timerange[0]))->where('createtime', '<=', strtotime($timerange[1]))->limit(Page::limit())->get();
     } else {
         $total = $Model->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->count();
         $page = Page::row(8)->make($total);
         $data = $Model->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->limit(Page::limit())->get();
     }
     //收入
     $income = $Model->where('num', '>', 0)->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->sum('num');
     //支出
     $expend = $Model->where('num', '<', 0)->where('uid', Session::get('member.uid'))->where('credittype', q('get.type'))->sum('num');
     View::with(['income' => $income, 'expend' => $expend]);
     View::with('page', $page);
     View::with('user', $user);
     View::with('data', $data);
     View::make($this->ucenter_template . '/credit_lists.html');
 }
Пример #8
0
 public function add()
 {
     foreach ($_POST['stock_attr'] as $k => $v) {
         if ($s = $this->db->where('stock_attr', $_POST['stock_attr'][$k])->first()) {
             //以前设置了库存信息,更新库存
             $data['stock_attr'] = $_POST['stock_attr'][$k];
             $data['stock_goods_sn'] = $_POST['stock_goods_sn'][$k];
             $data['stock_count'] = $_POST['stock_count'][$k];
             $data['goods_id'] = $_POST['goods_id'];
             $data['stock_id'] = $s['stock_id'];
             $this->db->save($data);
         } else {
             if ($_POST['stock_count'][$k]) {
                 //没有设置过库存信息,新增库存信息,排除库存为0的组合
                 $data['stock_attr'] = $_POST['stock_attr'][$k];
                 $data['stock_goods_sn'] = $_POST['stock_goods_sn'][$k];
                 if (!$data['stock_goods_sn']) {
                     $data['stock_goods_sn'] = 'gd' . time() . rand(100, 999);
                 }
                 $data['stock_count'] = $_POST['stock_count'][$k];
                 $data['goods_id'] = $_POST['goods_id'];
                 unset($data['stock_id']);
                 //卸载上溢出的stock_id值
                 Db::table('goods_stock')->insert($data);
             }
         }
     }
     $this->success('库存信息更新成功', 'Goods/index');
 }
Пример #9
0
 /**
  * 支付
  *
  * @param $param
  */
 public function weixin($param)
 {
     if (!v('module.name') || !Session::get('member.uid') || empty($param['goods_name']) || empty($param['fee']) || empty($param['body']) || empty($param['tid'])) {
         message('支付参数错误,请重新提交', 'back', 'error');
     }
     if ($pay = Db::table('pay')->where('tid', $param['tid'])->first()) {
         if ($pay['status'] == 1) {
             message('定单已经支付完成', $param['back_url'], 'success');
         }
     }
     $data['siteid'] = SITEID;
     $data['uid'] = Session::get('member.uid');
     $data['tid'] = $param['tid'];
     $data['fee'] = $param['fee'];
     $data['goods_name'] = $param['goods_name'];
     $data['attach'] = isset($param['attach']) ? $param['attach'] : '';
     //附加数据
     $data['module'] = v('module.name');
     $data['body'] = $param['body'];
     $data['attach'] = $param['attach'];
     $data['status'] = 0;
     $data['is_usecard'] = isset($param['is_usecard']) ? $param['is_usecard'] : 0;
     $data['card_type'] = isset($param['card_type']) ? $param['card_type'] : '';
     $data['card_id'] = isset($param['is_usecard']) ? $param['card_id'] : 0;
     $data['card_fee'] = isset($param['card_fee']) ? $param['card_fee'] : 0;
     if (empty($pay)) {
         Db::table('pay')->insertGetId($data);
     }
     Session::set('pay', ['tid' => $data['tid'], 'module' => v('module.name'), 'siteid=' => SITEID]);
     View::with('data', $data);
     View::make('server/build/template/pay.html');
 }
Пример #10
0
 public function doWebBalance()
 {
     if (IS_POST) {
         //检测是否有相同金额的充值记录,如果有就使用它,避免重复金额定单产生
         $pay = Db::table('balance')->where('fee', $_POST['fee'])->where('siteid', SITEID)->where('status', 0)->where('uid', Session::get('member.uid'))->pluck('tid');
         $data['tid'] = $pay ? $pay : Cart::getOrderId();
         $data['goods_name'] = '会员充值';
         $data['fee'] = $_POST['fee'];
         $data['body'] = '会员余额充值';
         $data['attach'] = '';
         //附加数据
         //在会员充值表中记录定单
         if (empty($pay)) {
             $balance['siteid'] = SITEID;
             $balance['uid'] = Session::get('member.uid');
             $balance['fee'] = $data['fee'];
             $balance['stauts'] = 0;
             $balance['createtime'] = time();
             $balance['tid'] = $data['tid'];
             Db::table('balance')->insert($balance);
         }
         Util::instance('pay')->weixin($data);
     }
     View::make($this->ucenter_template . '/balance.html');
 }
 /**
  * Init the index view with the current
  * average rate data stored in the db.
  *
  * @return Response
  */
 public function index()
 {
     // Select the rates of the year 2015.
     // NOTE: Just for the purpose of the exercise,
     // would be nicer to provide all the results available
     // grouped accordingly
     $rates = Db::table('monthly_rates')->select('currency_from', 'currency_to', 'month', 'avg_rate')->where('year', 2015)->orderBy('currency_from')->orderBy('currency_to')->get();
     // Initialize the messages array as charts.js expects it
     if (empty($rates)) {
         $messages = [[]];
     } else {
         $messages = [];
     }
     $monthRates = [];
     $totRates = count($rates);
     // Aggregate the messages as an array
     // currencyfrom_currencyto => [1 => avg_rate, 2 => ...]
     // where the inner array index corresponds to a month
     for ($i = 0; $i < $totRates; $i++) {
         $rate = $rates[$i];
         $monthRates[$rate->month] = $rate->avg_rate;
         if ($i == $totRates - 1) {
             $key = $rate->currency_from . '-' . $rate->currency_to;
             $messages[$key] = $monthRates;
         } elseif ($rate->currency_from != $rates[$i + 1]->currency_from || $rate->currency_to != $rates[$i + 1]->currency_to) {
             // Build the array key and store the data
             $key = $rate->currency_from . '-' . $rate->currency_to;
             $messages[$key] = $monthRates;
             $monthRates = [];
         }
     }
     return view('socket', compact('messages'));
 }
Пример #12
0
 /**
  * 多对多关联
  *
  * @param  [string] $class       [关联类]
  * @param  [string] $middleTabe [中间表]
  * @param  [string] $localKey  [主表字段]
  * @param  [string] $foreignKey  [关联表字段]
  *
  * @return [object]
  */
 protected function belongsToMany($class, $middleTable, $localKey = NULL, $foreignKey = NULL)
 {
     $instance = new $class();
     $localKey = $localKey ?: $this->table . '_' . $this->pk;
     $foreignKey = $foreignKey ?: $instance->getTableName() . '_' . $instance->getPrimaryKey();
     $middle = Db::table($middleTable)->where($localKey, $this[$this->pk])->lists($foreignKey);
     return $instance->whereIn($instance->getPrimaryKey(), array_values($middle))->get();
 }
Пример #13
0
 public function getAttrName($goods_id)
 {
     //获取商品类型
     $type_id = Db::table('goods')->where('goods_id', $goods_id)->pluck('type_id');
     //获取商品规格
     $attr_name = DB::table('shop_attr')->where('shop_type_id', $type_id)->where('attr_type', 2)->lists('attr_name');
     return $attr_name;
 }
Пример #14
0
 /**
  * 删除文章
  *
  * @param $aid 文章编号
  *
  * @return bool
  */
 public function del($aid)
 {
     $rid = Db::table('reply_cover')->where('module', 'article:aid:' . $aid)->pluck('rid');
     service('WeChat')->removeRule($rid);
     Db::table('web_article')->where('aid', $aid)->delete();
     Db::table('reply_cover')->where('module', 'article:aid:' . $aid)->delete();
     return TRUE;
 }
Пример #15
0
 public function getIdChannelById($id)
 {
     $id_channel = Db::table('rss_item_for_channel')->select('id_channel')->where('id', '=', $id)->get();
     if (empty($id_channel)) {
         throw new \Exception('Can not find channel for this item.');
     }
     return $id_channel[0]->id_channel;
 }
Пример #16
0
 public function doWebShow()
 {
     $id = q('get.id', 0, 'intval');
     $article = Db::table('reply_news')->where('id', $id)->first();
     $tpl = __TEMPLATE__ . '/article.html';
     View::with('hdcms', $article);
     return view($tpl);
 }
Пример #17
0
 /**
  * 定单处理
  * @param $tid 定单编号
  */
 public function handle($tid)
 {
     Db::table('balance')->where('tid', $tid)->update(array('status' => 1));
     //添加会员余额
     $balance = Db::table('balance')->where('siteid', SITEID)->where('tid', $tid)->first();
     $sql = "UPDATE " . tablename('member') . " SET credit2=credit2+{$balance['fee']} WHERE uid={$balance['uid']}";
     Db::execute($sql);
 }
Пример #18
0
 public function doWebEmploy()
 {
     $tid = q('get.tid', 0, 'intval');
     //会员卡卷记录
     $ticket = Db::table('ticket')->where('tid', $tid)->first();
     View::with('ticket', $ticket);
     View::make($this->ucenter_template . '/ticket_employ.html');
 }
Пример #19
0
 protected function validateRid($field, $val)
 {
     $rule = Db::table('rule')->where('rid', $val)->first();
     if (!empty($rule) && $rule['siteid'] != SITEID) {
         return FALSE;
     }
     return TRUE;
 }
Пример #20
0
 public function removeSiteUser()
 {
     if ((new User())->isManage()) {
         Db::table('site_user')->where('siteid', SITEID)->whereIn('uid', $_POST['uids'])->delete();
         message('站点管理员删除成功', '', 'success');
     } else {
         message('你没有操作站点的权限', '', 'error');
     }
 }
Пример #21
0
 public function findTagsByLocationId($locationId)
 {
     $tagsSelected = [];
     $tags = \Db::table('location_tag')->select('tag_id')->where('location_id', '=', $locationId)->get();
     foreach ($tags as $tag) {
         $tagsSelected[] = $tag->tag_id;
     }
     return $tagsSelected;
 }
Пример #22
0
 /**
  * List Items
  *
  * @param int $maxItems
  * @return array|static[]
  */
 public static function loadItems($maxItems = 10)
 {
     try {
         $items = \Db::table('adrenth_rssfetcher_items')->select(['adrenth_rssfetcher_items.*', 'adrenth_rssfetcher_sources.name AS source'])->join('adrenth_rssfetcher_sources', 'adrenth_rssfetcher_items.source_id', '=', 'adrenth_rssfetcher_sources.id')->where('adrenth_rssfetcher_sources.is_enabled', '=', 1)->orderBy('adrenth_rssfetcher_items.pub_date', 'desc')->limit($maxItems);
     } catch (\InvalidArgumentException $e) {
         return [];
     }
     return $items->get();
 }
Пример #23
0
 public function article()
 {
     $id = Q('id', 0, 'intval');
     $article = Db::table('article a')->where('a.id', '=', $id)->first();
     $category = Db::table('category')->where('id', '=', $article['cid'])->first();
     $cms = $article;
     $cms['category'] = $category;
     View::with('cms', $cms)->make($this->tpl . '/article.html');
 }
Пример #24
0
 protected function autoSn()
 {
     while (TRUE) {
         $sn = 'HD' . strtoupper(substr(md5(time()), 0, 15));
         if (!Db::table('ticket')->where('sn', $sn)->get()) {
             return $sn;
         }
     }
 }
Пример #25
0
 /**
  * 更新一个配置项
  * @param  [type] $name 配置名称
  * @param  [type] $data 更新数据
  * @return [type]        [description]
  */
 public function editOne($name, $data)
 {
     if (Db::table("config")->where('name', $name)->update($data)) {
         $this->createConfigFile();
         return true;
     } else {
         $this->error = '更新失败';
     }
 }
Пример #26
0
 public function doWebHome()
 {
     $uc = Db::table('web_page')->where('siteid', SITEID)->where('type', 3)->first();
     //获取菜单
     $menus = Db::table('web_nav')->where('siteid', SITEID)->where('entry', 'profile')->get();
     //会员信息
     View::with(['uc' => $uc, 'menus' => $menus]);
     return View::make($this->ucenter_template . '/home.html');
 }
Пример #27
0
 public function unique($field, $value, $params, $data)
 {
     $args = explode(',', $params);
     $db = Db::table($args[0])->where($field, $value);
     if (isset($data[$args[1]])) {
         $db->where($args[1], '<>', $data[$args[1]]);
     }
     return empty($value) || !$db->pluck($field) ? TRUE : FALSE;
 }
Пример #28
0
 public function handle($rid)
 {
     $res = Db::table('reply_cover')->where('rid', $rid)->where('siteid', SITEID)->first();
     if ($res) {
         $data[] = ['title' => $res['title'], 'discription' => $res['description'], 'picurl' => __ROOT__ . '/' . $res['thumb'], 'url' => preg_match('/^http/i', $res['url']) ? $res['url'] : __ROOT__ . '/' . $res['url']];
         $this->news($data);
         return TRUE;
     }
 }
Пример #29
0
 public function remove()
 {
     $userGroup = new UserGroup();
     foreach ((array) Request::post('id') as $id) {
         $userGroup->delete($id);
         //更改默认用户组
         Db::table('user')->where('groupid', $id)->update(['groupid' => v('system.register.groupid')]);
     }
     message('更新用户组成功', 'lists', 'success');
 }
Пример #30
0
 public function getKeywords()
 {
     $key = q('post.key');
     if ($key) {
         $content = Db::table('rule_keyword')->where("content LIKE '%{$key}%'")->where('siteid', SITEID)->where('status', 1)->get();
     } else {
         $content = Db::table('rule_keyword')->where('siteid', v('site.siteid'))->where('status', 1)->limit(10)->get();
     }
     ajax($content);
 }