예제 #1
0
파일: Department.php 프로젝트: ptphp/ptphp
 static function getDepartmentRows()
 {
     $table = self::_table("org_department");
     $table_position = self::_table("org_position");
     $sql = "select dep_id as `key`,dep_name,dep_pid as pid,dep_name as label,concat('d_',dep_id) as value from {$table}";
     $rows = self::_db()->select_rows($sql);
     if (empty($rows)) {
         $row = array("dep_name" => "部门", "dep_pid" => 0);
         self::_db()->insert($table, $row);
         $rows = self::_db()->select_rows($sql);
     }
     $departments_rows = array();
     $departments_pid_rows = array();
     $positions = self::_db()->rows("select p.* from {$table_position} as p left join {$table} as d on d.dep_id = p.dep_id");
     $_positions = array();
     foreach ($positions as $position) {
         $_positions[$position['dep_id']][] = $position;
     }
     foreach ($rows as &$row) {
         $departments_rows[$row['key']] = $row['dep_name'];
         $departments_pid_rows[$row['key']] = $row['pid'];
         if (!empty($_positions[$row['key']])) {
             $row['positions'] = $_positions[$row['key']];
         }
     }
     $res = array("rows" => Utils::list_to_tree($rows, "key", "pid", "children"), "departments_rows" => $departments_rows, "departments_pid_rows" => $departments_pid_rows, "positions" => $_positions);
     return $res;
 }
예제 #2
0
파일: Task.php 프로젝트: ptphp/ptphp
 function action_do_verify($mission_id, $task_key, $pics, $note)
 {
     $task_key = intval($task_key);
     if (!$task_key) {
         _throw("task_key 不能为空");
     }
     $user_id = Auth::get_user_id();
     if (!$user_id) {
         _throw("您还没有登陆", 9001);
     }
     $table = self::_table("user_mission");
     $row = self::_db()->row("select * from {$table} where user_id = ? and mission_id = ?", $user_id, $mission_id);
     if (!$row) {
         _throw("您还没有参与过此任务");
     }
     if ($row['task_key'] != $task_key) {
         _throw("请按数序提交任务审核");
     }
     $table_verify = self::_table("user_mission_verify");
     $_pics = array();
     if (1) {
         $pics = explode("|", $pics);
         foreach ($pics as $pic) {
             $_pics[] = \Controller\Mission\Tool::upload_content($pic);
         }
     }
     $_pics = implode("|", $_pics);
     self::_debug($_pics);
     $verify_id = self::_db()->insert($table_verify, array("user_id" => $user_id, "mission_id" => $mission_id, "task_key" => $task_key, "pics" => $_pics, "note" => $note, "add_time" => Utils::date_time_now()));
     self::_db()->update($table, array("verify_id" => $verify_id), array("id" => $row['id']));
     return array("msg" => "提交审核成功");
 }
예제 #3
0
파일: Hu.php 프로젝트: ptphp/ptphp
 function action_update()
 {
     $id = Utils::I("id");
     $row = self::getSaveRow();
     self::_db()->update("small", $row, array("id" => $id));
     return array("id" => $id);
 }
예제 #4
0
파일: revisit.php 프로젝트: ptphp/ptphp
 static function add($_row)
 {
     $row = self::getSaveRow($_row);
     $row['add_time'] = Utils::date_time_now();
     $row['op_uid'] = Model_Admin_Auth::get_user_id();
     return self::_db()->insert(self::TABLE_REVISIT, $row);
 }
예제 #5
0
파일: area.php 프로젝트: ptphp/ptphp
 static function remove($id)
 {
     $row['del_time'] = Utils::date_time_now();
     $row['is_del'] = 1;
     self::_db()->update(self::TABLE, $row, array("id" => $id));
     self::_redis()->del(self::KEY . $id);
 }
예제 #6
0
파일: porder.php 프로젝트: ptphp/ptphp
 static function add($_row)
 {
     $row = self::getPorderSaveRow($_row);
     $row['orderno'] = self::get_orderno(self::TABLE_PORDER);
     $row['add_time'] = Utils::date_time_now();
     $row['op_uid'] = Model_Admin_Auth::get_user_id();
     return self::_db()->insert(self::TABLE_PORDER, $row);
 }
예제 #7
0
파일: user.php 프로젝트: ptphp/ptphp
 static function bind_user($openid, $user_id)
 {
     $table = self::table("user_wx_rel");
     $row = self::_db()->row("select * from {$table} where user_id = ? and openid = ?", $user_id, $openid);
     if (empty($row)) {
         self::_db()->insert($table, array("user_id" => $user_id, "openid" => $openid, "bind_time" => Utils::date_time_now()));
     }
 }
예제 #8
0
파일: session.php 프로젝트: ptphp/ptphp
 static function session_start()
 {
     if (Utils::is_cli()) {
         return;
     }
     static $started = false;
     if (!$started) {
         session_start();
         $started = true;
     }
 }
예제 #9
0
파일: api.php 프로젝트: ptphp/ptphp
 static function get_auth_code_url()
 {
     if (!Utils::is_wechat_browser()) {
         $wechat_login_url = self::_get_auth_code_url_from_web();
         self::_debug(array("code url from open", $wechat_login_url));
     } else {
         $wechat_login_url = self::_get_auth_code_url_from_wechat();
         self::_debug(array("code url from wechat", $wechat_login_url));
     }
     return $wechat_login_url;
 }
예제 #10
0
파일: log.php 프로젝트: ptphp/ptphp
 static function add($msg, $method)
 {
     $ip = Utils::ip();
     $date = Utils::date_time_now();
     //        $row = array(
     //            "ip"       => $ip,
     //            "add_time" => $date,
     //            "msg"      => $msg,
     //            "method"   => $method,
     //            "user_id"  => Model_Admin_Auth::get_user_id(),
     //        );
     $row = array("action_ip" => Utils::ip(true), "create_time" => time(), "remark" => $msg, "model" => $method, "user_id" => Model_Admin_Auth::get_user_id());
     self::_db()->insert(self::TABLE, $row);
 }
예제 #11
0
파일: Tool.php 프로젝트: ptphp/ptphp
 function action_upload()
 {
     if (empty($_FILES)) {
         _throw("请选择上传文件");
     }
     $file_path = $_FILES['file']['tmp_name'];
     $file_name = "upload/img/" . date("YmdHis") . "/" . rand(10000, 99999) . "/" . $_FILES['file']['name'];
     $res = Model_Tools_Qiniu::upload_file($file_path, $file_name);
     $url = Model_Tools_Qiniu::get_res_url($res);
     self::_debug($url);
     if (Utils::I("simditor")) {
         echo json_encode(array("success" => true, "msg" => "ok", "file_path" => $url));
         exit;
     } else {
         return array("url" => $url);
     }
     //self::_debug($_FILES);
     //self::_debug($_REQUEST);
 }
예제 #12
0
파일: role.php 프로젝트: ptphp/ptphp
 static function update_permission($role_id, $permissions)
 {
     if (empty($role_id)) {
         _throw("role_id 不能为空");
     }
     if (is_array($permissions)) {
         $permissions = json_encode($permissions);
     }
     $permissions = Utils::unicodeString($permissions);
     $table = self::_table("role_perm");
     $row = self::_db()->select_row("select * from {$table} where role_id = ?", $role_id);
     if ($row) {
         $role_id = $row['role_id'];
         self::_db()->update($table, array("perm" => $permissions), array("role_id" => $role_id));
     } else {
         $id = self::_db()->insert($table, array("perm" => $permissions, "role_id" => $role_id));
     }
     return $role_id;
 }
예제 #13
0
파일: Category.php 프로젝트: ptphp/ptphp
 static function getRows()
 {
     $pk = self::pk();
     $table = self::table();
     $sql = "select {$pk} as `key`,cat_name,cat_pid as pid,cat_name as label,concat('d_',{$pk}) as value from {$table}";
     $rows = self::_db()->select_rows($sql);
     if (empty($rows)) {
         $row = array("cat_name" => "商品分类", "cat_pid" => 0);
         self::_db()->insert($table, $row);
         $rows = self::_db()->select_rows($sql);
     }
     $rows_key_name = array();
     $rows_key_pid = array();
     foreach ($rows as &$row) {
         $rows_key_name[$row['key']] = $row['cat_name'];
         $rows_key_pid[$row['key']] = $row['pid'];
     }
     $res = array("rows" => Utils::list_to_tree($rows, "key", "pid", "children"), "rows_key_name" => $rows_key_name, "rows_key_pid" => $rows_key_pid);
     return $res;
 }
예제 #14
0
파일: Zf.php 프로젝트: ptphp/ptphp
 static function getPayUrl($orderno, $total, $subject, $http_host = '')
 {
     $payType = Utils::is_wechat_browser() ? 19 : 18;
     $host = empty($http_host) ? HTTP_HOST : $http_host;
     $host = rtrim($host, "/");
     $data = array();
     $data['merchantNo'] = "990290048160001";
     $data['terminalNo'] = "77700032";
     $data['payMoney'] = $total;
     $data['productName'] = $subject;
     $data['inTradeOrderNo'] = $orderno;
     $data['payType'] = $payType;
     $data['merchant_url'] = "{$host}/api/pay/zf/pam_callback.php";
     $data['call_back_url'] = "{$host}/api/pay/zf/callback.php";
     $data['notify_url'] = "{$host}/api/pay/zf/notifySanWing.php";
     $key = "12345678";
     $data['signMsg'] = strtoupper(md5($data['merchantNo'] . $data['terminalNo'] . $data['payMoney'] . $data['inTradeOrderNo'] . $data['productName'] . $data['payType'] . $key));
     $url = "http://paygw.sanwing.com/swPayInterface";
     $url .= $payType == 18 ? "/html/alipayapi.jsp" : "/wechat/wechatPay.jsp";
     $url .= "?" . http_build_query($data);
     return $url;
 }
예제 #15
0
파일: auth.php 프로젝트: ptphp/ptphp
 static function check_login($username, $password)
 {
     $res = false;
     if (Utils::is_mobile($username)) {
         $stf_id = Model_Admin_Staff::get_staff_id_by_mobile($username);
         if (!$stf_id) {
             _throw("员工不存在");
         }
         self::_debug(array(__METHOD__, $stf_id));
         $user = Model_Admin_Staff::get_auth_user_by_stf_id($stf_id);
         self::_debug(array("auth user", $stf_id, $user));
         if (!$user) {
             _throw("员工未授权");
         }
         $_password = $user['password'];
         $salt = $user['salt'];
         if ($_password !== self::gen_password($password, $salt)) {
             _throw("密码不正确");
         }
         $res = true;
     }
     return $res;
 }
예제 #16
0
파일: order.php 프로젝트: ptphp/ptphp
 static function add($_row)
 {
     $row = self::getOrderSaveRow($_row);
     if ($row['orderno']) {
         $table = self::TABLE_ORDER;
         $order = self::_db()->select_row("select * from {$table} where orderno = ?", $row['orderno']);
         if ($order) {
             _throw("订单号:" . $row['orderno'] . " 已存在");
         }
     }
     $row['add_time'] = Utils::date_time_now();
     $row['op_uid'] = Model_Admin_Auth::get_user_id();
     $staff_info = Model_Admin_Staff::detail_by_uid($row['op_uid']);
     $row['op_name'] = $staff_info['name'];
     $items = self::getOrderItemsSaveRows($_row);
     $id = self::_db()->insert(self::TABLE_ORDER, $row);
     foreach ($items as &$item) {
         $item['order_id'] = $id;
     }
     if ($items) {
         self::_db()->insert("crm_client_order_item", $items);
     }
     return $id;
 }
예제 #17
0
파일: store.php 프로젝트: ptphp/ptphp
 static function note_add($id, $note, $op_uid)
 {
     $table = self::TABLE_TRACE;
     $row = array("note" => $note, "ip" => Utils::ip(), "store_id" => $id, "op_uid" => $op_uid, "add_time" => Utils::date_time_now());
     return self::_db()->insert($table, $row);
 }
예제 #18
0
파일: agent.php 프로젝트: ptphp/ptphp
 static function note_add($id, $note, $op_uid)
 {
     $row = array("note" => $note, "ip" => Utils::ip(), "agent_id" => $id, "op_uid" => $op_uid, "add_time" => Utils::date_time_now());
     return self::_db()->insert("crm_agent_trace", $row);
 }
예제 #19
0
파일: api.php 프로젝트: ptphp/ptphp
        foreach ($reflection->getParameters() as $arg) {
            if (isset($_REQUEST[$arg->name])) {
                $fire_args[$arg->name] = $_REQUEST[$arg->name];
            } else {
                $fire_args[$arg->name] = null;
            }
        }
        $controller_obj = new $controller();
        $return = call_user_func_array(array($controller_obj, $action), $fire_args);
    } else {
        $controller_obj = new $controller();
        if (!method_exists($controller_obj, $action)) {
            _throw($controller . "::{$action} is no exsits", 9004);
        }
        //$return = $controller_obj->$action();
        $return = call_user_func_array(array($controller_obj, $action), array());
    }
    if ($return !== null) {
        $result = $return;
    }
} catch (AppException $e) {
    //print_r($exception_point);
    $error_code = $e->getCode() ? $e->getCode() : 1;
    $result = $e->getMessage();
    Logger::warn(array($error_code, $result), Utils::get_exception_file_line($e->getTrace()));
} catch (Exception $e) {
    $error_code = $e->getCode() ? $e->getCode() : 1;
    $result = $e->getMessage();
    Logger::error(array($error_code, $result, $e->getTrace()));
}
api_json_response($result, $error_code);
예제 #20
0
파일: Goods.php 프로젝트: ptphp/ptphp
 function action_add($row)
 {
     $res = self::getSaveRow($row);
     $table = self::table();
     $pk = self::pk();
     $res['row']['add_time'] = Utils::date_time_now();
     $id = self::_db()->insert($table, $res['row']);
     return array($pk => $id);
 }
예제 #21
0
파일: Mission.php 프로젝트: ptphp/ptphp
 function action_add($row)
 {
     $res = self::getSaveRow($row);
     $res['row']['add_time'] = Utils::date_time_now();
     $id = self::_db()->insert("ldt_mission", $res['row']);
     if (!empty($res['tasks'])) {
         $tasks = $res['tasks'];
         foreach ($tasks as &$task) {
             unset($task['id']);
             $task['mission_id'] = $id;
         }
         //print_r($tasks);
         self::_db()->insert("ldt_mission_task", $tasks);
     }
     return array("id" => $id);
 }
예제 #22
0
파일: Bill.php 프로젝트: ptphp/ptphp
 function action_add($bill_type, $bill_amount, $bill_kind, $bill_note, $user_id)
 {
     $table = self::table();
     self::_db()->insert($table, array("bill_type" => $bill_type, "bill_amount" => $bill_amount, "bill_kind" => $bill_kind, "bill_note" => $bill_note, "user_id" => $user_id, "add_time" => Utils::date_time_now()));
 }
예제 #23
0
파일: user.php 프로젝트: ptphp/ptphp
 /**
  * 使用密码登陆
  * @param $username
  * @param $password
  * @return array|bool|mixed
  * @throws Exception
  */
 static function login_by_password($username, $password)
 {
     self::_debug($username, $password);
     try {
         if ($user_id = self::check_user_exsits($username)) {
             //绿电通验证
             self::_debug("user_id" . $user_id);
             $user_info = self::get_user_info($user_id);
             self::check_login_user_info($user_info, $password);
         } else {
             //passport 验证
             $passport_user = Model_Passport::login($username, $password);
             if (Utils::is_mobile($passport_user['username'])) {
                 $mobile = $passport_user['username'];
             } else {
                 $mobile = "";
                 try {
                     $passport_user = Model_Passport::get_user($passport_user['user_id']);
                     $mobile = $passport_user['mobile'];
                 } catch (Exception $e) {
                     self::_warn("passport get user error " . $e->getMessage());
                 }
             }
             $user_info = self::create_new_user($passport_user['username'], $password, $mobile, $passport_user['locked'], $passport_user['userid']);
             self::check_login_user_info($user_info, $password);
         }
     } catch (AppException $e) {
         _throw($e->getMessage());
     }
     self::_debug("登陆成功");
     return $user_info;
 }
예제 #24
0
파일: Log.php 프로젝트: ptphp/ptphp
 static function add($content, $method, $user_id, $ip = null)
 {
     self::_db()->insert(self::table(), array("content" => $content, "method" => $method, "ip" => $ip, "user_id" => $user_id, "add_time" => Utils::date_time_now()));
 }
예제 #25
0
파일: Auth.php 프로젝트: ptphp/ptphp
 /**
  * 微信绑定手机号
  * @return string
  */
 function action_wechat_bind_mobile()
 {
     Model_Session::session_start(true);
     $mobile = Utils::I("mobile");
     $nick_name = Utils::I("nick_name");
     $captcha = Utils::I("captcha");
     $oauth_id = Utils::I("oauth_id");
     self::_debug(array($oauth_id));
     $safe_token = Utils::I(Model_Auth::ENCRYPT_FIELD_NAME);
     if (!$safe_token) {
         _throw("safe_token is null");
     }
     //Model_Auth::login_safe($username,$password,$safe_token);
     $encrypt_data = self::_redis()->get(Model_Auth::ENCRYPT_CACEH_KEY . $safe_token);
     if (empty($encrypt_data)) {
         _throw("加密信息已过期");
     }
     $encrypt_data = json_decode($encrypt_data);
     $private_key = $encrypt_data->private_key;
     $reqData = array('mobile' => $mobile, 'captcha' => $captcha, 'nick_name' => $nick_name);
     $reqData = Safe::decrypt($reqData, $private_key);
     self::_debug($reqData);
     if (!$reqData) {
         _throw("解密失败");
     }
     $mobile = $reqData['mobile'];
     $nick_name = $reqData['nick_name'];
     $captcha = $reqData['captcha'];
     if (!Utils::is_mobile($mobile)) {
         _throw("手机号不合法");
     }
     $key = Controller_Captcha::get_captcha_session_key($mobile, "wechat_bind_mobile");
     self::_debug($key);
     if (empty($_SESSION[$key])) {
         _throw("验证码已过期");
     }
     $_captcha_session = $_SESSION[$key];
     self::_debug($_captcha_session);
     list($_captcha, $time) = explode("|", $_captcha_session);
     if (time() - $time > 60 * 60 * 5) {
         unset($_SESSION[$key]);
         _throw("验证码已过期");
     }
     self::_debug($_captcha_session);
     if ($captcha != $_captcha) {
         _throw("验证码不正确");
     }
     if (!($user_id = Model_User::check_user_exsits($mobile))) {
         $user = array("password" => null, "mobile" => $mobile, "nick_name" => $nick_name, "add_time" => Utils::date_time_now(), "email" => null);
         self::_debug("create user");
         self::_debug($user);
         $user_id = self::_db()->insert(Model_User::TABLE, $user);
     }
     self::_debug(array("update", Model_Wechat_User::TABLE, $user_id, $oauth_id));
     self::_db()->update(Model_Wechat_User::TABLE, array("uid" => $user_id), array("id" => $oauth_id));
     $wx_auth_info = $_SESSION['wx_auth_info'];
     $wx_auth_info['uid'] = $user_id;
     $_SESSION['wx_auth_info'] = $wx_auth_info;
     self::_debug($user_id);
     Model_Admin_Auth::set_login_session($user_id);
     //set login
     unset($_SESSION[$key]);
     Controller_Captcha::clear_status_key("wechat_bind_mobile");
     $redirect = self::get_redirect_url();
     return array("message" => "绑定成功", "redirect" => $redirect);
 }
예제 #26
0
파일: approve.php 프로젝트: ptphp/ptphp
 static function add($row)
 {
     $_row = array("add_time" => Utils::date_time_now());
     return self::_db()->insert(self::TABLE, $_row);
 }
예제 #27
0
파일: User.php 프로젝트: ptphp/ptphp
 function action_add($row)
 {
     $res = self::getSaveRow($row);
     $table = self::table();
     $pk = self::pk();
     $res['row']['add_time'] = Utils::date_time_now();
     if (!Utils::is_mobile($res['row']['mobile'])) {
         _throw("手机号不合法");
     }
     $mobile = $res['row']['mobile'];
     $user_mobile = self::_db()->row("select mobile from {$table} where mobile = ?", $mobile);
     if ($user_mobile) {
         _throw("手机号已存在");
     }
     if (!empty($res['row']['password'])) {
         $password = $res['row']['password'];
         $salt = \Model_Admin_Auth::gen_salt();
         $res['row']['password'] = \Model_Admin_Auth::gen_password($password, $salt);
         $res['row']['salt'] = $salt;
     } else {
         _throw("密码不能为空");
     }
     $user_id = self::_db()->insert($table, $res['row']);
     $stf_id = Model_Admin_Staff::get_staff_id_by_mobile($mobile);
     if ($stf_id) {
         Model_Admin_Staff::bind_staff_user($stf_id, $user_id);
     }
     $res = $this->action_row($user_id);
     $res['row'][$pk] = $user_id;
     return $res;
 }
예제 #28
0
파일: setting.php 프로젝트: ptphp/ptphp
use Symfony\Component\Yaml\Yaml;
use PtPHP\Utils;
/**
 * 配置类代码
 *
 */
class PtConfig
{
    public static $env = "development";
    public static $qiniu = array("access_key" => "zlbOjuyGIUaq73PhpZVetqvcPIPk6EgugFHY3N-y", "secret_key" => "7uiio8iIRfqOtlYqGpZpp7G3IpyUVOO5-QPkWkja", "bucket" => "lvdiantong", "domain" => "7xq9wj.com1.z0.glb.clouddn.com");
    public static $userRsaAuth = true;
    public static $safeLogin = array("username" => "", "password" => "");
    public static $siteAdminTitle = "PtPHP";
}
$env = Utils::get_pt_env("APPLICATION_ENV");
if ($env) {
    PtConfig::$env = $env;
} else {
    if (is_file(__DIR__ . "/.env.php")) {
        PtConfig::$env = (require_once __DIR__ . "/.env.php");
    }
}
$phinx_config = null;
if (is_file(PATH_PRO . "/phinx.yml")) {
    $phinx_config = Yaml::parse(@file_get_contents(PATH_PRO . "/phinx.yml"));
} elseif (is_file(PATH_APP . "/config/phinx.yml")) {
    $phinx_config = Yaml::parse(@file_get_contents(PATH_APP . "/config/phinx.yml"));
}
if ($phinx_config) {
    $db_config = $phinx_config['environments'][PtConfig::$env];
예제 #29
0
파일: Staff.php 프로젝트: ptphp/ptphp
 function action_add($row)
 {
     $table = self::table();
     $res = self::getSaveRow($row);
     $res['row']['add_time'] = Utils::date_time_now();
     if (!empty($res['row']['mobile'])) {
         $mobile = $res['row']['mobile'];
         $staff = self::_db()->row("select mobile from {$table} where mobile = ?", $mobile);
         if ($staff) {
             _throw("手机号已存在");
         }
     }
     $password = null;
     if (!empty($res['row']['password'])) {
         $password = $res['row']['password'];
         unset($res['row']['password']);
     }
     unset($res['row']['password']);
     $id = self::_db()->insert($table, $res['row']);
     if ($password) {
         $table_user = self::_table("user");
         $user_mobile = self::_db()->row("select user_id from {$table_user} where mobile = ?", $res['row']['mobile']);
         if (!$user_mobile) {
             $salt = \Model_Admin_Auth::gen_salt();
             $password = \Model_Admin_Auth::gen_password($password, $salt);
             $user_row = array("password" => $password, "mobile" => $res['row']['mobile'], "salt" => $salt, "add_time" => Utils::date_time_now());
             $user_id = self::_db()->insert($table_user, $user_row);
         } else {
             $user_id = $table_user['user_id'];
         }
         self::_db()->insert(self::_table("staff_user"), array("stf_id" => $id, "user_id" => $user_id));
     }
     return array("stf_id" => $id, "row" => self::get_detail($id));
 }