query()->insertGetId($data); // 如果操作失败 if( !$id ) return $id; // 返回结果 return $id; } /** * 添加数据 * */ public function edit($id,$data) { // 更新时间 $data['update_time'] = time(); // 写入数据表 $result = $this->query()->where([['id','=',$id]])->update($data); // 如果操作失败 if( !$result ) return 0; // 返回结果 return $id; } /** * 添加数据 * */ public function getIdByAttrIds($attrIds,$productId) { // 写入数据表 $id = $this->query()->where([['attr_ids','=',$attrIds],['product_id','=',$productId]])->value('id'); // 如果操作失败 if( !$id ) return 0; // 返回结果 return $id; } /** * 添加数据 * */ public function getListByIds($skuIds) { // 写入数据表 $data = $this->query()->whereIn('id',$skuIds)->where([['status','=',0]])->get(['id as sku_id','product_id','attr_names as sku_attr_names','quota','min_quota','price','market_price','stock','status'])->toArray(); // 列表 $list = []; // 循环处理 foreach ($data as $value) { // 重组数据 $list[$value['sku_id']]= $value; } // 返回结果 return $list; } /** * 添加数据 * */ public function getListByProductId($productId) { // 写入数据表 $list = $this->query()->where([['product_id','=',$productId]])->get(['id','attr_ids','attr_names','min_quota','quota','sku_thumb','price','market_price','stock','status'])->toArray(); // 返回结果 return $list; } }