private function _add() { $this->verifyForm(); $data = array(); $data['sn'] = post('sn'); $data['name'] = post('name'); $data['pinyin'] = getPinYin($data['name']); $data['contact'] = post('contact'); $data['phone'] = post('phone'); $data['address'] = post('address'); $data['memo'] = post('memo'); //$data['money'] = post('money'); $data['overdraft'] = post('overdraft'); $data['offer'] = post('offer'); $data['consume'] = post('consume'); $data['shop_id'] = post('shop_id'); $data['shop_name'] = getShop($data['shop_id']); $data['status'] = post('status'); $data['create_time'] = time(); $cus_mod = m('Customer'); $r = $cus_mod->insert($data); if ($r === false) { $this->error($cus_mod->error()); } else { $this->success('保存成功!'); } }
private function _edit() { $this->verifyForm(); $data = array(); $data['name'] = post('name'); $data['pinyin'] = getPinYin($data['name']); $data['status'] = post('status'); $shop_mod = m('Shop'); $r = $shop_mod->update($data, 'id=' . post('id')); if ($r === false) { $this->error($shop_mod->error()); } else { $shop_mod->clearCache(); $this->success('保存成功!'); } }
/** * 过滤输入、创建群联系人对象 * @param array $data 联系人信息 * @return Group_Contact $contact */ public function array_to_Group_contact($data) { $contact = new Group_Contact(); $location_model = Location_Model::instance(); $bjx_arr = Kohana::config_load('bjx'); foreach ($data as $type => $value) { switch ($type) { case 'tels': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $location_model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'ims': if (!empty($value)) { $values = $tmp = $protocols = array(); foreach ($value as $val) { $val['protocol'] = strtolower($val['protocol']); $keys = array_keys($tmp, trim($val['value'])); $key = isset($keys[0]) ? $keys[0] : -1; if ($key < 0 or $protocols[$key] != $val['protocol']) { $tmp[] = trim($val['value']); $protocols[] = $val['protocol']; $values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'addresses': if (!empty($value)) { $values = $tmp = array(); $t = ''; foreach ($value as $val) { $t = trim($val['country']) . '|' . trim($val['region']) . '|' . trim($val['city']) . '|' . trim($val['street']) . '|' . trim($val['postal']); if (!in_array($t, $tmp)) { $values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']); $tmp[] = $t; } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'emails': case 'urls': case 'events': case 'relations': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'birthday': $contactModel = Contact_Model::instance(); call_user_func(array($contact, 'set_' . $type), !empty($value) ? $contactModel->_filter_birthday($value) : ''); break; case 'id': break; default: call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : ''); break; } } $formatted_name = $this->name_to_formatted_name($data['family_name'], $data['given_name']); //拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置 if (empty($formatted_name) and !empty($data['formatted_name'])) { $name = $this->formatted_name_to_name($data['formatted_name']); $contact->set_given_name($name['given_name']); $contact->set_family_name($name['family_name']); } else { $fn = $formatted_name; } if (!empty($fn)) { require_once Kohana::find_file('vendor', 'pinyin/c2p'); $phonetic = getPinYin($fn, false, ' '); $tmp = explode(' ', $phonetic); $sort = ''; if (is_array($tmp)) { foreach ($tmp as $t) { $sort .= isset($t[0]) ? $t[0] : ''; } } $t = ord($sort[0]); if (empty($sort) or $t < 97 or $t > 122) { $sort = '#'; } $sort = substr($sort, 0, 20); $contact->set_formatted_name($fn); $contact->set_phonetic(implode('', $tmp)); $contact->set_sort($sort); } else { $contact->set_formatted_name(''); $contact->set_phonetic(''); $contact->set_sort('#'); } return $contact; }
/** * 根据姓名、姓获取姓名全拼和简拼 * @param string $formatted_name 姓名 * @param string $family_name 姓 * @return array */ function get_name_phonetic($formatted_name, $family_name) { $sort = $phonetic = ''; if ($formatted_name) { if (mb_strlen($formatted_name, 'utf-8') > 6) { $all_phonetic = getPinYin($formatted_name, FALSE, ' ', FALSE); $tmp = explode(' ', $all_phonetic); foreach ($tmp as $t) { $sort .= isset($t[0]) ? $t[0] : ''; } $t = ord($sort[0]); if (empty($sort) or $t < 97 or $t > 122) { $sort = '#'; } $phonetic = implode('', $tmp); } else { $all_phonetic = getPinYin($formatted_name, false, " ", true, "string"); if ($all_phonetic) { $tmp = explode(' ', $all_phonetic); fix_family_name($formatted_name, $family_name, $tmp); array_walk($tmp, create_function('&$val, $key', '$val = explode(",", $val);')); $combined_phonetic = combine($tmp, 0); if ($combined_phonetic) { $count = count($combined_phonetic); foreach ($combined_phonetic as $key => $pair) { if (is_array($pair)) { foreach ($pair as $t) { $sort .= isset($t[0]) ? $t[0] : ''; $phonetic .= $t; } } else { $sort .= isset($pair[0]) ? $pair[0] : ''; $phonetic .= $pair; } if ($key != $count - 1) { $sort .= ','; $phonetic .= ','; } } $t = ord($sort[0]); if (empty($sort) or $t < 97 or $t > 122) { $sort = '#'; } } } } } $sort = empty($sort) ? '#' : implode(',', array_unique(explode(',', $sort))); $phonetic = implode(',', array_unique(explode(',', $phonetic))); return array('phonetic' => $phonetic, 'sort' => $sort); }
private function _edit() { $this->verifyForm(); $data = array(); $data['card'] = post('card'); $data['name'] = post('name'); $data['pinyin'] = getPinYin($data['name']); $data['sex'] = post('sex'); $data['birth'] = post('birth'); $data['phone'] = post('phone'); $data['address'] = post('address'); $data['money'] = post('money'); $data['consume'] = post('consume'); $data['point'] = post('point'); $data['password'] = post('password'); $data['level_id'] = post('level_id'); $level = getMemberLevel($data['level_id']); $data['level_name'] = $level['name']; $data['level_discount'] = $level['discount']; $data['shop_id'] = post('shop_id'); $data['shop_name'] = getShop($data['shop_id']); $data['memo'] = post('memo'); $member_mod = m('Member'); $r = $member_mod->update($data, 'id=' . post('id')); if ($r === false) { $this->error($member_mod->error()); } else { $this->success('保存成功!'); } }