Beispiel #1
0
 public function getData($id = null)
 {
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t2.id = t1.create_user", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t3.id = t2.employee_id", array('creater' => 'cname'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t4.id = t1.update_user", array())->joinLeft(array('t5' => $this->_dbprefix . 'employee'), "t5.id = t4.employee_id", array('updater' => 'cname'))->joinLeft(array('t6' => $this->_dbprefix . 'user'), "t1.user_id = t6.id", array())->joinLeft(array('t7' => $this->_dbprefix . 'employee'), "t6.employee_id = t7.id", array('cname', 'ename', 'email'));
     if ($id) {
         $sql->where("t1.id = " . $id);
         $data = $this->fetchRow($sql)->toArray();
         return $data;
     }
     $data = $this->fetchAll($sql)->toArray();
     $work = new Erp_Model_Sale_Saleswork();
     for ($i = 0; $i < count($data); $i++) {
         $data[$i]['create_time'] = strtotime($data[$i]['create_time']);
         $data[$i]['update_time'] = strtotime($data[$i]['update_time']);
         $data[$i]['active'] = $data[$i]['active'] == 1 ? true : false;
         $data[$i]['type'] = $work->getMemberId($data[$i]['id']);
     }
     return $data;
 }
Beispiel #2
0
 public function editsalesAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '编辑成功');
     $request = $this->getRequest()->getParams();
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $json = json_decode($request['json']);
     $updated = $json->updated;
     $inserted = $json->inserted;
     $deleted = $json->deleted;
     $sales = new Erp_Model_Sale_Sales();
     $work = new Erp_Model_Sale_Saleswork();
     if (count($updated) > 0) {
         foreach ($updated as $val) {
             $data = array('active' => $val->active, 'user_id' => $val->user_id, 'tel' => $val->tel, 'fax' => $val->fax, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id);
             if ($sales->fetchAll("id != " . $val->id . " and user_id = " . $val->user_id)->count() > 0) {
                 $result['success'] = false;
                 $result['info'] = "销售员已存在,请勿重复添加!";
             } else {
                 try {
                     $sales->update($data, "id = " . $val->id);
                     $work->delete("sales_id = " . $val->id);
                     foreach ($val->type as $type_id) {
                         $work->insert(array('sales_id' => $val->id, 'type_id' => $type_id));
                     }
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
         }
     }
     if (count($inserted) > 0) {
         foreach ($inserted as $val) {
             $data = array('active' => $val->active, 'user_id' => $val->user_id, 'tel' => $val->tel, 'fax' => $val->fax, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id);
             if ($sales->fetchAll("user_id = " . $user_id)->count() > 0) {
                 $result['success'] = false;
                 $result['info'] = "销售员已存在,请勿重复添加!";
             } else {
                 try {
                     $sales_id = $sales->insert($data);
                     foreach ($val->type as $type_id) {
                         $work->insert(array('sales_id' => $sales_id, 'type_id' => $type_id));
                     }
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
         }
     }
     if (count($deleted) > 0) {
         foreach ($deleted as $val) {
             try {
                 $sales->delete("id = " . $val->id);
                 $work->delete("sales_id = " . $val->id);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }