protected function _after_insert($id)
 {
     // 线索、客户、商机等上次联系时间,更新
     if (I('post.crm_clue_id')) {
         // 线索
         $related_id = I('post.crm_clue_id');
         $model = "Crm/CrmClue";
     } else {
         if (I('post.customer_id')) {
             // 客户
             $related_id = I('post.customer_id');
             $model = "Crm/Customer";
         }
     }
     if ($model && $id) {
         D($model)->where(array('id' => $id, 'company_id' => get_current_company_id()))->save(array('last_contact_time' => date('Y-m-d H:i:s')));
     }
     if (I('post.next_contact_time') && I('post.next_contact_content') && $related_id) {
         // 更新日程
         if (AppService::is_app_active('calendar')) {
             $event_service = D('Calendar/Events');
             $event_service->create(['subject' => I('post.next_contact_content'), 'type' => 'info', 'start_at' => I('post.next_contact_time'), 'end_at' => I('post.next_contact_time'), 'related_model' => $this->module_alias, 'related_id' => $related_id]);
             $event_service->add();
         }
     }
 }
 public function assign_to_by_product_unique($rows)
 {
     if (!AppService::is_app_active('productAttribute')) {
         return [];
     }
     $attr_content_ids = [];
     foreach ($rows as $k => $row) {
         $unique_id = $row['product_unique_id'];
         if (!$unique_id) {
             continue;
         }
         $tmp = explode('|', $unique_id);
         $rows[$k]['attribute_content_ids'] = [];
         foreach ($tmp as $attr) {
             list($attr_id, $attr_content_id) = explode('_', $attr);
             array_push($attr_content_ids, $attr_content_id);
             array_push($rows[$k]['attribute_content_ids'], $attr_content_id);
         }
     }
     if (!$attr_content_ids) {
         return $rows;
     }
     $attribute_contents = D('ProductAttribute/ProductAttributeContent', 'Model')->where(['id' => ['IN', $attr_content_ids]])->select();
     $attribute_contents = get_array_to_ka($attribute_contents, 'id');
     foreach ($rows as $k => $row) {
         foreach ($row['attribute_content_ids'] as $ac_id) {
             if (array_key_exists($ac_id, $attribute_contents)) {
                 $attribute_field = $attribute_contents[$ac_id]['alias'];
                 $attribute_value = $attribute_contents[$ac_id]['content'];
                 $rows[$k][$attribute_field] = $attribute_value;
             }
         }
     }
     return $rows;
 }
Esempio n. 3
0
 public function convert_to_stock_in($id)
 {
     if (!AppService::is_app_active('storage')) {
         $this->error = sprintf(__('common.Need %s App Active'), 'storage');
         return false;
     }
     $meta_fields = ['quantity', 'subject', 'bill_no', 'remark'];
     $meta = [];
     $raw_main_data = $this->where(['id' => $id])->find();
     foreach ($raw_main_data as $field => $value) {
         if (in_array($field, $meta_fields)) {
             $meta[$field] = $value;
         }
     }
     $meta['subject'] = __('purchase.Purchase stock in') . ' ' . $meta['subject'];
     $meta['source_model'] = 'purchase.purchase';
     $meta['source_id'] = $id;
     $meta['workflow_id'] = DBC('purchase_stock_in_workflow');
     $row_model = D('Purchase/PurchaseDetail');
     $raw_rows_data = $row_model->where(['purchase_id' => $id])->select();
     $stock_in_service = D('Storage/StockIn');
     $stock_in_id = $stock_in_service->add_bill($meta, $raw_rows_data);
     if (!$stock_in_id) {
         $this->error = $stock_in_service->getError();
         return false;
     }
     return $stock_in_id;
 }
Esempio n. 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);
 }
Esempio n. 5
0
 public function get_quantity_by_product($row_data)
 {
     $quantity_balance = 0;
     if ($row_data['product_unique_id']) {
         $product_unique_id = $row_data['product_unique_id'];
     } else {
         if (AppService::is_app_active('productAttribute')) {
             $attribute_fields = D('ProductAttribute/ProductAttribute')->get_attribute_fields();
             $product_unique_id = generate_product_unique_id($row_data, $attribute_fields);
         } else {
             if ($row_data['product_id']) {
                 $product_unique_id = $row_data['product_id'];
             }
         }
     }
     if (!$product_unique_id) {
         return $quantity_balance;
     }
     $map = ['product_unique_id' => $product_unique_id];
     // 指定仓库
     if ($row_data['storage_id']) {
         $map['storage_id'] = $row_data['storage_id'];
     }
     $raw_data = $this->where($map)->select();
     foreach ($raw_data as $v) {
         $quantity_balance += $v['balance'];
     }
     return round((string) $quantity_balance, DBC('decimal_scale'));
 }
Esempio n. 6
0
 public function get_main_include()
 {
     $main_include = [];
     foreach (AppService::$allAppConfigs as $app => $app_config) {
         if (!AppService::is_app_active($app)) {
             continue;
         }
         $main_include = array_merge_recursive($main_include, (array) $app_config['main_include']);
     }
     return $main_include;
 }
Esempio n. 7
0
 public function on_list()
 {
     $data = parent::on_list(true);
     $list = $data[1];
     $product_ids = get_array_by_field($list, 'product_id');
     $map = ['product_id' => ['IN', $product_ids]];
     $total_balance = D('Storage/Stock')->field('SUM(balance) as total_balance, product_id, product_unique_id')->where($map)->group('product_unique_id')->select();
     $total_balance = get_array_to_ka($total_balance, 'product_unique_id');
     foreach ($list as $k => $v) {
         if (array_key_exists($v['product_unique_id'], $total_balance)) {
             $list[$k]['total_balance'] = $total_balance[$v['product_unique_id']]['total_balance'];
         }
     }
     // 产品属性
     if (AppService::is_app_active('productAttribute')) {
         $list = D('ProductAttribute/ProductAttribute')->assign_to($list);
     }
     $data[1] = reIndex($list);
     $this->response($data, 'stock', true);
 }
Esempio n. 8
0
 public function get_full_data($id)
 {
     if (!$this->check_params()) {
         $this->error = __('common.System Error');
         return false;
     }
     $meta = D($this->main_model, 'Model')->where(['id' => $id])->find();
     if (!$meta) {
         // @todo error_message
         return false;
     }
     if ($this->is_locked($meta['status'])) {
         $meta['locked'] = true;
     }
     $meta = Schema::data_format($meta, $this->main_table, true);
     $detail_model = D($this->detail_model, 'Model');
     $rows = $detail_model->where([$this->detail_main_foreign => $id])->select();
     // 本次出入库数量
     if ($this->include_this_time_quantity && $this->balance_direction) {
         foreach ($rows as $k => $v) {
             $this_time_quantity_field = sprintf('this_time_%s_quantity', $this->balance_direction);
             $rows[$k][$this_time_quantity_field] = round($v['quantity'] - $v['already_' . $this->balance_direction], DBC('decimal_scale'));
         }
     }
     $rows = Schema::data_format($rows, $this->detail_table, true);
     // 工作流进程
     $progress_service = D('Bpm/WorkflowProgress');
     $meta['workflow_progress'] = $progress_service->get_progress($meta['workflow_id'], $meta['id']);
     // 产品属性
     if (AppService::is_app_active('productAttribute')) {
         $rows = D('ProductAttribute/ProductAttribute')->assign_to_by_product_unique($rows, $this->detail_model_alias);
     }
     return ['meta' => $meta, 'rows' => $rows];
 }
Esempio n. 9
0
 public function __construct()
 {
     //支持方法
     if (!$this->allowMethod) {
         $this->allowMethod = explode(",", strtolower(SUPPORTED_METHOD));
     }
     //session token
     if (I('server.HTTP_TOKEN')) {
         session(array('id' => I("server.HTTP_TOKEN"), 'expire' => 1800));
         session('[start]');
         $this->user = I("session.user");
         $this->is_super_user = $this->user['is_super_user'];
         if (isset($_SESSION['user']) && (!get_current_company_id() || !get_current_user_id())) {
             return $this->login_required();
         }
     }
     tag('before_controller_construct');
     parent::__construct();
     // 当前请求 =》 auth_node
     $this->current_action_all = sprintf("%s.%s.%s.%s", lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME), lcfirst(ACTION_NAME), $this->_method);
     //当前用户所属公司
     if ($this->user or true) {
         $this->company = D("Account/Company")->relation(true)->find(get_current_company_id());
     }
     //当前公司启用应用
     $this->activeApps = $this->baseApps;
     if ($this->company) {
         $this->activeApps = array_merge($this->activeApps, get_array_by_field($this->company['apps'], "alias"));
     }
     //启用应用
     AppService::active($this->activeApps, $this->baseApps);
     //当前模块前端别名
     $this->module_alias = __(sprintf('%s.%s', lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME)));
     //导入非当前应用的插件及函数等信息
     foreach ($this->activeApps as $app) {
         $app = ucfirst($app);
         if ($app == APP_NAME or $app == "common") {
             continue;
         }
         // 插件
         if (is_file(APPLICATION_PATH . $app . '/Conf/tags.php')) {
             \Think\Hook::import(require APPLICATION_PATH . $app . '/Conf/tags.php');
         }
         // 函数
         if (is_file(APPLICATION_PATH . $app . '/Common/function.php')) {
             require_once APPLICATION_PATH . $app . '/Common/function.php';
         }
     }
     //基本运行配置
     $this->bootstrapConfigs = parse_yml(ENTRY_PATH . '/config.yaml');
     //当前接口版本
     if (I('server.HTTP_API_VERSION')) {
         define('API_VERSION', I('server.HTTP_API_VERSION'));
     } else {
         define('API_VERSION', false);
     }
     //当前语言
     $this->currentLanguage = $this->bootstrapConfigs["default_language"] ? $this->bootstrapConfigs["default_language"] : 'zh-cn';
     if (I("server.HTTP_CLIENT_LANGUAGE")) {
         $this->currentLanguage = I("server.HTTP_CLIENT_LANGUAGE");
     }
     if (I('get.lang')) {
         $this->currentLanguage = I('get.lang');
     }
     define('CURRENT_LANGUAGE', $this->currentLanguage);
     /*
      * 解析应用配置
      * * */
     $cachedAppConfig = S("configs/app/all");
     if (DEBUG or !$cachedAppConfig) {
         foreach (new RecursiveFileFilterIterator(APP_PATH, "config.yml") as $item) {
             $app = lcfirst(basename(dirname($item)));
             $this->appConfigs[$app] = parse_yml($item);
         }
         S("configs/app/all", $this->appConfigs);
     } else {
         if (!DEBUG && $cachedAppConfig) {
             $this->appConfigs = $cachedAppConfig;
         }
     }
     AppService::$allAppConfigs = $this->appConfigs;
     foreach ($this->appConfigs as $app => $config) {
         $this->bootstrapConfigs['auth_dont_need_login'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_login'], (array) $config['auth_dont_need_login']);
         $this->bootstrapConfigs['auth_dont_need_check'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_check'], (array) $config['auth_dont_need_check']);
     }
     // 当前表名
     if (!$this->model_name) {
         $this->model_name = ucfirst(CONTROLLER_NAME);
     }
     // 获得用户已授权节点
     $authed_nodes = session('authed_nodes');
     if (DEBUG || !$authed_nodes) {
         $authed_nodes = D('Account/Authorize')->get_authed_nodes();
         session('authed_nodes', $authed_nodes);
     }
     self::$authed_nodes = $authed_nodes;
     AuthorizeService::set_authed_nodes($authed_nodes);
     //当前动作权限检测
     // @todo event, event_get
     $current_node_auth_flag = DEBUG ? 1 : $this->check_permission();
     if (substr($this->_method, 0, 5) !== 'event' && false === $current_node_auth_flag) {
         $node_lang = __(lcfirst(MODULE_NAME) . '.METHODS.' . $this->_method) . ' ' . __(lcfirst(MODULE_NAME) . '.' . ucfirst(CONTROLLER_NAME));
         return $this->httpError(403, __("common.Permission Denied") . ": " . $node_lang . "({$this->current_action_all})");
     }
     $this->current_node_auth_flag = (int) $current_node_auth_flag;
     tag('after_controller_construct');
 }
Esempio n. 10
0
 public function get_full_data($id)
 {
     if (!$this->check_params()) {
         $this->error = __('common.System Error');
         return false;
     }
     $meta = D($this->main_model, 'Model')->where(['id' => $id])->find();
     if (!$meta) {
         // @todo error_message
         return false;
     }
     if ($this->is_locked($meta['status'])) {
         $meta['locked'] = true;
     }
     $meta = Schema::data_format($meta, $this->main_table, true);
     $detail_model = D($this->detail_model, 'Model');
     $rows = $detail_model->where([$this->detail_main_foreign => $id])->select();
     $rows = Schema::data_format($rows, $this->detail_table, true);
     // 工作流进程
     $progress_service = D('Bpm/WorkflowProgress');
     $meta['workflow_progress'] = $progress_service->get_progress($meta['workflow_id'], $meta['id']);
     // 产品属性
     if (AppService::is_app_active('productAttribute')) {
         $rows = D('ProductAttribute/ProductAttribute')->assign_to($rows, $this->detail_model_alias);
     }
     return ['meta' => $meta, 'rows' => $rows];
 }