ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
使用了thinkphp的数据库操作原理,用户可以使用thinkphp的数据库操作,但是针对数据库操作整体进行了封装,数据查询更加方便,所以建议用户使用专门封装的数据库操作便于整体管理。 ### 1.**数据查询** 查询单条数据 getInfo($condition, $field):$condition:表示传入条件,$field:表示查询字段 ~~~php model('help')->getInfo([ ['id', '=', $help_id], ['site_id', '=', $site_id] ], 'id, title, content, class_id, class_name, sort, link_address, create_time, modify_time'); ~~~ 查询列表getList($condition = \[\], $field = true, $order = '', $alias = 'a', $join = \[\], $group = '', $limit = null) ~~~php model('help')->getList($condition, $field, $order, '', '', '', $limit); ~~~ 查询分页列表pageList($condition = \[\], $field = true, $order = '', $page = 1, $list\_rows = PAGE\_LIST\_ROWS, $alias = 'a', $join = \[\], $group = null, $limit = null) ~~~php model('help')->pageList($condition, $field, $order, $page, $page_size); ~~~ 查询视图,按照thinkphp视图查询方法: ~~~php public function getApplyDetail($condition) { $field = 'nsa.apply_id, nsa.site_id,nsa.website_id, nsa.member_id, nsa.username, nsa.cert_id, nsa.shop_name, nsa.apply_state, nsa.apply_message, nsa.apply_year, nsa.category_name, nsa.category_id, nsa.group_name, nsa.group_id, nsa.paying_money_certificate, nsa.paying_money_certificate_explain, nsa.paying_deposit, nsa.paying_apply, nsa.paying_amount, nsa.create_time, nsa.audit_time, nsa.finish_time, nsc.cert_id, nsc.cert_type, nsc.company_name, nsc.company_province_id, nsc.company_city_id, nsc.company_district_id, nsc.company_address, nsc.contacts_name, nsc.contacts_mobile, nsc.contacts_card_no, nsc.contacts_card_electronic_1, nsc.contacts_card_electronic_2, nsc.contacts_card_electronic_3, nsc.business_licence_number, nsc.business_licence_number_electronic, nsc.business_sphere, nsc.taxpayer_id, nsc.general_taxpayer, nsc.tax_registration_certificate, nsc.tax_registration_certificate_electronic, nsc.bank_account_name, nsc.bank_account_number, nsc.bank_name, nsc.bank_address, nsc.bank_code, nsc.bank_type, nsc.settlement_bank_account_name, nsc.settlement_bank_account_number, nsc.settlement_bank_name, nsc.settlement_bank_address,nsc.company_full_address, w.site_area_name'; $alias = 'nsa'; $join = [ [ 'shop_cert nsc', 'nsa.cert_id = nsc.cert_id', 'left' ], [ 'website w', 'w.site_id = nsa.website_id', 'left' ], ]; $info = model('shop_apply')->getInfo($condition, $field, $alias, $join); return $this->success($info); } ~~~ 查询第一条数据getFirstData($condition, $order) 获取查询数据的数量getCount($condition) 获取查询字段和getSum($condition, $field) 获取查询字段最大值getMax($condition, $field) 获取查询字段最小值getMin($condition, $field) ### **2\. 数据添加** niushop数据添加使用add方法,例如: ~~~php /** * 添加帮助文章 * @param array $data */ public function addHelp($data) { $help_id = model('help')->add($data); Cache::tag("help")->clear(); return $this->success($help_id); } ~~~ ### **3\. 数据修改,使用update方法,传入修改条件** ~~~php /** * 修改帮助文章 * @param array $data */ public function editHelp($data, $condition) { $res = model('help')->update($data, $condition); Cache::tag("help")->clear(); return $this->success($res); } ~~~ ### **4\. 数据删除,使用delete方法** ~~~php /** * 删除文章 * @param unknown $coupon_type_id */ public function deleteHelp($condition) { $res = model('help')->delete($condition); Cache::tag("help")->clear(); return $this->success($res); } ~~~