Ejemplo n.º 1
0
 public function before($obj = null)
 {
     // 推荐商户设置   add by t-btei 2015/05/04
     $companyId = Req::args('companyId');
     if (isset($companyId)) {
         // 保存推荐ID
         setcookie('company_affiliate_uid', $companyId);
     }
     //测试平板或者手机端主题
     $clientType = Chips::clientType();
     if ($clientType == 'tablet' || $clientType == 'mobile') {
         $config_path = APP_CODE_ROOT . 'config/config.php';
         $config = (require $config_path);
         if (isset($config['themes_mobile'])) {
             $themes_mobile = Tiny::app()->setTheme($config['themes_mobile']);
         } else {
             Tiny::app()->setTheme("default");
         }
     }
     $config = Config::getInstance();
     $site = $config->get('globals');
     $other = $config->get('other');
     $currency_symbol = isset($other['other_currency_symbol']) ? $other['other_currency_symbol'] : '¥';
     $site_logo = isset($site['site_logo']) && $site['site_logo'] != '' ? $site['site_logo'] : 'static/images/logo.png';
     $site_qr = isset($site['site_qr']) && $site['site_qr'] != '' ? $site['site_qr'] : 'static/images/qr-app.png';
     $site_name = isset($site['site_name']) ? $site['site_name'] : 'TinyShop商城';
     $site_icp = isset($site['site_icp']) ? $site['site_icp'] : '鲁ICP备00000100号';
     $obj->assign('currency_symbol', $currency_symbol);
     $obj->assign('site_logo', $site_logo);
     $obj->assign('site_qr', $site_qr);
     $obj->assign('site_name', $site_name);
     $obj->assign('site_icp', $site_icp);
 }
Ejemplo n.º 2
0
 /**
  * 取得视图路径
  * 
  * @access public
  * @return String
  */
 public function getViewPath()
 {
     if ($this->viewPath === null) {
         if (!is_null(Req::args($this->viewParam))) {
             $this->resolveView(Req::args($this->viewParam));
         } else {
             $this->viewPath = strtolower($this->getController()->id) . DIRECTORY_SEPARATOR . strtr($this->id, '.', '/');
         }
     }
     return $this->viewPath;
 }
Ejemplo n.º 3
0
 /**
  * action 运行入口
  * 
  * @access public
  * @return mixed
  */
 public function run()
 {
     $controller = $this->getController();
     $methodName = preg_split("/_(?=(save|del|edit)\$)/i", $this->getId());
     if (count($methodName) == 2) {
         $op = $methodName[1];
         $modelName = $methodName[0];
     } else {
         $op = $methodName[0];
         $modelName = $controller->getId();
     }
     $operator = array('save' => 'save', 'del' => 'delete', 'edit' => 'find');
     //如果配制文件存在curd函数自动进行处理
     if ($controller->getAutoActionRight() && array_key_exists($op, $operator)) {
         if ($op == 'save') {
             $pre_validator = $modelName . '_validator';
             if (method_exists($controller, $pre_validator)) {
                 $validator = $controller->{$pre_validator}();
                 if (is_array($validator)) {
                     $data = Req::args() + array('validator' => $validator);
                     $controller->redirect($modelName . '_edit', false, $data);
                     exit;
                 }
             }
         }
         $model = new Model($modelName);
         $data = $model->data(Req::args())->{$operator}[$op]();
         switch ($op) {
             case 'save':
                 if ($data !== false) {
                     $controller->redirect($modelName . '_list');
                 } else {
                     $controller->redirect($modelName . '_edit', null, false, array('form' => $model->find()));
                 }
                 break;
             case 'del':
                 $controller->redirect($modelName . '_list');
                 break;
             case 'edit':
                 $data = isset($data) ? $data : array();
                 $controller->redirect($modelName . '_edit', false, $data);
                 break;
         }
     } else {
         $action = new ViewAction($controller, $this->getId());
         $action->run();
         //exit;
     }
 }
Ejemplo n.º 4
0
 function brand_list()
 {
     $condition = Req::args("condition");
     $condition_str = Common::str2where($condition);
     if ($condition_str) {
         $where = $condition_str;
     } else {
         $where = "1=1";
     }
     $this->assign("condition", $condition);
     $this->assign("where", $where);
     $this->redirect();
 }
Ejemplo n.º 5
0
 /**
  * 取得请求视图文件
  * 
  * @access public
  * @return mixed
  */
 public function getRequestedView()
 {
     if ($this->viewPath === null) {
         if (!is_null(Req::args($this->viewParam))) {
             $this->viewPath = Req::args($this->viewParam);
         } else {
             $this->viewPath = $this->defaultView;
         }
     }
     return $this->viewPath;
 }
Ejemplo n.º 6
0
 public function checkProductTax()
 {
     $ship_id = Req::args("ship_id");
     $real_price = Filter::float(Req::args("real_price"));
     $tax_type_percent = Filter::float(Req::args("tax_type_percent"));
     $num = Filter::int(Req::args("num"));
     $tax_amount = $this->checkProductTax_p($ship_id, $real_price, $tax_type_percent, $num);
     $data = array('taxAmount' => $tax_amount);
     echo JSON::encode($data);
 }
Ejemplo n.º 7
0
 public function change_wel_open()
 {
     $id = Req::args("id");
     $is_open = Req::args("is_open");
     $model = new Model("wel");
     $model->data(array('is_open' => $is_open))->where("id={$id}")->update();
     echo JSON::encode(array('status' => 'success'));
 }
Ejemplo n.º 8
0
 public function examine_list()
 {
     $condition = Req::args("condition");
     $condition = str_replace(" ", "--", $condition);
     $condition_str = Common::str2where($condition);
     if ($condition_str) {
         $this->assign("where", $condition_str);
     } else {
         $approve = Req::args("approve");
         if ($approve) {
             $this->assign("where", "approve_result='" . $approve . "'");
         } else {
             $this->assign("where", "1=1");
         }
     }
     $this->assign("condition", $condition);
     $this->redirect();
 }
Ejemplo n.º 9
0
 /**
  * 创建表
  * 
  * @access public
  * @return mixed
  */
 public function createTable()
 {
     $table = Req::args('table');
     if ($table !== null) {
         $model = new Model($table);
     }
 }
Ejemplo n.º 10
0
 public function order_getlist()
 {
     $order_no = Filter::int(Req::args('order_no'));
     $order_inst = Order::getOrderWithDetailByNo($order_no);
     //        echo  JSON::encode($retData,JSON_UNESCAPED_SLASHES);
     echo json_encode($order_inst, JSON_UNESCAPED_SLASHES);
 }
Ejemplo n.º 11
0
 /**
  * 保存数据,自动识别更新还是添加
  * 
  * @access public
  * @return mixed
  */
 public function save()
 {
     if (!is_array($this->sql['data']) || count($this->sql['data']) < 1) {
         $this->sql['data'] = Req::args();
     }
     if (isset($this->sql['data'][$this->primary_key]) && $this->sql['data'][$this->primary_key]) {
         return $this->update();
     } else {
         if (isset($this->sql['data'][$this->primary_key])) {
             unset($this->sql['data'][$this->primary_key]);
         }
         return $this->insert();
     }
 }
Ejemplo n.º 12
0
 public function voucher_create()
 {
     $id = Req::args("id");
     $start_time = Req::args("start_time");
     $start_time = $start_time == null ? date("Y-m-d") : $start_time;
     $end_time = Req::args("end_time");
     $end_time = $end_time == null ? date("Y-m-d 23:59:59", strtotime("+30 days")) : date("Y-m-d 23:59:59", strtotime($end_time));
     $model = new Model('voucher_template');
     $voucher_template = $model->where("id = {$id}")->find();
     if ($voucher_template) {
         $voucher_model = new Model('voucher');
         $num = Req::args('num');
         $i = 0;
         while ($i < $num) {
             do {
                 $account = strtoupper(CHash::random(10, 'char'));
                 $password = strtoupper(CHash::random(10, 'char'));
                 $voucher_template['account'] = $account;
                 $voucher_template['password'] = $password;
                 $voucher_template['start_time'] = $start_time;
                 $voucher_template['end_time'] = $end_time;
                 $obj = $voucher_model->where("account = '{$account}'")->find();
             } while ($obj);
             unset($voucher_template['id'], $voucher_template['point']);
             $voucher_model->data($voucher_template)->insert();
             $i++;
         }
     }
     echo JSON::encode(array('status' => 'success', 'msg' => '已成功生成[' . $voucher_template['name'] . ']代金券(' . $num . ')张'));
 }
Ejemplo n.º 13
0
 function async_callback()
 {
     //从URL中获取支付方式
     $payment_id = Filter::int(Req::get('payment_id'));
     $payment = new Payment($payment_id);
     $paymentPlugin = $payment->getPaymentPlugin();
     if (!is_object($paymentPlugin)) {
         echo "fail";
     }
     //初始化参数
     $money = '';
     $message = '支付失败';
     $orderNo = '';
     //执行接口回调函数
     $callbackData = Req::args();
     //array_merge($_POST,$_GET);
     unset($callbackData['con']);
     unset($callbackData['act']);
     unset($callbackData['payment_id']);
     $return = $paymentPlugin->callback($callbackData, $payment_id, $money, $message, $orderNo);
     //支付成功
     if ($return == 1) {
         //充值方式
         if (stripos($orderNo, 'recharge_') !== false) {
             $tradenoArray = explode('_', $orderNo);
             $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0;
             if (Order::recharge($recharge_no, $payment_id, $callbackData)) {
                 $paymentPlugin->asyncStop();
                 exit;
             }
         } else {
             $order_id = Order::updateStatus($orderNo, $payment_id, $callbackData);
             if ($order_id) {
                 $paymentPlugin->asyncStop();
                 exit;
             }
         }
     }
 }
Ejemplo n.º 14
0
 private function calendar()
 {
     $cal = array();
     $s_time = Req::args("s_time");
     if (!$s_time) {
         $s_time = date("Y-m-d -- Y-m-d");
     }
     $date = explode(' -- ', $s_time);
     $stime = date('Y-m-d 00:00:00', strtotime($date[0]));
     $etime = date('Y-m-d 00:00:00', strtotime($date[1] . '+1day'));
     $cle = strtotime($etime) - strtotime($stime);
     $num = ceil($cle / 86400);
     $cal['start'] = $stime;
     $cal['end'] = $etime;
     $cal['days'] = $num;
     $cal['str'] = $s_time;
     return $cal;
 }
Ejemplo n.º 15
0
 /**
  * 安规则的标尺进行验证
  * 
  * @access public
  * @param array $rules 如 array('title:required|int:标题不能为空!);
  * @param mixed $data
  * @return bool
  */
 public static function check($rules, $data = null)
 {
     if ($data == null) {
         $data = Req::args();
     }
     foreach ($rules as $rule) {
         list($name, $reg, $msg) = explode(':', $rule);
         $info = array('name' => $name, 'msg' => $msg);
         $field = isset($data[$name]) ? $data[$name] : null;
         if (strpos($reg, '|') !== false) {
             $regs = explode('|', $reg);
             foreach ($regs as $reg) {
                 if (method_exists('Validator', $reg)) {
                     if (!self::$reg($field)) {
                         return $info;
                     }
                 } else {
                     if (!self::match($reg, $field)) {
                         return $info;
                     }
                 }
             }
         } else {
             if (method_exists('Validator', $reg)) {
                 if (!self::$reg($field)) {
                     return $info;
                 }
             } else {
                 if (!self::match($reg, $field)) {
                     return $info;
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 16
0
 public function ext_params_edit()
 {
     $this->layout = "blank";
     $id = intval(Req::args('id'));
     $model = new Model('area');
     $obj = $model->where("id={$id}")->find();
     $this->redirect("ext_params_edit", false, $obj);
 }
Ejemplo n.º 17
0
 public function company_del()
 {
     $id = Req::args("id");
     if (is_array($id)) {
         $cond = ' in (' . implode(",", $id) . ')';
     } else {
         $cond = " = {$id}";
     }
     $model = new Model();
     $companys = $model->table("company")->where("company_id {$cond}")->findAll();
     $model->table("company")->where("company_id {$cond}")->delete();
     if ($companys) {
         $company_name = "";
         foreach ($companys as $value) {
             $company_name .= $value['company_name'] . "、";
         }
         $company_name = trim($company_name, '、');
         Log::op($this->manager['id'], "删除会员", "管理员[" . $this->manager['name'] . "]:删除了商户" . $company_name);
     }
     $this->redirect("company_list");
 }
Ejemplo n.º 18
0
 public function safe()
 {
     $safe = array('safe_reg_limit' => Req::args('safe_reg_limit'), 'safe_reg_num' => Req::args('safe_reg_num'), 'safe_comment_limit' => Req::args('safe_comment_limit'), 'safe_comment_num' => Req::args('safe_comment_num'), 'safe_album_limit' => Req::args('safe_album_limit'), 'safe_album_num' => Req::args('safe_album_num'), 'safe_click_count' => Req::args('safe_click_count'));
     $this->config->set('safe', $safe);
     return true;
 }
Ejemplo n.º 19
0
 /**
  * 生成短信验证码接口
  * AJAX
  * apikey 为云片分配的apikey
  * text 为短信内容
  * mobile 为接受短信的手机号
  */
 public function send_auth_code()
 {
     $info = array('status' => false, 'msg' => '验证码发送失败!');
     // $apikey = "06ec231c5d876ffe119b38013662f661";   // todo  短信接口部署时,需修改这里的APIKEY
     $phoneNumber = Filter::int(Req::args("mobile"));
     $config_inst = Config::getInstance();
     $config = $config_inst->get("sms");
     $apikey = $config['api_key'];
     $authChars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     //验证码生成
     $authCode = '';
     for ($i = 0; $i < 4; $i++) {
         $authCode .= substr($authChars, mt_rand(0, strlen($authChars) - 1), 1);
     }
     $authCode = strtolower($authCode);
     // 变成小写
     // $text = "【全品电台】您的验证码是".$authCode;
     $text = "【全品电台】感谢您的注册,您的验证码是 {$authCode} 。有效期为3分钟,请尽快验证";
     //$text = "【云片网】您的验证码是".$authCode;
     Tiny::log(__FILE__ . '--' . __LINE__ . '--' . $phoneNumber . "--" . $authCode . "--" . $text);
     //验证码与手机号码绑定
     $model = $this->model->table("auth_code");
     $obj = $model->where('phone_number=' . $phoneNumber)->find();
     $time = date('Y-m-d H:i:s', strtotime("+3 minutes"));
     if ($obj == null) {
         $data['phone_number'] = $phoneNumber;
         $data['auth_code'] = $authCode;
         $data['start_time'] = date('Y-m-d H:i:s');
         $data['end_time'] = $time;
         $auth_code_id = $this->model->table("auth_code")->data($data)->insert();
         if ($auth_code_id) {
             //发送验证码,发送成功
             //Tiny::log("auth_code 表 ID--".$auth_code_id);
             // todo SKM 要发短信验证码时,把下面注释去掉
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             // todo SKM SMS服务正式提供后,把下面一行代码注释掉
             //$ret = array('code' => 0, 'msg' => 'OK');
             if (isset($ret['code']) && $ret['code'] == 0) {
                 $info['status'] = true;
                 //$info['msg'] = "发送验证码成功!短信API接口返回:".$ret['msg'];
                 $info['msg'] = "发送验证码成功!";
             } else {
                 $info['status'] = false;
                 //$info['msg'] = "发送验证码失败!短信API接口返回:".$ret['msg'];
                 Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "短信接口发送失败:" . var_export($ret, true));
                 $info['msg'] = "发送验证码失败!";
             }
             echo JSON::encode($info);
         } else {
             // 插入失败
             Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "插入失败:auth_code--" . $auth_code_id);
             echo JSON::encode($info);
         }
     } else {
         // 1分钟内不能发送2次验证码
         $expired_time = strtotime("+3 minutes", intval($obj['start_time']));
         if ($expired_time > strtotime(date('y-m-d h:i:s'))) {
             $info['status'] = false;
             $info['msg'] = "两次验证码发送间隔不能少于60秒!";
             echo JSON::encode($info);
         } else {
             // 已经存在验证码,更新验证码, 从新发送到手机上
             $obj['auth_code'] = $authCode;
             $obj['start_time'] = date('Y-m-d H:i:s');
             $obj['end_time'] = $time;
             $model->data($obj)->update();
             // 重新发送
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             //$ret = array('code' => 0, 'msg' => 'OK');
             $info['status'] = true;
             $info['msg'] = "发送验证码成功!";
             echo JSON::encode($info);
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * 取得action
  * 
  * @access public
  * @return mixed
  */
 public function getAction()
 {
     if ($this->action === null) {
         $this->setAction(Req::args('act'));
     }
     return $this->action;
 }
Ejemplo n.º 21
0
 public function address_save($redirect = null)
 {
     $rules = array('zip:zip:邮政编码格式不正确!', 'addr:required:内容不能为空!', 'accept_name:required:收货人姓名不能为空!,mobile:mobi:手机格式不正确!,phone:phone:电话格式不正确', 'province:[1-9]\\d*:选择地区必需完成', 'city:[1-9]\\d*:选择地区必需完成', 'county:[1-9]\\d*:选择地区必需完成');
     $info = Validator::check($rules);
     if (!is_array($info) && $info == true) {
         Filter::form(array('sql' => 'accept_name|mobile|phone', 'txt' => 'addr', 'int' => 'province|city|county|zip|is_default|id'));
         $is_default = Filter::int(Req::args("is_default"));
         if ($is_default == 1) {
             $this->model->table("address")->where("user_id=" . $this->user['id'])->data(array('is_default' => 0))->update();
         } else {
             Req::args("is_default", "0");
         }
         Req::args("user_id", $this->user['id']);
         $id = Filter::int(Req::args('id'));
         if ($id) {
             $this->model->table("address")->where("id={$id} and user_id=" . $this->user['id'])->update();
         } else {
             $obj = $this->model->table("address")->where('user_id=' . $this->user['id'])->fields("count(*) as total")->find();
             if ($obj && $obj['total'] >= 20) {
                 $this->assign("msg", array("error", '地址最大允许添加20个'));
                 $this->redirect("address_other", false, Req::args());
                 exit;
             } else {
                 $address_id = $this->model->table("address")->insert();
                 $order_status = Session::get("order_status");
                 $order_status['address_id'] = $address_id;
                 Session::set("order_status", $order_status);
             }
         }
         $this->assign("msg", array("success", "地址编辑成功!"));
         Req::args("id", null);
         //$this->redirect("address_other",false);
         if ($redirect == null) {
             echo "<script>parent.location.reload();</script>";
         } else {
             $this->redirect($redirect);
         }
         exit;
     } else {
         $this->assign("msg", array("error", $info['msg']));
         $this->redirect("address_other", false, Req::args());
     }
 }
Ejemplo n.º 22
0
 public function address_del()
 {
     $id = Filter::int(Req::args("id"));
     $this->model->table("address")->where("id={$id} and user_id=" . $this->user['id'])->delete();
     $this->redirect("address");
 }
Ejemplo n.º 23
0
 /**
  * 验证令牌并销毁
  * 
  * @access public
  * @param string $key
  * @return mixed
  */
 public function checkToken($key = '')
 {
     $key = "tiny_token_" . $key;
     $token = Req::args($key);
     $rel_token = Session::get($key);
     Session::clear($key);
     return $token != null && $token == $rel_token;
 }
Ejemplo n.º 24
0
 /**
  * 过滤表单,然后重新写回表单
  * @param  array  $rule 表单各字段验证的标尺规则
  */
 public static function form($rule = array())
 {
     if (empty($rule)) {
         $args = Req::args();
         foreach ($args as $key => $value) {
             Req::args($key, self::sql($value));
         }
     } else {
         foreach ($rule as $key => $re) {
             $key = strtolower($key);
             if (strpos($re, '|')) {
                 $res = explode('|', $re);
                 if (method_exists('Filter', $key)) {
                     foreach ($res as $re) {
                         Req::args($re, self::inputFilter(Req::args($re), $key));
                     }
                 }
             }
             if (method_exists('Filter', $key)) {
                 Req::args($re, self::inputFilter(Req::args($re), $key));
             }
         }
     }
 }