Example #1
0
 public function update_customer_head($ids, $uid)
 {
     if (!$ids) {
         return;
     }
     $company_id = get_current_company_id();
     // 原始数据
     $source = array();
     if (!$uid) {
         $source = $this->where(array('id' => array("IN", $ids)))->select();
         $source = get_array_to_kv($source, 'user_id', 'id');
     }
     // 往来单位
     $contacts_company = D('ContactsCompany/ContactsCompany', 'Service')->where(array('id' => array("IN", $ids)))->select();
     $contacts_company = get_array_to_ka($contacts_company);
     foreach ($ids as $id) {
         $map = array('contacts_company_id' => $id, 'company_id' => $company_id);
         $exists = $this->where($map)->find();
         if ($exists) {
             // 已存在更新负责人ID
             $this->where($map)->save(array('head_id' => $uid));
         } else {
             // 不存在新增一条
             $data = array('contacts_company_id' => $id, 'head_id' => $uid, 'user_id' => $uid, 'crm_clue_id' => null, 'company_id' => $company_id, 'source_from' => $contacts_company[$id]['source_form']);
             $this->add($data);
         }
     }
     $head_model = D('Crm/CustomerHeadLog');
     $type = $uid ? 1 : 2;
     foreach ($ids as $id) {
         $user_id = $uid ? $uid : $source[$id];
         $head_model->add(array('type' => $type, 'company_id' => $company_id, 'customer_id' => $id, 'user_id' => $user_id));
     }
     return true;
 }
Example #2
0
 public function bootstrap()
 {
     $data = array();
     foreach ($this->bootstrapConfigs as $k => $v) {
         if (in_array($k, $this->supportResponseBaseConfigKeys)) {
             $data[$k] = $v;
         }
     }
     // 已启用应用
     $data['loaded_apps'] = array_merge(AppService::$activeApps, AppService::$baseApps);
     // 已授权节点
     $data['authed_nodes'] = get_array_to_kv(AuthorizeService::$authed_nodes, "flag", "node");
     // 用户信息
     $data['all_users'] = UserService::get_all_basic_data();
     // 当前用户信息
     $data['user_info'] = D('Account/User')->get_current_user();
     // 系统首选项
     $system_preference = D('Home/Config', 'Service')->get_kv_config();
     foreach ($system_preference as $k => $v) {
         $system_preference[$k] = Schema::data_field_format($v['val'], $v['data_type']);
     }
     $data['system_preference'] = $system_preference;
     // 个人首选项
     $user_preference = D('Account/UserPreference', 'Service')->get_preference();
     foreach ($user_preference as $k => $v) {
         $user_preference[$k] = Schema::data_field_format($v['data'], $v['data_type']);
     }
     $data['user_preference'] = $user_preference;
     // 主页面包含
     $data['main_include'] = D('Home/Config', 'Service')->get_main_include();
     tag('before_bootstrap_config_response', $data);
     $this->response($data);
 }
 public function get_tree($pid = null)
 {
     $data = parent::get_tree($pid);
     $leaders = array();
     foreach ($data as $k => $v) {
         $leaders = array_merge($leaders, explode(',', $v['leader']));
     }
     if (!$leaders) {
         return $data;
     }
     $users = D('Account/User')->where(array('id' => array("IN", array_filter($leaders))))->select();
     $realnames = get_array_to_kv($users, 'realname');
     foreach ($data as $k => $v) {
         if (!$v['leader']) {
             continue;
         }
         $leaders_name = array();
         $the_leader = explode(',', $v['leader']);
         foreach ($the_leader as $leader) {
             $leaders_name[] = $realnames[$leader];
         }
         $data[$k]['leader_label'] = implode(',', $leaders_name);
     }
     return $data;
 }
Example #4
0
 public function on_event_list()
 {
     $apps_get = I('get.apps');
     if ($apps_get === "all") {
         $apps = array_merge((array) get_array_to_kv(D('Home/App')->select(), 'alias'), $this->baseApps);
     } else {
         $apps = explode(',', $apps_get);
         // 应用requirements
         foreach ($apps as $app) {
             $app_config = ConfigService::get_config_by_app($app);
             if ($app_config['requirements']) {
                 $apps = array_merge($apps, (array) $app_config['requirements']);
             }
         }
     }
     array_unshift($apps, 'common');
     $apps = array_unique($apps);
     if ($apps !== array("common", "account") && !$this->is_login()) {
         $this->login_required();
     }
     $cache_key = sprintf('i18n/%s/all', CURRENT_LANGUAGE);
     $langs = S($cache_key);
     if (DEBUG || !$langs) {
         $langs = self::make_i18n_cache($cache_key);
     }
     $return = array();
     foreach ($apps as $app) {
         if ($apps_get !== 'all' && $app !== "common" && !AppService::is_app_active($app)) {
             continue;
         }
         $return[$app] = $langs[$app];
     }
     $this->response($return);
 }
 public function run(&$param)
 {
     $ids = is_array($param['deleted']) ? $param['deleted'] : explode(',', $param['deleted']);
     $map = array('source_model' => sprintf('%s.%s', lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME)), 'source_id' => array('IN', $ids));
     $data = D('Uploader/Attachment', 'Model')->where($map)->select();
     $attach_ids = get_array_to_kv($data, 'id', 'id');
     $service = D('Uploader/Attachment', 'Service');
     $service->do_delete($attach_ids);
 }
Example #6
0
 public function disable($alias)
 {
     $apps_info = $this->where(array('alias' => array('IN', $alias)))->select();
     if (!$apps_info) {
         return true;
     }
     $model = D('Account/CompanyActiveApps');
     return $model->where(array('app_id' => array('IN', get_array_to_kv($apps_info, 'id')), 'company_id' => get_current_company_id()))->delete();
 }
Example #7
0
function DBC($alias = null)
{
    $cache_key = "db_config_" . get_current_company_id();
    $cached = S($cache_key);
    if (DEBUG || !$cached) {
        $cached = D('Home/Config', 'Service')->get_kv_config();
        $cached = get_array_to_kv($cached, 'val', 'alias');
        S($cache_key, $cached);
    }
    return $alias ? $cached[$alias] : $cached;
}
Example #8
0
 public function on_list()
 {
     $this->_authed_nodes = get_array_to_kv(parent::$authed_nodes, 'node');
     $navs = $this->bootstrapConfigs['navs'];
     foreach ($this->appConfigs as $app => $config) {
         if (!$this->is_app_active($app)) {
             continue;
         }
         $navs = array_merge_recursive($navs, (array) $config["navs"]);
     }
     // 二维数组导航信息
     $flat_navs = array();
     $flat_cache_key = 'navs/all/flat';
     /*
      * 支持三级菜单
      * **/
     $result = array();
     foreach ($navs as $n1alias => $n1st) {
         $n2children = array();
         foreach ($n1st['children'] as $n2alias => $n2nd) {
             $n3children = array();
             foreach ($n2nd['children'] as $n3alias => $n3rd) {
                 if (!$this->check_nav_permission($n3rd)) {
                     continue;
                 }
                 $n3rd['alias'] = $n3alias;
                 array_push($n3children, $n3rd);
                 unset($n3rd['children']);
                 array_push($flat_navs, $n3rd);
             }
             if (!$this->check_nav_permission($n2nd) || !$n3children && !$n2nd['link']) {
                 continue;
             }
             $n2nd['alias'] = $n2alias;
             $n2nd['children'] = $n3children;
             array_push($n2children, $n2nd);
             unset($n2nd['children']);
             array_push($flat_navs, $n2nd);
         }
         $n1st['children'] = $n2children;
         $n1st['alias'] = $n1alias;
         if (!$this->check_nav_permission($n1st) || !$n1st['children'] && !$n1st['link']) {
             continue;
         }
         array_push($result, $n1st);
         unset($n1st['children']);
         array_push($flat_navs, $n1st);
     }
     tag("before_nav_response", $result);
     S($flat_cache_key, $flat_navs);
     $this->response($result);
 }
Example #9
0
 public function update_kv_config($data)
 {
     $company_id = get_current_company_id();
     $exists = $this->where(array('company_id' => $company_id))->select();
     $exists_id = get_array_to_kv($exists, 'id', 'alias');
     $exists = get_array_to_kv($exists, 'val', 'alias');
     foreach ($data as $row) {
         if (array_key_exists($row['alias'], $exists)) {
             if ($row['val'] == $exists) {
                 continue;
             }
             $this->save(array('id' => $exists_id[$row['alias']], 'val' => $row['val'], 'alias' => $row['alias'], 'data_type' => $row['data_type'], 'app' => $row['app']));
             continue;
         }
         $row['company_id'] = $company_id;
         $this->add($row);
     }
     S('kv_db_configs' . get_current_company_id(), null);
 }
 public function update_kv_config($data)
 {
     $uid = get_current_user_id();
     $exists = $this->where(array('user_id' => $uid))->select();
     $exists_id = get_array_to_kv($exists, 'id', 'name');
     $exists = get_array_to_kv($exists, 'data', 'name');
     foreach ($data as $row) {
         if (array_key_exists($row['name'], $exists)) {
             if ($row['data'] == $exists) {
                 continue;
             }
             $this->save(array('id' => $exists_id[$row['name']], 'data' => $row['data'], 'name' => $row['name'], 'data_type' => $row['data_type']));
             continue;
         }
         $row['user_id'] = $uid;
         $this->add($row);
     }
     S('user_preference_' . $uid, null);
 }
Example #11
0
 public function update_clue_head($ids, $uid)
 {
     if (!$ids) {
         return;
     }
     // 原始数据
     $source = array();
     if (!$uid) {
         $source = $this->where(array('id' => array("IN", $ids)))->select();
         $source = get_array_to_kv($source, 'user_id', 'id');
     }
     $result = $this->where(array("id" => array("IN", $ids)))->save(array("head_id" => $uid));
     if (false === $result) {
         return $result;
     }
     $head_model = D('Crm/CustomerHeadLog');
     $company_id = get_current_company_id();
     $type = $uid ? 1 : 2;
     foreach ($ids as $id) {
         $user_id = $uid ? $uid : $source[$id];
         $head_model->add(array('type' => $type, 'company_id' => $company_id, 'crm_clue_id' => $id, 'user_id' => $user_id));
     }
     return $result;
 }
Example #12
0
 public static function get_map_by_flag($flag, $map, $model_name = null)
 {
     $field_name = $model_name ? $model_name . '.user_id' : 'user_id';
     $user_service = D('Account/Department', 'Service');
     switch ($flag) {
         case "1":
             // 自己
             break;
         case "2":
             // 所有人
             $map[$field_name] = get_current_user_id();
             break;
         case "3":
             // 自己和直属下属
             $subs = $user_service->get_directly_subordinates();
             if ($subs) {
                 $map[$field_name] = array("IN", get_array_to_kv($subs, 'id'));
             }
             break;
         case "4":
             // 自己和所有下属
             break;
         case "5":
             // 自己部门
             break;
         case "6":
             // 自己部门及部门下属部门
             break;
         case "7":
             // 自己负责
             break;
         case "8":
             // 自己及直属下属负责
             break;
         case "9":
             // 自己及所有下属负责
             break;
     }
     return $map;
 }
 public function on_put()
 {
     // 提交的源数据
     $source_data = I('post.');
     $workflow_id = I('get.id');
     $workflow_model = D('Bpm/Workflow');
     $workflow = $workflow_model->where(array('id' => $workflow_id))->find();
     if (!$workflow) {
         $error = $workflow_model->getError();
         $error = $error ? $error : __(CommonModel::MSG_NOT_FOUND);
         $this->error($error);
     }
     $node_service = D('Bpm/WorkflowNode');
     // 删除原数据
     $node_service->where(['workflow_id' => $workflow_id])->save(['trashed' => 1]);
     $company_id = get_current_company_id();
     $id_map = [];
     $node_ids = [];
     foreach ($source_data as $group_value => $data) {
         $nodes = $data['widgets'];
         foreach ($nodes as $node) {
             $node_data = [];
             $node_data['label'] = $node['label'];
             $node_data['node_type'] = $node['type'];
             $node_data['action_type'] = $node['action_type'];
             switch ($node['action_type']) {
                 case "n":
                     break;
                 case "e":
                     //service api
                     $node_data['action'] = $node['service_api'];
                     break;
                 case "u":
                     // 修改源数据
                     $node_data['action'] = $node['edit_source_config'];
                     break;
             }
             // 执行者
             $node_data['executor'] = $group_value;
             $node_data['workflow_id'] = $workflow_id;
             $node_data['company_id'] = get_current_company_id();
             // 提醒
             $node_data['notify'] = $node['notify'];
             $node_data['notify_content'] = $node['notify_content'];
             $node_data['widget_id'] = $node['id'];
             $node_data['status_label'] = $node['status_label'];
             $node_data['widget_config'] = serialize($node);
             if (!$node_service->create($node_data)) {
                 return $this->error($node_service->getError());
             }
             $node_id = $node_service->add();
             /*
              * 关联本表
              * */
             $id_map[$node['id']] = ['node_id' => $node_id, 'relation' => ['prev_nodes' => $node['prev_node_ids'], 'next_nodes' => $node['next_node_ids'], 'condition_true_nodes' => $node['condition_true_ids'], 'condition_false_nodes' => $node['condition_false_ids']]];
             array_push($node_ids, $node_id);
         }
     }
     /*
      * 获取新近插入的节点
      * */
     $all_nodes = $node_service->where(array('id' => ['IN', $node_ids]))->select();
     $all_nodes_map = get_array_to_kv($all_nodes, 'id', 'widget_id');
     foreach ($id_map as $widget_id => $item) {
         $map = ['id' => $item['node_id'], 'widget_id' => $widget_id];
         $save_data = [];
         foreach ($item['relation'] as $relation_field => $relation_ids) {
             $relation_ids = array_unique($relation_ids);
             foreach ($relation_ids as $relation_id) {
                 $save_data[$relation_field][] = $all_nodes_map[$relation_id];
             }
             $save_data[$relation_field] = implode(',', $save_data[$relation_field]);
         }
         $node_service->where($map)->save($save_data);
     }
 }