public function add() { $m_product_category = M('ProductCategory'); $data['name'] = filtStr($this->_post('name', 'trim')); $data['member_id'] = intval(session('member_id')); if ($data['name']) { if ($m_product_category->where($data)->find()) { $this->ajaxReturn(0, "类别名不可重复", 0); } elseif ($result = $m_product_category->add($data)) { $this->ajaxReturn($result, "添加类别成功", 1); } else { $this->ajaxReturn(0, "添加失败", 0); } } else { $this->ajaxReturn(0, "参数错误", 0); } }
public function edit() { if ($this->isPost() || $this->isAjax()) { $d_product = D('Product'); $m_page = M('Page'); $member_id = intval(session('member_id')); $create_time = time(); //$json_obj = filtStr($this->_post('productname', 'trim')); $json_obj = $_POST['productname']; $this->error($json_obj . "shit" . "done"); die; //TODO } else { if ($this->isPost() || $this->isAjax()) { $d_product = D('Product'); $d_video = D('Video'); $m_page = M('Page'); $member_id = intval(session('member_id')); $product['product_id'] = $this->_post('product_id', 'intval'); $product['name'] = filtStr($this->_post('name', 'trim')); $product['description'] = filtStr($this->_post('description', 'trim')); $product['image'] = $this->_post('image', 'trim'); $product['update_time'] = time(); if ($member_id != 0) { $product['member_id'] = $member_id; } $old_product = $d_product->where('product_id = %d', $product['product_id'])->find(); if (empty($old_product) || ($old_product['member_id'] ? $old_product['member_id'] != $member_id : !$_POST['verify'] || trim($_POST['verify']) != $old_product['verify'])) { if ($this->isAjax()) { $this->ajaxReturn(100, "非法操作!", 0); } else { $this->error('保存失败'); } } elseif ($old_product['status'] != 1) { if ($this->isAjax()) { $this->ajaxReturn(0, "该说明书已被停用!", 0); } else { $this->error('该说明书已被停用'); } } //开始事务 $is_failed = false; $m_page->startTrans(); if ($d_product->create($product)) { if ($d_product->save()) { //删除对应的相关页 $m_page->where(array('product_id' => $product['product_id']))->delete(); $pages = $_POST['pages']; $d_video->where('product_id = %d', $product['product_id'])->setField('product_id', 0); foreach ($pages as $v) { $page = array(); $page['product_id'] = $product['product_id']; if ($member_id != 0) { $page['member_id'] = intval(session('member_id')); } $page['subject'] = trim($v['subject']) ? filtStr(trim($v['subject'])) : '默认标题'; $content = $d_video->updateVideo($v['content'], $product['product_id']); $page['content'] = serialize($content); $page['sort_id'] = intval($v['sort_id']); //页面数据添加失败,回滚事务 if (!$m_page->add($page) || $content === false) { $is_failed = true; $m_page->rollback(); break; } } //提交事务 if (!$is_failed) { $m_page->commit(); } else { if ($this->isAjax()) { $this->ajaxReturn(0, "保存失败,部分页面数据异常", 0); } else { $this->error('保存失败,部分页面数据异常', U('product/edit', 'product_id=' . $product['product_id'] . '&verify=' . $product['verify'])); } } $jump_url = $member_id ? U('product/view', 'product_id=' . $product['product_id']) : U('product/view', 'product_id=' . $product['product_id'] . '&verify=' . $old_product['verify']); if (!session('?member_id')) { session('product_id', session('product_id') . ',' . $product['product_id']); } if ($this->isAjax()) { //$url = 'http://www.yhb360.com/recall/'.$product['product_id'].'/'.M('product')->where('product_id=%d',$product['product_id'])->getField('verify'); if (session('?member_id')) { $this->ajaxReturn(1, "保存成功", 1); } else { $this->ajaxReturn(1, "保存成功!", 2); } } else { $this->success('保存成功', $jump_url); } } else { if ($this->isAjax()) { $this->ajaxReturn(1, "保存失败," . $d_product->getError(), 1); } else { $this->success('保存失败,' . $d_product->getError()); } } } else { if ($this->isAjax()) { $this->ajaxReturn(1, "保存失败," . $d_product->getError(), 1); } else { $this->error('保存失败,' . $d_product->getError()); } } } else { $member_id = intval(session('member_id')); $product_id = intval($_GET['product_id']); if (empty($product_id)) { // 如果product id为空,则是add流程 $this->display(); } else { $m_product = M('Product'); $m_page = M('Page'); $product = $m_product->where('product_id = %d', $product_id)->find(); if (empty($product) || ($product['member_id'] ? $product['member_id'] != $member_id : !$_GET['verify'] || trim($_GET['verify']) != $product['verify'])) { if ($_GET['verify'] && $_GET['verify'] == $product['verify']) { $message = '说明书已被认领,链接失效'; } elseif ($_GET['verify']) { $message = '请确认您的编辑链接是否正确'; } elseif (empty($product)) { $message = '该产品说明书不存在'; } else { $message = '您没有权限编辑该说明书'; } $this->error($message); } else { $pages = $m_page->where('product_id = %d', intval($product['product_id']))->order('sort_id asc')->select(); foreach ($pages as $k => $v) { $pages[$k]['content'] = D('Video')->checkStatus(unserialize($v['content'])); } if (!$product['member_id'] && $product['verify']) { //$this->copylink = 'http://www.yhb360.com/recall/'.$product['product_id'].'/'.$product['verify']; $this->copylink = C('APPUSER_BASE_URL') . '/recall/' . $product['product_id'] . '/' . $product['verify']; } $islogin = session('?email') ? 1 : 0; $this->islogin = $islogin; $this->pages = $pages; $this->product = $product; $this->display(); } } } } }
public function updateinfo() { $field_name = $this->_post('name', 'trim'); $value = filtStr($this->_post('value', 'trim')); $member_id = intval(session('member_id')); if ($field_name && $member_id) { switch ($field_name) { case 'name': $field_name = 'name'; break; case 'true_name': $field_name = 'true_name'; break; case 'qq': $field_name = 'qq'; break; case 'phone_number': $field_name = 'phone_number'; break; case 'company_name': $field_name = 'company_name'; break; case 'short_name': $field_name = 'short_name'; break; case 'company_address': $field_name = 'company_address'; break; case 'company_description': $field_name = 'company_description'; break; case 'company_website': $field_name = 'company_website'; break; case 'company_salelink': $field_name = 'company_salelink'; break; default: $this->ajaxReturn(0, "非法操作", 0); break; } if (M('Member')->where('member_id = %d', $member_id)->setField($field_name, $value)) { $member = M('Member')->where('member_id = %d', $member_id)->find(); if ($field_name = 'short_name') { $member['short_name'] ? session('email', $member['short_name']) : session('email', $member['email']); } $this->ajaxReturn($value, "资料修改成功", 1); } else { $this->ajaxReturn(0, "资料修改失败", 0); } } else { $this->ajaxReturn(0, "参数错误", 0); } }
public function getVerifyCode() { $this->check_login(); $this->check_user(); $way = filtStr($_POST['way']); $target = filtStr($_POST['target']); $db = M('shop'); $where = 'uid=' . $this->user['id']; if (!$target || !$way) { $data['info'] = '填写信息不全'; $this->ajaxReturn($data); } $verifyCode = getRandStr(6); $save[$way] = $verifyCode; $msg = '您的验证码:' . $verifyCode; if ($way == 'mobile') { if (!checkIsMobile($target)) { $data['info'] = '手机号格式错误'; $this->ajaxReturn($data); } if (sendSms($msg, $target, $setting)) { $db->where($where)->save($save); $data['info'] = '验证码发送成功'; } else { $data['info'] = '验证码发送失败'; } } else { if ($way == 'email') { if (!checkIsEmail($target)) { $data['info'] = '邮箱格式错误'; $this->ajaxReturn($data); } $send_result = sp_send_email($target, "邮箱认证", $msg); if ($send_result['error']) { $data['info'] = '验证码发送失败'; } else { $data['info'] = '验证码发送成功'; } } else { $data['info'] = "非法请求"; } } M('shop')->where('uid=' . $this->user['id'])->setField($way, $verifyCode); $this->ajaxReturn($data); }