当前位置: 首页 > 工具软件 > Niushop > 使用案例 >

Niushop开源商城数据操作

阳兴朝
2023-12-01

niushop使用了thinkphp的数据库操作原理,用户可以使用thinkphp的数据库操作,但是niushop针对数据库操作整体进行了封装,数据查询更加方便,所以建议用户使用niushop专门封装的数据库操作便于整体管理。

  1. 数据查询
    查询单条数据 getInfo($condition, f i e l d ) : field): field):condition:表示传入条件,$field:表示查询字段

model(‘help’)->getInfo([ [‘id’, ‘=’, $help_id], [‘site_id’, ‘=’, s i t e i d ] ] , ′ i d , t i t l e , c o n t e n t , c l a s s i d , c l a s s n a m e , s o r t , l i n k a d d r e s s , c r e a t e t i m e , m o d i f y t i m e ′ ) ; 查询列表 g e t L i s t ( site_id] ], 'id, title, content, class_id, class_name, sort, link_address, create_time, modify_time'); 查询列表getList( siteid]],id,title,content,classid,classname,sort,linkaddress,createtime,modifytime);查询列表getList(condition = [], $field = true, $order = ‘’, $alias = ‘a’, $join = [], $group = ‘’, $limit = null)

model(‘help’)->getList($condition, $field, $order, ‘’, ‘’, ‘’, l i m i t ) ; 查询分页列表 p a g e L i s t ( limit); 查询分页列表pageList( limit);查询分页列表pageList(condition = [], $field = true, $order = ‘’, $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = ‘a’, $join = [], $group = null, $limit = null)

model(‘help’)->pageList($condition, $field, $order, $page, $page_size);
查询视图,按照thinkphp视图查询方法:

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)

  1. 数据添加
    niushop数据添加使用add方法,例如:

    /**

    • 添加帮助文章
    • @param array d a t a ∗ / p u b l i c f u n c t i o n a d d H e l p ( data */ public function addHelp( data/publicfunctionaddHelp(data)
      {
      h e l p i d = m o d e l ( ′ h e l p ′ ) − > a d d ( help_id = model('help')->add( helpid=model(help)>add(data);
      Cache::tag(“help”)->clear();
      return t h i s − > s u c c e s s ( this->success( this>success(help_id);
      }
  2. 数据修改,使用update方法,传入修改条件
    /**

    • 修改帮助文章
    • @param array d a t a ∗ / p u b l i c f u n c t i o n e d i t H e l p ( data */ public function editHelp( data/publicfunctioneditHelp(data, $condition)
      {
      r e s = m o d e l ( ′ h e l p ′ ) − > u p d a t e ( res = model('help')->update( res=model(help)>update(data, $condition);
      Cache::tag(“help”)->clear();
      return t h i s − > s u c c e s s ( this->success( this>success(res);
      }
  3. 数据删除,使用delete方法

    /**

    • 删除文章
    • @param unknown c o u p o n t y p e i d ∗ / p u b l i c f u n c t i o n d e l e t e H e l p ( coupon_type_id */ public function deleteHelp( coupontypeid/publicfunctiondeleteHelp(condition)
      {
      r e s = m o d e l ( ′ h e l p ′ ) − > d e l e t e ( res = model('help')->delete( res=model(help)>delete(condition);
      Cache::tag(“help”)->clear();
      return t h i s − > s u c c e s s ( this->success( this>success(res);
      }
 类似资料: