Exemplo n.º 1
0
 public function edit()
 {
     $leads_id = $_POST['leads_id'] ? intval($_POST['leads_id']) : intval($_REQUEST['id']);
     if (!check_permission($leads_id, 'leads')) {
         $this->error(L('HAVE NOT PRIVILEGES'));
     }
     $field_list = M('Fields')->where('model = "leads"')->order('order_id')->select();
     if ($this->isPost()) {
         $m_leads = M('Leads');
         $m_leads_data = M('LeadsData');
         foreach ($field_list as $v) {
             switch ($v['form_type']) {
                 case 'address':
                     $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     break;
                 case 'datetime':
                     $_POST[$v['field']] = strtotime($_POST[$v['field']]);
                     break;
                 case 'box':
                     eval('$field_type = ' . $v['setting'] . ';');
                     if ($field_type['type'] == 'checkbox') {
                         $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     }
                     break;
             }
         }
         if ($m_leads->create()) {
             if ($m_leads_data->create() !== false) {
                 $m_leads->update_time = time();
                 $a = $m_leads->where('leads_id= %d', $_REQUEST['leads_id'])->save();
                 $b = $m_leads_data->where('leads_id=%d', $_REQUEST['leads_id'])->save();
                 if ($a && $b !== false) {
                     actionLog($_REQUEST['leads_id']);
                     alert('success', L('LEADS_MODIFIED_SUCCESSFULLY'), U('leads/index'));
                 } else {
                     alert('error', L('LEADS_MODIFIED_FAILED'), $_SERVER['HTTP_REFERER']);
                 }
             } else {
                 $this->error($m_leads_data->getError());
             }
         } else {
             $this->error($m_leads->getError());
         }
     } elseif ($_REQUEST['id']) {
         $d_v_leads = D('LeadsView')->where('leads.leads_id = %d', $this->_request('id'))->find();
         $d_v_leads['owner'] = D('RoleView')->where('role.role_id = %d', $d_v_leads['owner_role_id'])->find();
         if (!$d_v_leads) {
             alert('error', L('LEADS_DOES_NOT_EXIST'), $_SERVER['HTTP_REFERER']);
             die;
         }
         $field_list = field_list_html("edit", "leads", $d_v_leads);
         $this->field_list = $field_list;
         $this->leads = $d_v_leads;
         $this->alert = parseAlert();
         $this->display();
     } else {
         alert('error', L('INVALIDATE_PARAM'), $_SERVER['HTTP_REFERER']);
     }
 }
Exemplo n.º 2
0
 public function add()
 {
     if ($this->isPost()) {
         $m_product = D('Product');
         $m_product_data = D('ProductData');
         if (!isset($_POST['name']) || $_POST['name'] == '') {
             $this->error(L('PRODUCT_NAME_CANNOT_BE_EMPTY'));
         } elseif ($m_product->where('name = "%s"', trim($_POST['name']))->find()) {
             alert('error', L('THE_EXISTING_PRODUCT_OPPORTUNITIES'), $_SERVER['HTTP_REFERER']);
         }
         $field_list = M('Fields')->where('model = "product" and in_add = 1')->order('order_id')->select();
         foreach ($field_list as $v) {
             switch ($v['form_type']) {
                 case 'address':
                     $a = array_filter($_POST[$v['field']]);
                     $_POST[$v['field']] = !empty($a) ? implode(chr(10), $a) : '';
                     break;
                 case 'datetime':
                     $_POST[$v['field']] = strtotime($_POST[$v['field']]);
                     break;
                 case 'box':
                     eval('$field_type = ' . $v['setting'] . ';');
                     if ($field_type['type'] == 'checkbox') {
                         $b = array_filter($_POST[$v['field']]);
                         $_POST[$v['field']] = !empty($b) ? implode(chr(10), $b) : '';
                     }
                     break;
             }
         }
         if ($m_product->create()) {
             if ($m_product_data->create() !== false) {
                 $m_product->creator_role_id = session('role_id');
                 $m_product->create_time = time();
                 $m_product->update_time = time();
                 if ($product_id = $m_product->add()) {
                     $m_product_data->product_id = $product_id;
                     actionLog($product_id);
                     if ($m_product_data->add()) {
                         //上传产品主图和副图至服务器
                         if (array_sum($_FILES['main_pic']['size'])) {
                             //如果有文件上传 上传附件
                             import('@.ORG.UploadFile');
                             //导入上传类
                             $upload = new UploadFile();
                             //设置上传文件大小
                             $upload->maxSize = 20000000;
                             //设置附件上传目录
                             $dirname = UPLOAD_PATH . date('Ym', time()) . '/' . date('d', time()) . '/';
                             $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
                             // 设置附件上传类型
                             if (!is_dir($dirname) && !mkdir($dirname, 0777, true)) {
                                 $this->error(L('ATTACHMENTS TO UPLOAD DIRECTORY CANNOT WRITE'));
                             }
                             $upload->savePath = $dirname;
                             if (!$upload->upload()) {
                                 // 上传错误提示错误信息
                                 alert('error', $upload->getErrorMsg(), $_SERVER['HTTP_REFERER']);
                             } else {
                                 // 上传成功 获取上传文件信息
                                 $info = $upload->getUploadFileInfo();
                                 //写入数据库
                                 $m_product_images = M('productImages');
                                 foreach ($info as $iv) {
                                     if ($iv['key'] == 'main_pic') {
                                         //主图
                                         $img_data['is_main'] = 1;
                                     } else {
                                         //副图
                                         $img_data['is_main'] = 0;
                                     }
                                     $img_data['product_id'] = $product_id;
                                     $img_data['name'] = $iv['name'];
                                     $img_data['save_name'] = $iv['savename'];
                                     $img_data['size'] = sprintf("%.2f", $iv['size'] / 1024);
                                     $img_data['path'] = $iv['savepath'] . $iv['savename'];
                                     $img_data['create_time'] = time();
                                     $img_data['listorder'] = intval($m_product_images->max('listorder')) + 1;
                                     $m_product_images->add($img_data);
                                 }
                             }
                         }
                         if ($_POST['submit'] == L('SAVE')) {
                             alert('success', L('PRODUCT_ADDED_SUCCESSFULLY'), U('product/index'));
                         } else {
                             alert('success', L('PRODUCT_ADDED_SUCCESSFULLY'), U('product/add'));
                         }
                     } else {
                         alert('error', $m_product_data->getError());
                         $this->alert = parseAlert();
                         $this->error();
                     }
                 } else {
                     alert('error', $m_product->getError());
                     $this->alert = parseAlert();
                     $this->error();
                 }
             } else {
                 $this->error($m_product_data->getError());
             }
         } else {
             $this->error($m_product->getError());
         }
     } else {
         $field_list = field_list_html("add", "product");
     }
     $this->field_list = $field_list;
     $this->alert = parseAlert();
     $this->display();
 }
 /**
  *修改商机
  *
  **/
 public function edit()
 {
     $v_business = D('BusinessView');
     $business = $v_business->where('business.business_id = %d', $this->_request('id'))->find();
     if (!$business) {
         alert('error', L('THERE_IS_NO_BUSINESS_OPPORTUNITIES'), $_SERVER['HTTP_REFERER']);
     }
     $field_list = M('Fields')->where('model = "business"')->order('order_id')->select();
     $business_id = $_POST['business_id'] ? intval($_POST['business_id']) : intval($_GET['id']);
     if (!check_permission($business_id, 'business')) {
         $this->error(L('HAVE NOT PRIVILEGES'));
     }
     if ($this->isPost()) {
         $m_business = D('business');
         $m_business_data = D('BusinessData');
         foreach ($field_list as $v) {
             switch ($v['form_type']) {
                 case 'address':
                     $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     break;
                 case 'datetime':
                     $_POST[$v['field']] = strtotime($_POST[$v['field']]);
                     break;
                 case 'box':
                     eval('$field_type = ' . $v['setting'] . ';');
                     if ($field_type['type'] == 'checkbox') {
                         $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     }
                     break;
             }
         }
         if (empty($_POST['customer_id'])) {
             $this->error(L('THE_CUSTOMER_CANNOT_BE_EMPTY'));
         }
         if ($m_business->create()) {
             if ($m_business_data->create() !== false) {
                 $m_business->update_time = time();
                 $r = M('rBusinessProduct');
                 foreach ($_POST['product'] as $val) {
                     $data = array();
                     $data['product_id'] = $val['product_id'];
                     $data['unit_price'] = $val['unit_price'];
                     $data['amount'] = $val['amount'];
                     $data['discount_rate'] = $val['discount_rate'];
                     $data['tax_rate'] = $val['tax_rate'];
                     $data['subtotal'] = $val['subtotal'];
                     $data['subtotal_val'] = $_POST['subtotal_val'];
                     $data['discount_price'] = $_POST['discount_price'];
                     $data['sales_price'] = $_POST['sales_price'];
                     $data['description'] = $val['description'];
                     $data['business_id'] = $business_id;
                     //在编辑时,如果又添加商品,根据是否存在sales_product_id来进行编辑或添加
                     if (empty($val['r_id'])) {
                         //添加
                         $result_product = $r->add($data);
                         if (empty($result_product)) {
                             $res = false;
                             break;
                         }
                     } else {
                         //编辑
                         $result_product = $r->where('id = %d', $val['r_id'])->save($data);
                         if ($result_product === false) {
                             $res = false;
                             break;
                         }
                     }
                     //在编辑时,如果从原来的商品中去除一条信息,则删除该产品
                     if ($val['r_id'] && empty($val['product_id'])) {
                         $result_product = $r->where('id = %d', $val['r_id'])->delete();
                         if ($result_product == 0 || $result_product === false) {
                             $res = false;
                         }
                     }
                 }
                 $a = $m_business->where('business_id=' . $business['business_id'])->save();
                 $b = $m_business_data->where('business_id=' . $business['business_id'])->save();
                 if ($a && $b !== false) {
                     if (intval($_POST['status_id']) == 100) {
                         M('Customer')->where('customer_id = %d', intval($_POST['customer_id']))->setField('is_locked', 1);
                     }
                     actionLog($business['business_id']);
                     alert('success', L('MODIFY_BUSINESS_INFORMATION_SUCCESSFULLY'), U('business/index'));
                 } else {
                     alert('error', L('MODIFY_THE_BUSINESS_INFORMATION_FAILURE'), $_SERVER['HTTP_REFERER']);
                 }
             } else {
                 $this->error($m_business_data->getError());
             }
         } else {
             $this->error($m_business->getError());
         }
     } else {
         $business['owner'] = getUserByRoleId($business['owner_role_id']);
         $business['product'] = M('rBusinessProduct')->where('business_id = %d', $business_id)->select();
         $product_count = M('rBusinessProduct')->where('business_id = %d', $business_id)->count();
         $business['product_count'] = empty($product_count) ? 0 : $product_count;
         $product_category = M('product_category');
         foreach ($business['product'] as $k => $v) {
             $info = M('product')->where('product_id = %d', $v['product_id'])->find();
             $business['product'][$k]['info'] = $info;
             $total_amount += $v['amount'];
         }
         $this->business = $business;
         $this->total_amount = $total_amount;
         $alert = parseAlert();
         $this->alert = $alert;
         $this->field_list = field_list_html('edit', 'business', $business);
         $this->display();
     }
 }
 public function edit()
 {
     if (!check_permission(intval($this->_request('id')), 'customer')) {
         $this->error(L('HAVE NOT PRIVILEGES'));
     }
     $customer = D('CustomerView')->where('customer.customer_id = %d', $this->_request('id'))->find();
     if (!$customer) {
         alert('error', L('CUSTOMER_DOES_NOT_EXIST!'), $_SERVER['HTTP_REFERER']);
     }
     $customer['owner'] = D('RoleView')->where('role.role_id = %d', $customer['owner_role_id'])->find();
     $customer['contacts_name'] = M('contacts')->where('contacts_id = %d', $customer['contacts_id'])->getField('name');
     $field_list = M('Fields')->where('model = "customer"')->order('order_id')->select();
     if ($this->isPost()) {
         $m_customer = D('Customer');
         $m_customer_data = D('CustomerData');
         foreach ($field_list as $v) {
             switch ($v['form_type']) {
                 case 'address':
                     $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     break;
                 case 'datetime':
                     $_POST[$v['field']] = strtotime($_POST[$v['field']]);
                     break;
                 case 'box':
                     eval('$field_type = ' . $v['setting'] . ';');
                     if ($field_type['type'] == 'checkbox') {
                         $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]);
                     }
                     break;
             }
         }
         if ($m_customer->create()) {
             if ($m_customer_data->create() !== false) {
                 $m_customer->update_time = time();
                 $a = $m_customer->where('customer_id =%s ', $customer['customer_id'])->save();
                 $b = $m_customer_data->where('customer_id =%s', $customer['customer_id'])->save();
                 if ($a !== false && $b !== false) {
                     if ($_POST['contacts_id'] && $_POST['contacts_id'] != $customer['contacts_id']) {
                         $rcc['contacts_id'] = intval($_POST['contacts_id']);
                         $rcc['customer_id'] = $customer['customer_id'];
                         if (!M('RContactsCustomer')->where($rcc)->find()) {
                             M('RContactsCustomer')->add($rcc);
                         }
                     }
                     actionLog($customer['customer_id']);
                     alert('success', L('EDIT_CLIENTS_SUCCESS'), U('customer/index'));
                 } else {
                     alert('error', L('CUSTOMER_EDITING_FAILED!'), $_SERVER['HTTP_REFERER']);
                 }
             } else {
                 $this->error($m_customer_data->getError());
             }
         } else {
             $this->error($m_customer->getError());
         }
     } else {
         $alert = parseAlert();
         $this->alert = $alert;
         $this->customer = $customer;
         $this->field_list = field_list_html("edit", "customer", $customer);
         $this->display();
     }
 }