public function getData($condition = null) { if ($condition['partner_type'] == 0) { $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 . 'bpartner'), "t1.supplier_id = t6.id", array('supplier_code' => 'code', 'supplier_name' => new Zend_Db_Expr("case when t6.cname != '' then t6.cname else t6.ename end")))->joinLeft(array('t8' => $this->_dbprefix . 'product_materiel'), "t1.code = t8.code", array('t8.name', 't8.description'))->where("t1.type = " . $condition['partner_type'])->order("t1.code"); } else { $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 . 'bpartner'), "t1.supplier_id = t6.id", array('supplier_code' => 'code', 'supplier_name' => new Zend_Db_Expr("case when t6.cname != '' then t6.cname else t6.ename end")))->joinLeft(array('t8' => $this->_dbprefix . 'product_catalog'), "t1.product_code = t8.model_internal", array('product_description' => 't8.description'))->where("t1.type = " . $condition['partner_type'])->order("t1.code"); } if ($condition['supplier_id']) { $sql->where("t1.supplier_id = " . $condition['supplier_id']); } if ($condition['key']) { $sql->where("t1.code like '%" . $condition['key'] . "%' or t8.description like '%" . $condition['key'] . "%' or t1.remark like '%" . $condition['key'] . "%'"); } $total = $this->fetchAll($sql)->count(); if ($condition['type'] != 'csv') { $sql->limitPage($condition['page'], $condition['limit']); } $data = $this->fetchAll($sql)->toArray(); $ladder = new Erp_Model_Warehouse_Ladder(); 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']); $price = $this->getBestPrice($data[$i]['code'], $data[$i]['supplier_id'], $data[$i]['currency']); $data[$i]['price_best'] = $price['price']; if ($ladder->fetchAll("pricelist_id = " . $data[$i]['id'])->count() > 0) { $data[$i]['date_range'] = 1; } else { $data[$i]['date_range'] = 0; } } if ($condition['type'] == 'csv') { $data_csv = array(); $title = array('cnt' => '#', 'supplier_name' => '业务伙伴', 'code' => '物料号', 'name' => '名称', 'description' => '描述', 'price' => '固定价格', 'price_best' => '最低价格', 'currency' => '币种', 'remark' => '备注'); if ($condition['partner_type'] == 1) { $title = array('cnt' => '#', 'supplier_name' => '业务伙伴', 'code' => '产品型号', 'description' => '描述', 'price' => '固定价格', 'price_best' => '最低价格', 'currency' => '币种', 'remark' => '备注'); } array_push($data_csv, $title); $i = 0; foreach ($data as $d) { $i++; if ($condition['partner_type'] == 1) { $info = array('cnt' => $i, 'supplier_name' => $d['supplier_name'], 'code' => $d['product_code'], 'description' => $d['product_description'], 'price' => $d['price'], 'price_best' => $d['price_best'], 'currency' => $d['currency'], 'remark' => $d['remark']); } else { $info = array('cnt' => $i, 'supplier_name' => $d['supplier_name'], 'code' => $d['code'], 'name' => $d['name'], 'description' => $d['description'], 'price' => $d['price'], 'price_best' => $d['price_best'], 'currency' => $d['currency'], 'remark' => $d['remark']); } array_push($data_csv, $info); } return $data_csv; } return array('total' => $total, 'rows' => $data); }
public function editladderAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); // 价格清单ID $pricelist_id = isset($request['pricelist_id']) ? $request['pricelist_id'] : null; if ($pricelist_id) { $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; $ladder = new Erp_Model_Warehouse_Ladder(); if (count($updated) > 0) { foreach ($updated as $val) { $val->date = substr($val->date, 0, 10); $data = array('pricelist_id' => $pricelist_id, 'date' => $val->date, 'price' => $val->price, 'currency' => $val->currency, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id); if ($ladder->fetchAll("id != " . $val->id . " and pricelist_id = " . $pricelist_id . " and date = '" . $val->date . "' and price = " . $val->price)->count() > 0) { $result['success'] = false; $result['info'] = '价格清单重复,请勿重复添加!'; } else { try { $ladder->update($data, "id = " . $val->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) { $val->date = substr($val->date, 0, 10); $data = array('pricelist_id' => $pricelist_id, 'date' => $val->date, 'price' => $val->price, 'currency' => $val->currency, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id); if ($ladder->fetchAll("pricelist_id = " . $pricelist_id . " and date = '" . $val->date . "' and price = " . $val->price)->count() > 0) { $result['success'] = false; $result['info'] = '价格清单重复,请勿重复添加!'; } else { try { $ladder->insert($data); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } } if (count($deleted) > 0) { $qty = new Erp_Model_Warehouse_Ladderqty(); foreach ($deleted as $val) { try { // 删除日期起数量阶梯价 $qty->delete("ladder_id = " . $val->id); $ladder->delete("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; }