ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 案例介绍 - 客户信息维护 本案例基于框架代码,开发并维护OA系统的客户信息 案例代码下载地址: 链接:https://pan.baidu.com/s/1NYUJdmrIJ5X6NzWXC4BHvw 提取码:m63e ## 案例效果 ![](https://img.kancloud.cn/3c/de/3cdea7a9e41076086fe5bfdbbefc0788_1627x760.png) ![](https://img.kancloud.cn/08/bc/08bc8d08b3a1244d8af21a8c3d85baa8_1502x735.png) ## 开发过程 ### 1. 创建C层控制器方法 首先在 controller 文件夹内创建 customer文件目录以及customer.php 文件 ![](https://img.kancloud.cn/34/5b/345b7d94a2d11da4974cbd00be4e4c01_1444x553.png) 同时在customer.php 编写或集成C层基类方法,参考代码如下: ~~~ <?php /** * 客户控制层类 */ class controller_customer_customer_customer extends controller_base_action { public $provArr; function __construct() { $this->objName = "customer"; $this->objPath = "customer_customer"; parent::__construct (); } /** * 跳转到客户信息列表 */ function c_page() { $this->view ( 'list' ); } /** * * 选择客户 */ function c_selectCustomers() { $this->assign ( 'showButton', $_GET ['showButton'] ); $this->assign ( 'showcheckbox', $_GET ['showcheckbox'] ); $this->assign ( 'checkIds', $_GET ['checkIds'] ); $this->view ( 'select' ); } /** * 客户可编辑表格测试 */ function c_editlist() { $this->view ( 'edit-list' ); } /** * 跳转到新增页面 */ function c_toAdd() { $this->showDatadicts ( array ('TypeOne' => 'KHLX' ) ); //客户类型数据字典 $this->assign ( 'createName', $_SESSION ['USERNAME'] ); $this->assign ( 'createNameId', $_SESSION ['USER_ID'] ); $this->assign ( 'CreateDT', date("Y-m-d") ); $this->provArr = $this->service->province_d (); $this->softSelect ( $this->service->province_d (), 'Prov' ); $this->view ( 'add' ); } /** * 新增对象操作 */ function c_add($isAddInfo = false) { $customer = $_POST [$this->objName]; $codeDao = new model_common_codeRule (); $customer ['objectCode'] = $codeDao->customerCode ( "customer", $customer ['TypeOne'], $customer ['CountryId'], $customer ['CityId'] ); $id = $this->service->add_d ( $customer, $isAddInfo ); $customer ['id'] = $id; if ($id) { echo "<script>window.returnValue='" . util_jsonUtil::encode ( $customer ) . "';</script>"; msg ( '添加成功!' ); } //$this->listDataDict(); } /** * 跳转编辑页面 */ function c_init() { $id = $_GET ['id']; $rows = $this->service->get_d ( $id ); foreach ( $rows as $key => $val ) { $this->assign ( $key, $val ); } $this->showDatadicts ( array ('TypeOne' => 'KHLX' ), $rows ['TypeOne'] ); $this->softSelect ( $this->provArr, 'Prov', $rows ['Prov'] ); try { $isRelated = $this->service->isCustomerRelated ( $id ); } catch ( Exception $e ) { $isRelated = true; } $this->assign ( "isRelated", $isRelated ); $this->assign ( "UpdateDT", date("Y-m-d") ); $this->display ( 'edit' ); } } ?> ~~~ ### 2. 创建V层页面 在view/template 文件夹内,创建customer文件目录以及相关的页面文件和js文件 ![](https://img.kancloud.cn/34/16/34165e50c78e272abe8f96122e13fd91_410x701.png)![](https://img.kancloud.cn/34/16/34165e50c78e272abe8f96122e13fd91_410x701.png) 注意: 1. 页面文件路径需要与C层文件路径相同 2. 页面文件规则为 类名-模板名,如新增页面 customer-add.htm ### 3. 创建M层文件,完成基础数据操作 在model内建立和C层文件通用的customer文件目录,并创建两个model需要的文件 1. customer.php //model基础文件 2. customerSql.php //数据库配置文件 ![](https://img.kancloud.cn/7c/9f/7c9feaf4fb67f1b08b66086d503d3cae_343x495.png) 参考代码如下: ~~~ <?php /** * 客户model层类 */ class model_customer_customer_customer extends model_base { function __construct() { $this->tbl_name = "customer"; $this->sql_map = "customer/customer/customerSql.php"; parent::__construct (); } /**** * 读取省份信息方法 * **/ function province_d() { $provice = new model_system_procity_province (); $proviceShow = $provice->findAll (); return $proviceShow; } /** * 修改客户信息 */ function edit_d($object) { try { $this->start_d (); $sconfig = new model_common_securityUtil ("customer"); $key=$sconfig->md5Row($object); $object['skey_']=$key; // util_messageUtil::sendMessageByObjCode("customerUpdate",$object); parent::edit_d($object,true); $this->commit_d (); return true; } catch ( Exception $e ) { $this->rollBack (); return false; } } } ?> ~~~