public function store_edit() { $database_merchant_store = D('Merchant_store'); if (IS_POST) { if (empty($_POST['name'])) { $this->error('店铺名称必填!'); } if (empty($_POST['phone'])) { $this->error('联系电话必填!'); } if (empty($_POST['long_lat'])) { $this->error('店铺经纬度必填!'); } if (empty($_POST['adress'])) { $this->error('店铺地址必填!'); } if (empty($_POST['pic'])) { $this->error('请至少上传一张图片'); } $_POST['pic_info'] = implode(';', $_POST['pic']); if (empty($_POST['txt_info'])) { $this->error('请输入店铺描述信息'); } $keywords = trim($_POST['keywords']); if (!empty($keywords)) { $tmp_key_arr = explode(' ', $keywords); $key_arr = array(); foreach ($tmp_key_arr as $value) { if (!empty($value)) { array_push($key_arr, $value); } } if (5 < count($key_arr)) { $this->error('关键词最多5个。'); } } $office_time = array(); if ($_POST['office_start_time'] != '00:00' || $_POST['office_stop_time'] != '00:00') { array_push($office_time, array('open' => $_POST['office_start_time'], 'close' => $_POST['office_stop_time'])); } if ($_POST['office_start_time2'] != '00:00' || $_POST['office_stop_time2'] != '00:00') { array_push($office_time, array('open' => $_POST['office_start_time2'], 'close' => $_POST['office_stop_time2'])); } if ($_POST['office_start_time3'] != '00:00' || $_POST['office_stop_time3'] != '00:00') { array_push($office_time, array('open' => $_POST['office_start_time3'], 'close' => $_POST['office_stop_time3'])); } $_POST['office_time'] = serialize($office_time); $_POST['sort'] = intval($_POST['sort']); $long_lat = explode(',', $_POST['long_lat']); $_POST['long'] = $long_lat[0]; $_POST['lat'] = $long_lat[1]; $_POST['last_time'] = $_SERVER['REQUEST_TIME']; $condition_merchant_store['store_id'] = $_POST['store_id']; $condition_merchant_store['mer_id'] = $this->merchant_session['mer_id']; unset($_POST['store_id']); if ($database_merchant_store->where($condition_merchant_store)->data($_POST)->save()) { $data_keywords['third_id'] = $condition_merchant_store['store_id']; $data_keywords['third_type'] = 'Merchant_store'; $database_keywords = D('Keywords'); $database_keywords->where($data_keywords)->delete(); if (!empty($key_arr)) { foreach ($key_arr as $value) { $data_keywords['keyword'] = $value; $database_keywords->data($data_keywords)->add(); } } $this->success('保存成功!'); } else { $this->error('保存失败!!您是不是没做过修改?请重试~'); } } else { $condition_merchant_store['store_id'] = $_GET['id']; $condition_merchant_store['mer_id'] = $this->merchant_session['mer_id']; $now_store = $database_merchant_store->where($condition_merchant_store)->find(); if (empty($now_store)) { $this->error('店铺不存在!'); } $now_store['office_time'] = unserialize($now_store['office_time']); if (!empty($now_store['pic_info'])) { $store_image_class = new store_image(); $tmp_pic_arr = explode(';', $now_store['pic_info']); foreach ($tmp_pic_arr as $key => $value) { $now_store['pic'][$key]['title'] = $value; $now_store['pic'][$key]['url'] = $store_image_class->get_image_by_path($value); } } $keywords = D('Keywords')->where(array('third_type' => 'Merchant_store', 'third_id' => $condition_merchant_store['store_id']))->select(); $str = ''; foreach ($keywords as $key) { $str .= $key['keyword'] . ' '; } $now_store['keywords'] = $str; $this->assign('now_store', $now_store); $this->display(); } }