function test_action_remove() { $mobile = "18601628932"; $stf_id = \Model_Admin_Staff::get_staff_id_by_mobile($mobile); if ($stf_id) { $res = $this->obj->action_remove($stf_id, "1"); var_export($res); } else { throw new Exception("stf_id is null"); } }
static function list_rows($condition = array(), $pager = array(), $order = array()) { $sort_field = !in_array($order['sort_field'], array("id")) ? "id" : $order['sort_field']; $table = self::TABLE_REVISIT; $where = 'where 1= 1'; $args = array(); if (!empty($condition['client_id'])) { $where .= " and client_id = ?"; $args[] = $condition['client_id']; } // if(!empty($condition['name'])){ // $where .= " and name like ?"; // $args[] = "%".$condition['name']."%"; // } $sort_type_tpl = array("ascend" => "asc", "descend" => "desc"); $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']]; //_throw($sort_type); $count_res = self::_db()->select_row("SELECT COUNT(id) AS total FROM {$table} {$where}", $args); $records = $count_res['total']; $page = $pager['page']; $limit = $pager['limit']; if ($records > 0) { $total_pages = ceil($records / $limit); } else { $total_pages = 1; } $skip = ($page - 1) * $limit; $sql = "SELECT *,id as `key` FROM {$table} {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} "; //_throw($sql); //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type)); $rows = self::_db()->select_rows($sql, $args); foreach ($rows as &$row) { $op_uid = $row['op_uid']; $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid); if ($staff_info) { $row['op_name'] = $staff_info['name']; $row['op_avatar'] = $staff_info['avatar']; } else { $row['op_name'] = ""; $row['op_avatar'] = ""; } } return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows); }
static function list_rows($condition = array(), $pager = array(), $order = array()) { $sort_field = !in_array($order['sort_field'], array("id")) ? "id" : $order['sort_field']; $table = self::TABLE_ORDER; $where = 'where 1= 1'; $args = array(); if (!empty($condition['client_id'])) { $where .= " and client_id = ?"; $args[] = $condition['client_id']; } $sort_type_tpl = array("ascend" => "asc", "descend" => "desc"); $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']]; //_throw($sort_type); $count_res = self::_db()->select_row("SELECT COUNT(id) AS total FROM {$table} {$where}", $args); $records = $count_res['total']; $page = $pager['page']; $limit = $pager['limit']; if ($records > 0) { $total_pages = ceil($records / $limit); } else { $total_pages = 1; } $skip = ($page - 1) * $limit; $sql = "SELECT *,id as `key` FROM {$table} {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} "; //_throw($sql); //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type)); $rows = self::_db()->select_rows($sql, $args); foreach ($rows as &$row) { $op_uid = $row['op_uid']; $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid); if ($staff_info) { $row['op_name'] = $staff_info['name']; $row['op_avatar'] = $staff_info['avatar']; } else { $row['op_name'] = ""; $row['op_avatar'] = ""; } $row['items'] = self::_db()->select_rows("select i.id as `key`,p.*,i.item_num as num,i.doct_uid,i.doct_name,i.appoint_time\n from crm_client_order_item as i\n left join crm_product as p on p.id = i.item_id\n where i.order_id = ?", $row['id']); } return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows); }
static function list_rows($condition = array(), $pager = array(), $order = array()) { $sort_field = !in_array($order['sort_field'], array("id", "name")) ? "id" : $order['sort_field']; $table = self::TABLE; $table_alias = "c"; $sort_field = $table_alias . "." . $sort_field; $where = "where {$table_alias}.is_del = 0"; $args = array(); if (!empty($condition['name'])) { $where .= " and {$table_alias}.name like ?"; $args[] = "%" . $condition['name'] . "%"; } if (!empty($condition['tel'])) { $where .= " and {$table_alias}.tel like ?"; $args[] = "%" . $condition['tel'] . "%"; } if (!empty($condition['zxs_uid'])) { $where .= " and {$table_alias}.zxs_uid like ?"; $args[] = "%" . $condition['zxs_uid'] . "%"; } if (!empty($condition['sjs_uid'])) { $where .= " and {$table_alias}.sjs_uid like ?"; $args[] = "%" . $condition['sjs_uid'] . "%"; } if (!empty($condition['ys_uid'])) { $where .= " and {$table_alias}.ys_uid like ?"; $args[] = "%" . $condition['ys_uid'] . "%"; } if (!empty($condition['area_id'])) { $where .= " and {$table_alias}.area_id = ?"; $args[] = $condition['area_id']; } if (!empty($condition['province_id'])) { $where .= " and {$table_alias}.province_id = ?"; $args[] = $condition['province_id']; } if (!empty($condition['store_id'])) { $where .= " and {$table_alias}.store_id = ?"; $args[] = $condition['store_id']; } if (!empty($condition['start_time'])) { $where .= " and {$table_alias}.add_time >= ?"; $args[] = $condition['start_time'] . " 00:01"; } if (!empty($condition['end_time'])) { $where .= " and {$table_alias}.add_time <= ?"; $args[] = $condition['end_time'] . " 23:59"; } $user_id = Model_Admin_Auth::get_user_id(); if ($user_id > 0) { $uids = Model_Admin_Staff::get_sub_position_uids($user_id); $uids[] = $user_id; $where .= " and ({$table_alias}.op_uid in (" . implode(",", $uids) . ") or\n {$table_alias}.zxs_uid = ? or\n {$table_alias}.zxz_uid = ? or\n {$table_alias}.sjs_uid = ? or\n {$table_alias}.yl_uid = ? or\n {$table_alias}.sj_uid = ? or\n {$table_alias}.kef_uid = ? or\n {$table_alias}.ys_uid = ? or\n {$table_alias}.copyer like ?\n )"; $args[] = $user_id; $args[] = $user_id; $args[] = $user_id; $args[] = $user_id; $args[] = $user_id; $args[] = $user_id; $args[] = $user_id; $args[] = "%|" . $user_id . "|%"; } $sort_type_tpl = array("ascend" => "asc", "descend" => "desc"); $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']]; //_throw($sort_type); $count_res = self::_db()->select_row("SELECT COUNT({$table_alias}.id) AS total FROM {$table} as {$table_alias} {$where}", $args); $records = $count_res['total']; $page = $pager['page']; $limit = $pager['limit']; if ($records > 0) { $total_pages = ceil($records / $limit); } else { $total_pages = 1; } $skip = ($page - 1) * $limit; $sql = "SELECT {$table_alias}.*,{$table_alias}.id as `key` FROM {$table} as {$table_alias} {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} "; //_throw($sql); //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type)); $rows = self::_db()->select_rows($sql, $args); foreach ($rows as &$row) { $row['key'] = $row['id']; if ($row['store_id']) { $store_info = Model_Crm_Store::detail($row['store_id']); if ($store_info && $store_info['is_del'] == 0) { $row['store_name'] = $store_info['name']; $row['area_id'] = $store_info['area_id']; $row['province_id'] = $store_info['province_id']; } else { $row['store_name'] = ""; $row['area_id'] = ""; $row['province_id'] = ""; } } else { $row['area_id'] = ""; $row['province_id'] = ""; $row['store_name'] = ""; } $row['area_name'] = Model_Crm_Area::detail($row['area_id']); $row['province_name'] = Model_Province::detail($row['province_id']); } return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows); }
function action_update($id, $row) { $table = self::table(); $res = self::getSaveRow($row, false); $password = null; if (!empty($res['row']['mobile'])) { $mobile = $res['row']['mobile']; $staff = self::_db()->row("select mobile from {$table} where stf_id <> ? and mobile = ?", $id, $mobile); if ($staff) { _throw("手机号已存在"); } } if (!empty($res['row']['password'])) { $password = $res['row']['password']; } unset($res['row']['password']); self::_db()->update($table, $res['row'], array("stf_id" => $id)); $auth_user = \Model_Admin_Staff::get_auth_user_by_stf_id($id); if ($password) { //修改密码 if ($auth_user) { $salt = $auth_user['salt']; } else { $salt = \Model_Admin_Auth::gen_salt(); } //生成密码 $password = \Model_Admin_Auth::gen_password($password, $salt); if ($auth_user) { $user_row = array("password" => $password); self::_db()->update(self::_table("user"), $user_row, array("user_id" => $auth_user['user_id'])); } else { $table_user = self::_table("user"); $user_mobile = self::_db()->row("select user_id from {$table_user} where mobile = ?", $res['row']['mobile']); if (!$user_mobile) { $user_row = array("password" => $password, "salt" => $salt, "mobile" => $res['row']['mobile'], "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)); } } //修改登陆手机号 if ($auth_user && !empty($res['row']['mobile'])) { $mobile = $res['row']['mobile']; self::_db()->update(self::_table("user"), array("mobile" => $mobile), array("user_id" => $auth_user['user_id'])); } return array("stf_id" => $id, "row" => self::get_detail($id)); }
static function get_role_id() { $user_id = self::get_user_id(); $staff_info = Model_Admin_Staff::detail_by_uid($user_id); return $staff_info && $staff_info['role_id'] ? $staff_info['role_id'] : 0; }