💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 根据商品ID查询满足的满折活动ID **位置:** Common\Common\function.php **参数:** * @param int $no_id 商品ID * @param int $type 商品ID类型 1表示唯一码 2表示SKU 3表示SKC **调用:** **控制器中调用:** $total_discount = check_total_discount($skc_id, 3); **View模版中调用:** {$vo.no_id|check_total_discount = 3} **完整代码:** ~~~ /** * 根据商品ID查询满足的满折活动ID * QuJinming 2018-07-18 * @param int $no_id 商品ID * @param int $type 商品ID类型 1表示传入的是唯一码,2表示传入的是SKU,3表示传入的SKC(活动范围为唯一码时必须传入唯一码) * @return array $active 查询到的活动ID数组 * 异常返回 -1:传入商品ID的SPUID不存在 * -2:传入商品ID的SKUID不存在 * -3:传入商品ID的SKCID不存在 */ function check_total_discount($no_id, $type) { // 1、根据用途,获取满减活动基本信息 $time = time(); $map['start_time'] = array('elt', $time); // 活动开始时间 $map['end_time'] = array('egt', $time); // 活动结束时间 $map['types'] = array('eq', 3); // 活动类型 1为限时折扣,2为满减,3为满折 $map['status'] = 1; // 审批状态(0为未审批;1为审批通过;2为终止或审批不通过) $event_result = M('event_basic')->where($map)->select(); // 2、根据传入的商品ID获取商品的SPUID和SKUID及商品品类信息 if ($type == 1) { $spu_id = M('goods_item')->where('id=' . $no_id)->getField('spu_id'); // 获取spu_id $sku_id = M('goods_item')->where('id=' . $no_id)->getField('sku_id'); // 获取sku_id $skc_id = M('goods_item')->where('id=' . $no_id)->getField('skc_id'); // 获取skc_id $item_id = $no_id; // 获取唯一码id } elseif ($type == 2) { $spu_id = M('goods_sku')->where('id=' . $no_id)->getField('spu_id'); // 获取spu_id $sku_id = $no_id; // 获取sku_id $skc_id = M('goods_sku')->where('id=' . $no_id)->getField('skc_id'); // 获取skc_id } elseif ($type == 3) { $spu_id = M('goods_skc')->where('id=' . $no_id)->getField('spu_id'); // 获取spu_id $sku_ids = M('goods_sku')->where('skc_id=' . $no_id)->getField('id', true); // 获取sku_id $skc_id = $no_id; // 获取skc_id } if (empty($spu_id)) { return -1; // '异常:传入商品ID的SPUID不存在' } if (empty($sku_id) && empty($sku_ids)) { return -2; // '异常:传入商品ID的SKUID不存在' } if (empty($skc_id)) { return -3; // '异常:传入商品ID的SKCID不存在' } $goods['price'] = M('goods_sku')->where('skc_id=' . $skc_id)->getField('original_price'); // 获取商品吊牌价 $goods['brand'] = M('goods_spu')->where('id=' . $spu_id)->getField('brand_id'); // 获取品牌ID $goods['sex'] = M('goods_spu_category')->where('level=1 and spu_id=' . $spu_id)->getField('cat_id'); // 获取性别ID $goods['big_class'] = M('goods_spu_category')->where('level=2 and spu_id=' . $spu_id)->getField('cat_id'); // 获取大类ID // 3、判断商品符合的活动 foreach ($event_result as $key => $value) { // 满减范围 1为品类,2为SPU,3为SKU if ($value['order_discount'] == 1) { $where_a['event_id'] = array('eq', $value['id']); $where_a['is_delete'] = array('eq', 0); $event_class = M('event_total_goods_class')->where($where_a)->select(); foreach ($event_class as $k => $v) { // 判断品牌ID是否相等 if (!empty($v['brand_id'])) { if ($v['brand_id'] != $goods['brand'] && $v['cat_big_id'] != 1) { unset($event_class[$k]); continue; } } // 判断性别ID是否相等 if (!empty($v['cat_sex_id'])) { if ($v['cat_sex_id'] != $goods['sex'] && $v['cat_big_id'] != 1) { unset($event_class[$k]); continue; } } // 判断大类ID是否相等 if (!empty($v['cat_big_id'])) { if ($v['cat_big_id'] != $goods['big_class'] && $v['cat_big_id'] != 1) { unset($event_class[$k]); continue; } } } if (empty($event_class)) { unset($event_result[$key]); } else { foreach ($event_class as $kk => $vv) { $id = $vv['event_id']; $active[] = array('id' => $id); } } } elseif ($value['order_discount'] == 2) { $where_b['event_id'] = array('eq', $value['id']); $where_b['mark'] = array('eq', 1); // 1是款号;2是SKU;3是skc;4是唯一码 $where_b['is_delete'] = array('eq', 0); $where_b['menu_id'] = array('eq', $spu_id); $event_no = M('event_total_goods_no')->where($where_b)->select(); if (!empty($event_no)) { $id = array_column($event_no, 'event_id')[0]; $active[] = array('id' => $id); } } elseif ($value['order_discount'] == 3) { $where_c['event_id'] = array('eq', $value['id']); $where_c['mark'] = array('eq', 2); // 1是款号;2是SKU;3是skc;4是唯一码 $where_c['is_delete'] = array('eq', 0); // $type表示传入的ID类型, 1表示传入的是唯一码,2表示传入的是SKU, 3表示传入的SKC if ($type == 1 || $type == 2) { // 在限时折扣款号表中查询该SKU $where_c['menu_id'] = array('eq', $sku_id); $event_no = M('event_total_goods_no')->where($where_c)->select(); } elseif ($type == 3) { // 在限时折扣款号表中查询该SKU $where_c['menu_id'] = array('in', $sku_ids); $event_no = M('event_total_goods_no')->where($where_c)->select(); } if (!empty($event_no)) { $id = array_column($event_no, 'event_id')[0]; $active[] = array('id' => $id); } } elseif ($value['order_discount'] == 4) { $where_d['event_id'] = array('eq', $value['id']); $where_d['mark'] = array('eq', 3); // 1是款号;2是SKU;3是SKC;4是唯一码 $where_d['is_delete'] = array('eq', 0); $where_d['menu_id'] = array('eq', $skc_id); $event_no = M('event_total_goods_no')->where($where_d)->select(); if (!empty($event_no)) { $id = array_column($event_no, 'event_id')[0]; $active[] = array('id' => $id); } } elseif ($value['order_discount'] == 5) { // $type表示传入的ID类型, 1表示传入的是唯一码,2表示传入的是SKU, 3表示传入的SKC if ($type == 1) { // 在限时折扣款号表中查询该唯一码 $where_e['event_id'] = array('eq', $value['id']); $where_e['mark'] = array('eq', 4); // 1是款号;2是SKU;3是SKC;4是唯一码 $where_e['is_delete'] = array('eq', 0); $where_e['menu_id'] = array('eq', $item_id); $event_no = M('event_total_goods_no')->where($where_e)->select(); } if (!empty($event_no)) { $id = array_column($event_no, 'event_id')[0]; $active[] = array('id' => $id); } } } // 4、返回查询到的活动ID数组 return $active; } ~~~