|
- <?php
-
- /**张帅
- * 数据汇总
- * Class dataInfo
- */
- class dataInfo extends base
- {
- /**
- * 获取城市
- */
- public function getArea($param)
- {
- $area_id = isset($param['area_id'])?trim($param['area_id']):false;//城市id
- if(false === $area_id)
- {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $sql = "SELECT
- id,
- area_name
- FROM
- base_area
- WHERE
- parent_id = " . $area_id;
- $area_array = $this->query($sql);
- $json['code'] = '0';
- $json['info'] = '返回数据成功';
- $json['list'] = $area_array;
- $json['count'] = (string)count($area_array);
- return $json;
- }
-
- /**
- * 操作联系人
- */
- public function execLink($param)
- {
- $operate = isset($param['operate']) ? trim($param['operate']) : '';//操作
- $id = isset($param['link_id']) ? trim($param['link_id']) : '';//id
- $link_name = isset($param['link_name']) ? trim($param['link_name']) : '';//联系类别
- $contact_name = isset($param['contact_name']) ? trim($param['contact_name']) : '';//姓名
- $contact_mobile = isset($param['contact_mobile']) ? trim($param['contact_mobile']) : '';//手机
- $contact_telphone = isset($param['contact_telphone']) ? trim($param['contact_telphone']) : '';//固话
- $fax = isset($param['fax']) ? trim($param['fax']) : '';//传真
- $email = isset($param['email']) ? trim($param['email']) : '';//邮箱
- $remark = isset($param['remark']) ? trim($param['remark']) : '';//备注
- //$is_db 是否为数据库已存的
- if ($operate == 'insert') {
- $result = $this->insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
- }
- if ($operate == 'delete') {
- $result = $this->deleteLink($id);
- }
- if ($operate == 'update') {
- $result = $this->updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
- }
- if ($operate == 'select') {
- $result = $this->selectLink($id);
- }
- return $result;
- }
-
- //增
- private function insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
- {
- if(!isset($_COOKIE['memcache']))
- {
- $time = time();
- setcookie('memcache',$time,time()+36000,"/");
- $_COOKIE['memcache']=$time;
- }
- $key = $_COOKIE['memcache'];
- $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
-
- if (!$link_memcache) {
- $link_memcache = array();
- }
- $link_info = array();
- $link_info['link_name'] = $link_name;
- $link_info['contact_name'] = $contact_name;
- $link_info['contact_mobile'] = $contact_mobile;
- $link_info['contact_telphone'] = $contact_telphone;
- $link_info['fax'] = $fax;
- $link_info['email'] = $email;
- $link_info['remark'] = $remark;
- $link_memcache[] = $link_info;
- $id_array = array_keys($link_memcache);
- $link_info['link_id'] = (string)end($id_array);//返回id
- $link_memcache[$link_info['link_id']] = $link_info;
- $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
- $json['code'] = '0';
- $json['info'] = '保存成功';
- $json['list'] = $link_info;
- return $json;
- }
-
- //删
- private function deleteLink($id)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
- unset($link_memcache[$id]);
- $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
- $json['code'] = '0';
- $json['info'] = '删除成功';
- return $json;
- }
-
- //改
- private function updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
- $link_info = $link_memcache[$id];
- $link_info['link_name'] = $link_name;
- $link_info['contact_name'] = $contact_name;
- $link_info['contact_mobile'] = $contact_mobile;
- $link_info['contact_telphone'] = $contact_telphone;
- $link_info['fax'] = $fax;
- $link_info['email'] = $email;
- $link_info['remark'] = $remark;
- $link_memcache[$id] = $link_info;
- $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
- $json['code'] = '0';
- $json['info'] = '修改成功';
- $json['list'] = $link_info;
- return $json;
- }
-
- //查
- private function selectLink($id)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
- $link_info = $link_memcache[$id];
- $json['code'] = '0';
- $json['info'] = '查询成功';
- $json['list'] = $link_info;
- return $json;
- }
-
- /**
- * 操作销售方式
- */
- public function execSale($param)
- {
- $operate = isset($param['operate']) ? trim($param['operate']) : '';
- $sale_id = isset($param['sale_id']) ? trim($param['sale_id']) : '';//id
- $prod_supplier_id = isset($param['prod_supplier_id']) ? trim($param['prod_supplier_id']) : '0';//供应商id
- $product_type = isset($param['product_type']) ? trim($param['product_type']) : '0';//产品子类(二级类)
- $parent_type = isset($param['parent_type']) ? trim($param['parent_type']) : '0';//产品父类(一级类)
- $sale_type = isset($param['sale_type']) ? trim($param['sale_type']) : '0';//销售方式
- $commision_flag = isset($param['commision_flag']) ? trim($param['commision_flag']) : '0';//是否有佣金规则,1:有,0:无
- $commision_type = isset($param['commision_type']) ? trim($param['commision_type']) : '0';//佣金类别
- $back_commision_type = isset($param['back_commision_type']) ? ($param['back_commision_type'] == '' ? '0' : trim($param['back_commision_type'])) : '0';//返佣类别
- $back_commision_method = isset($param['back_commision_method']) ? ($param['back_commision_method'] == '' ? '0' : trim($param['back_commision_method'])) : '0';//返佣方式
- $back_percent = isset($param['back_percent']) ? trim($param['back_percent']) : '0';//返佣比例
- $back_value = isset($param['back_value']) ? trim($param['back_value']) : '0';//返佣固定金额
- //$is_db 是否为数据库已存的
- if ($operate == 'insert') {
- $result = $this->insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
- }
- if ($operate == 'delete') {
- $result = $this->deleteSale($sale_id);
- }
- if ($operate == 'update') {
- $result = $this->updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
- }
- if ($operate == 'select') {
- $result = $this->selectSale($sale_id);
- }
- return $result;
- }
-
- //增
- private function insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
- {
- if (!isset($_COOKIE['memcache'])) {
- $time = time();
- setcookie('memcache', $time, time() + 36000, "/");
- $_COOKIE['memcache'] = $time;
- }
-
- $key = $_COOKIE['memcache'];
- $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
-
- if (!$sale_memcache) {
- $sale_memcache = array();
- }
-
- if ($back_percent == '' || $back_value == '') {
- $json['code'] = '1';
- $json['info'] = '请完整填写佣金规则';
- echo json_encode($json);
- exit();
- }
-
- $sale_info = array();
- $sale_info['prod_supplier_id'] = $prod_supplier_id;
- $sale_info['product_type'] = $product_type;
- $sale_info['parent_type'] = $parent_type;
- $sale_info['sale_type'] = $sale_type;
- $sale_info['commision_flag'] = $commision_flag;
- $sale_info['commision_type'] = $commision_type;
- $sale_info['back_commision_type'] = $back_commision_type;
- $sale_info['back_commision_method'] = $back_commision_method;
- $sale_info['back_percent'] = $back_percent;
- $sale_info['back_value'] = $back_value;
- $sale_memcache[] = $sale_info;
- $id_array = array_keys($sale_memcache);
- $sale_info['sale_id'] = (string)end($id_array);
- $sale_memcache[$sale_info['sale_id']] = $sale_info;
-
- $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
-
- $json['code'] = '0';
- $json['info'] = '保存成功';
- $json['list'] = $sale_info;
- return $json;
- }
-
- //删
- private function deleteSale($sale_id)
- {
- $key = $_COOKIE['memcache'];
- $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
- unset($sale_memcache[$sale_id]);
- $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
- $json['code'] = '0';
- $json['info'] = '删除成功';
- return $json;
- }
-
- //改
- private function updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
- {
- if ($back_percent == '' || $back_value == '') {
- $json['code'] = '1';
- $json['info'] = '请完整填写佣金规则';
- return $json;
- }
- $key = $_COOKIE['memcache'];
- $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
- $sale_info = $sale_memcache[$sale_id];
- $sale_info['prod_supplier_id'] = $prod_supplier_id;
- $sale_info['product_type'] = $product_type;
- $sale_info['parent_type'] = $parent_type;
- $sale_info['sale_type'] = $sale_type;
- $sale_info['commision_flag'] = $commision_flag;
- $sale_info['commision_type'] = $commision_type;
- $sale_info['back_commision_type'] = $back_commision_type;
- $sale_info['back_commision_method'] = $back_commision_method;
- $sale_info['back_percent'] = $back_percent;
- $sale_info['back_value'] = $back_value;
- $sale_memcache[$sale_id] = $sale_info;
- $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
-
- $json['code'] = '0';
- $json['info'] = '修改成功';
- $json['list'] = $sale_info;
- return $json;
- }
-
- //查
- private function selectSale($sale_id)
- {
- $key = $_COOKIE['memcache'];
- $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
- $sale_info = $sale_memcache[$sale_id];
- $json['code'] = '0';
- $json['info'] = '查询成功';
- $json['list'] = $sale_info;
- return $json;
- }
-
- /**
- * 检查供应商或渠道商名字
- * @param $param
- */
- public function checkSupplierName($param)
- {
- $supplier_type = isset($param['supplier_type'])?trim($param['supplier_type']):false;
- $supplier_name = isset($param['supplier_name'])?trim($param['supplier_name']):false;
- $supplier_id = empty($param['supplier_id'])?'':" and id != " . trim($param['supplier_id']);
- if(!$supplier_type || !$supplier_name){
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $sql = "SELECT
- supplier_name
- FROM
- base_supplier
- WHERE
- cancel_flag = 0
- AND supplier_name = '" . $supplier_name . "' AND supplier_type={$supplier_type} " . $supplier_id;
- $check_name = $this->query($sql);
- if(count($check_name) > 0)
- {
- $json['code'] = '1';
- $json['info'] = '用户名已存在';
- }
- else
- {
- $json['code'] = '0';
- $json['info'] = '用户名可用';
- }
- return $json;
- }
-
- /**
- * 操作账户
- * @param $param
- */
- public function execUser($param)
- {
- $operate = isset($param['operate']) ? trim($param['operate']) : false;
- $supplier_id = isset($param['supplier_id']) ? trim($param['supplier_id']) : '';//供应商或渠道商id
- $user_name = isset($param['user_name']) ? trim($param['user_name']) : '';//用户名
- $true_name = isset($param['true_name']) ? trim($param['true_name']) : '';//真实姓名
- $phone_no = isset($param['phone_no']) ? trim($param['phone_no']) : '';//手机号
- $user_id = isset($param['user_id']) ? trim($param['user_id']) : '';//用户id
-
- if($operate == 'check')//获得账号列表
- {
- $result = $this -> checkUserName($user_id,$user_name,'check');
- }
- if($operate == 'insert')//新增数据
- {
- $result = $this -> insertUser($supplier_id,$user_name,$true_name,$phone_no);
- }
- if($operate == 'list')//获得账号列表
- {
- $result = $this -> getListUser($supplier_id);
- }
- if($operate == 'stop')//停用
- {
- $result = $this -> stopUser($user_id);
- }
- if($operate == 'start')//启用
- {
- $result = $this -> startUser($user_id);
- }
- if($operate == 'delete')//删除
- {
- $result = $this -> deleteUser($user_id);
- }
- if($operate == 'detail')//获取详情
- {
- $result = $this -> detailUser($user_id);
- }
- if($operate == 'update')//修改账号
- {
- $result = $this -> updateUser($user_id,$user_name,$true_name,$phone_no);
- }
- if($operate == 'update_password')//初始化密码
- {
- $result = $this -> updateUserPassword($user_id);
- }
- return $result;
- }
-
- //新增用户
- private function insertUser($supplier_id,$user_name,$true_name,$phone_no)
- {
- if(empty($supplier_id) || empty($user_name) || empty($true_name) || empty($phone_no))
- {
- $json['code'] = '1';
- $json['info'] = '必填项不可为空';
- return $json;
- }
- $check_result = $this -> checkUserName('',$user_name,'insert_check');
- if(isset($check_result['code']) && $check_result['code'] != '0')
- {
- return $check_result;
- }
- $user_id = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- $id_sql = "select max(id) as id from base_user";
- $id = $this->query($id_sql);
- $id = $id[0]['id'];
- $id = $id+1;
-
- $main_corp_id_sql = "select main_corp_id from base_supplier where id = " . $supplier_id . ' and cancel_flag = 0 limit 1';
- $main_corp_id = $this->query($main_corp_id_sql);
- $main_corp_id = $main_corp_id[0]['main_corp_id'];
-
- $password = md5('zzcx8888');
- $sql = "INSERT INTO base_user (
- create_user_id,
- create_time,
- id,
- user_name,
- org_id,
- top_org_id,
- user_password,
- true_name,
- phone_no,
- `status`,
- main_corp_id
- )
- VALUE
- (" . $user_id . ", '" . $time . "'," . $id . ",'" . $user_name . "', " . $supplier_id . ", " . $supplier_id . ", '" . $password . "', '" . $true_name . "', '" . $phone_no . "',0," . $main_corp_id . ")";
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '插入成功';
- }
- else
- {
- $json['code'] = '1';
- $json['info'] = '系统原因插入失败';
- }
- return $json;
- }
-
- //检验用户名
- private function checkUserName($user_id,$user_name,$check_type)
- {
- if(empty($user_id))
- {
- $sql = "SELECT
- user_name
- FROM
- base_user
- WHERE
- cancel_flag = 0
- AND user_name = '" . $user_name . "'";
- }
- else
- {
- $sql = "SELECT
- user_name
- FROM
- base_user
- WHERE
- cancel_flag = 0
- AND id != " . $user_id . "
- AND user_name = '" . $user_name . "'";
- }
- $res = $this->query($sql);
- if(count($res) > 0)
- {
- $json['code'] = '1';
- $json['info'] = '用户名已存在';
- return $json;
- }
- else
- {
- if($check_type == 'check')
- {
- $json['code'] = '0';
- $json['info'] = '用户名可用';
- return $json;
- }
- else
- {
- return true;
- }
- }
- }
-
- //获得账号列表
- private function getListUser($supplier_id)
- {
- $sql = "SELECT
- id,true_name,`status`
- FROM
- base_user
- WHERE
- cancel_flag = 0
- AND org_id = " . $supplier_id;
- $res = $this->query($sql);
- if(count($res) > 0)
- {
- foreach($res as $k => $v)
- {
- if($v['status'] == 0)
- {
- $res[$k]['status'] = '停用';
- }
- else
- {
- $res[$k]['status'] = '启用';
- }
- }
- }
- $json['code'] = '0';
- $json['info'] = '用户名可用';
- $json['list'] = $res;
- return $json;
- }
-
- //停用账号
- private function stopUser($user_id)
- {
- $userId = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- $sql = "UPDATE base_user
- SET `status` = 1,
- update_user_id = " . $userId . ",
- update_time = '" . $time . "'
- WHERE
- id = " .$user_id;
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '停用成功';
- }
- else {
- $json['code'] = '1';
- $json['info'] = '系统原因停用失败';
- }
- return $json;
- }
-
- //启用账号
- private function startUser($user_id)
- {
- $userId = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- $sql = "UPDATE base_user
- SET `status` = 0,
- update_user_id = " . $userId . ",
- update_time = '" . $time . "'
- WHERE
- id = " .$user_id;
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '启用成功';
- }
- else {
- $json['code'] = '1';
- $json['info'] = '系统原因启用失败';
- }
- return $json;
- }
-
- //删除账号
- private function deleteUser($user_id)
- {
- $userId = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- $sql = "UPDATE base_user
- SET cancel_flag = 1,
- update_user_id = " . $userId . ",
- update_time = '" . $time . "'
- WHERE
- id = " .$user_id;
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '删除成功';
- }
- else {
- $json['code'] = '1';
- $json['info'] = '系统原因删除失败';
- }
- return $json;
- }
-
- //获取详情
- private function detailUser($user_id)
- {
- $sql = "SELECT
- id,user_name,true_name,phone_no
- FROM
- base_user
- WHERE
- cancel_flag = 0
- AND id = " . $user_id;
- $res = $this->query($sql);
- if(count($res) > 0)
- {
- $json['code'] = '0';
- $json['info'] = '获取信息成功';
- $json['list'] = $res;
- }
- else
- {
- $json['code'] = '1';
- $json['info'] = '该数据已删除';
- }
- return $json;
- }
-
- //修改账号
- private function updateUser($user_id,$user_name,$true_name,$phone_no)
- {
- $userId = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- if(empty($user_id) || empty($user_name) || empty($true_name) || empty($phone_no))
- {
- $json['code'] = '1';
- $json['info'] = '必填项不可为空';
- return $json;
- }
- $check_result = $this -> checkUserName($user_id,$user_name,'update_check');
- if(isset($check_result['code']) && $check_result['code'] != '0')
- {
- return $check_result;
- }
- $sql = "UPDATE base_user
- SET user_name = '" . $user_name . "',
- true_name = '" . $true_name . "',
- phone_no = '" . $phone_no . "',
- update_user_id = " . $userId . ",
- update_time = '" . $time . "'
- WHERE
- id = " . $user_id;
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '修改成功';
- }
- else {
- $json['code'] = '1';
- $json['info'] = '系统原因修改失败';
- }
- return $json;
- }
-
- //重置密码
- private function updateUserPassword($user_id)
- {
- $userId = $this->user_id;
- $time = date('Y-m-d H:i:s',time());
- $sql = "UPDATE base_user
- SET user_password = '" . md5('Zzcx888') . "',
- update_user_id = " . $userId . ",
- update_time = '" . $time . "'
- WHERE
- id = " . $user_id;
- $result = $this->exec($sql);
- if($result)
- {
- $json['code'] = '0';
- $json['info'] = '初始化密码成功';
- }
- else {
- $json['code'] = '1';
- $json['info'] = '系统原因初始化密码失败';
- }
- return $json;
- }
- }
- ?>
|