### 根据传入的商品ID查询最优限时折扣活动价格或者折扣信息(返回结果带有html标签)
**位置:** Common\Common\function.php
**参数:**
* @param int $no_id 商品ID
* @param int $type 商品ID类型, 1是唯一码,2是SKU,3是SKC
* @param $back int 返回结果类型 1返回的是带链接的活动价,2返回的是限时折扣,3返回的是活动价
* @param $shop_id int 当前门店ID,可以选填
**调用:**
列表展示用,详情页展示限时折扣活动价请调用Event组件库中的同名方法
getTimeEventPrice
**View模版中调用:**
{$vo.no_id|get_time_event_price = 1,1} // 返回活动价(带连接)
{$vo.no_id|get_time_event_price = 1,2,70} // 返回指定门店的限时折扣
{$vo.no_id|get_time_event_price = 1,3} // 返回活动价
**PHP 调用中调用:**
get_time_event_price($v['item_id'], 1, 1) // 返回活动价(带连接)
get_time_event_price($v['item_id'], 1, 2) // 返回限时折扣
get_time_event_price($v['item_id'], 1, 3,70) // 返回指定门店的活动价
**返回:**
如果是会员优先活动,非会员参与时间未到,根据函数第三个参数返回
会员限时折扣价
return "<a href=".$href.">".$min["ac_price"]."(会员)</a>";
或者会员限时折扣
return $min['ac_discount']."(会员)";
如果是会员优先活动,非会员参与时间已到,根据函数第三个参数返回
限时折扣价
return "<a href=".$href.">".$min["ac_price"]."</a>";
或者限时折扣
return $min['ac_discount'];
如果是非会员优先活动,根据函数第三个参数直接返回最低限时折扣价
return "<a href=".$href.">".$min["ac_price"]."</a>";
或者限时折扣
return $min['ac_discount'];
**完整代码:**
~~~
/**
* 查询最优限时折扣活动价格信息
* QJM 2018-07-11
* qjm 2023-02-21 update
* 为了兼容小程序无法从本文件获取SESSION信息,新添加了当前门店ID参数,如果不传,默认从SESSION取门店
* @param $no_id int 商品ID
* @param $type int 商品ID类型 1是唯一码,2是SKU,3是SKC
* @param $back int 返回结果类型 1返回的是带链接的活动价,2返回的是限时折扣,3返回的是活动价
* @param $shop_id int 当前门店ID,可以选填
* @return $min array 最优限时折扣信息
*/
function get_time_event_price ($no_id, $type, $back, $shop_id) {
// 1、查询所有正在进行的限时折扣活动
$time = time();
$map['start_time'] = array('elt', $time); // 活动开始时间
$map['end_time'] = array('egt', $time); // 活动结束时间
$map['types'] = array('eq', 1); // 活动类型 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 '异常:传入商品ID的SPUID不存在';
}
if (empty($sku_id) && empty($sku_ids)) {
return '异常:传入商品ID的SKUID不存在';
}
if (empty($skc_id)) {
return '异常:传入商品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, 4为SKC,5为唯一码
if ($value['time_discount'] == 1) {
$where_a['event_id'] = array('eq', $value['id']);
$where_a['is_delete'] = array('eq', 0);
$event_class = M('event_time_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'];
$discount = $vv['event_discount'];
$price = $vv['event_discount'] * $goods['price'];
$active[] = array('id' => $id, 'ac_price' => $price, 'ac_discount' => $discount);
}
}
} elseif ($value['time_discount'] == 2) {
$where_b['event_id'] = array('eq', $value['id']);
$where_b['mark'] = array('eq', 1); // 1是款号;2是SKU
$where_b['is_delete'] = array('eq', 0);
$where_b['menu_id'] = array('eq', $spu_id);
$event_no = M('event_time_goods_no')->where($where_b)->select();
if (!empty($event_no)) {
$id = array_column($event_no, 'event_id')[0];
$discount = round(array_column($event_no, 'discount_price')[0] / $goods['price'], 2); // 折扣价/原价保留两位小数
$price = array_column($event_no, 'discount_price')[0];
$active[] = array('id' => $id, 'ac_price' => $price, 'ac_discount' => $discount);
}
} elseif ($value['time_discount'] == 3) {
$where_c['event_id'] = array('eq', $value['id']);
$where_c['mark'] = array('eq', 2); // 1是款号;2是SKU
$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_time_goods_no')->where($where_c)->select();
} elseif ($type == 3) {
// 在限时折扣款号表中查询该SKU
$where_c['menu_id'] = array('in', $sku_ids);
$event_no = M('event_time_goods_no')->where($where_c)->select();
}
if (!empty($event_no)) {
$id = array_column($event_no, 'event_id')[0];
$discount = round(array_column($event_no, 'discount_price')[0] / $goods['price'], 2); // 折扣价/原价保留两位小数
$price = array_column($event_no, 'discount_price')[0];
// 将活动ID,活动折扣,活动折扣价存入活动数组
$active[] = array('id' => $id, 'ac_price' => $price, 'ac_discount' => $discount);
}
} elseif ($value['time_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_time_goods_no')->where($where_d)->select();
if (!empty($event_no)) {
$id = array_column($event_no, 'event_id')[0];
$discount = round(array_column($event_no, 'discount_price')[0] / $goods['price'], 2); // 折扣价/原价保留两位小数
$price = array_column($event_no, 'discount_price')[0];
// 将活动ID,活动折扣,活动折扣价存入活动数组
$active[] = array('id' => $id, 'ac_price' => $price, 'ac_discount' => $discount);
}
} elseif ($value['time_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_time_goods_no')->where($where_e)->select();
}
if (!empty($event_no)) {
$id = array_column($event_no, 'event_id')[0];
$discount = round(array_column($event_no, 'discount_price')[0] / $goods['price'], 2); // 折扣价/原价保留两位小数
$price = array_column($event_no, 'discount_price')[0];
// 将活动ID,活动折扣,活动折扣价存入活动数组
$active[] = array('id' => $id, 'ac_price' => $price, 'ac_discount' => $discount);
}
}
}
// 4、如果过滤后的活动信息为空,直接返回
if (empty($active)) {
return;
}
// 5、排除掉当前门店没有参与的活动 2023-10-12 jig add
$shop_active = '';
$push = 0;
$event_shop = '';
if (session('userInfo.is_hq') != 1 || !empty($shop_id)) { // 没有门店身份展示最优惠
if (empty($shop_id)) {
$login_shop = session('userInfo.shop_max_id');
} else {
$login_shop = $shop_id;
}
if ($login_shop > 0) {
foreach ($active as $key => $value) {
$arr_shop['event_id'] = $value['id'];
$arr_shop['shops_id'] = array(array('eq', $login_shop), array('eq', 1), 'or');
$event_shop = M('event_shop')->where($arr_shop)->select();
if (!empty($event_shop)) {
$shop_active[$push] = $active[$key];
$push++;
}
}
if (empty($shop_active)) {
return ''; // 未查到门店返回空
}
}
} else {
$shop_active = $active;
}
// 6、判断价格最低的活动
$min = null;
foreach ($shop_active as $key => $value) {
if ($key == 0) {
$min = $shop_active[$key];
continue;
}
if ($shop_active[$key]['ac_price'] < $min['ac_price']) {
$min = $shop_active[$key];
}
}
// 7、查询最优活动基本信息
$event_basic = M('event_basic')->where('id=' . $min['id'])->find();
$min['prior'] = $event_basic['prior']; // 会员优先参与活动
// 拼接限时折扣活动价链接
$href = '/index.php/Wpos/Member/Event/index/id/'.$event_basic['id'].'.html';
// 8、判断会员优先活动
if ($min['prior'] == 1) {
// 判断非会员是否已经可以参与最优活动价
$time = time();
if ($time < $event_basic['start_time'] + $event_basic['prior_days'] * 86400) {
if ($back == 1) {
return "<a href=".$href.">".$min["ac_price"]."(会员)</a>";
} elseif ($back == 2) {
return $min['ac_discount']."(会员)";
} elseif ($back == 3) {
return $min["ac_price"];
}
} else {
if ($back == 1) {
return "<a href=".$href.">".$min["ac_price"]."</a>";
} elseif ($back == 2) {
return $min['ac_discount'];
} elseif ($back == 3) {
return $min["ac_price"];
}
}
}
// 9、非会员优先活动直接返回最低限时折扣价或折扣
if ($back == 1) {
return "<a href=".$href.">".$min["ac_price"]."</a>";
} elseif ($back == 2) {
return $min['ac_discount'];
} elseif ($back == 3) {
return $min["ac_price"];
}
}
~~~
- 模版
- 前言
- 项目架构
- 项目规范
- HTML
- CSS
- Javascript
- PHP
- MySQL
- 注意规范
- 开发版本管理
- 开发流程
- 系统配置
- 阿里云服务器配置
- 计划任务配置说明
- 开发示例
- Page分页
- Search_param搜索结果赋值
- Add新增
- Edit编辑
- Ajax表单验证
- Ajax二级联动
- Excel 导出数据首位不去0的方法
- POS总部控制
- 下载CSV格式的模板
- 订单唯一码表和订单SKU表实收金额生成
- 快捷日期选择
- JS函数
- ajax_send
- ajax_result
- createQrCodes
- createBarCodes
- printTpl
- JS插件
- BootstrapValidator表单验证插件
- Address省市区插件
- Bootstrap-datepicker日期插件
- Bootstrap-select多选框插件
- Toastr消息提示插件
- PalyAudit扫描声音提示插件
- WebUploader多图片上传插件
- Ueditor富文本编辑器插件
- Function
- alert
- object_to_array
- array_to_object
- get_address
- set_param_url
- get_shops_name
- get_user_name
- get_warehouse
- get_cheapest_sku
- print_attr(新)
- print_img(新)
- get_spu_no(新)
- get_type_name(新)
- get_brand_en(新)
- get_cat_name(新)
- get_attr_name(新)
- spu_cat_info(新)
- get_time_event_price
- get_vendors
- check_total_reduce
- check_total_discount
- get_inventory
- get_delivery
- get_sale_inventory
- get_customer_name
- phone_protection
- get_order_no
- get_event_name
- get_order_status
- get_item_status
- get_ditch_name
- get_card_no
- get_shop_sales
- get_pay_name
- get_season
- amt_format
- get_cat_parent
- print_attr_id
- round_bcadd
- round_bcsub
- round_bcmul
- round_bcdiv
- get_account_name
- Controller
- Common_BaseController
- check_membership_card
- get_menu_list
- importErrorMassage
- Wpos_IndexController
- get_customer_vip_card
- get_shops_id
- calculate_active_integral
- check_numbers_active
- check_goods_active
- Woms_IndexController
- Model
- View
- category
- cycle_date.html
- shop_select门店多选搜索框
- 品牌A-Z排序多选brand_mc.html
- 供应商代码A-Z排序vendor_no_mc.html
- Lib
- BuyerLib
- WarehouseLib
- EventLib
- getTimeEventPrice
- getVipType
- getEvent
- orderTotalEvent
- orderTimeEvent
- getTotalReduce
- getTotalDiscount
- SaleLib
- CustomerLib
- addCustomerService
- GiftcardLib
- WechatLib
- wxRefund
- OrdersLib
- orderLog
- calculatePayinAmount
- calculateSubtotal
- correctPayinAmount
- saveOrderAddress
- getOrderAddress
- setDeliveryNo
- SyncLib
- updateOuterStock
- UserLib
- createCommission
- FlowLib
- orderList
- addOrder
- addLog
- orderInfo
- checkSku
- orderSave
- orderStop
- orderExecute
- skuEdit
- orderPrinta
- scanGoods
- boxClose
- orderOut
- take
- bview
- check
- deliveryStatus
- checkGoods
- GoodsLib
- createGoodsNo
- createNewGoodsNo
- getSystemStyleNo
- getDim
- MallLib
- smsLog
- GoodsBaseLib
- getBrandInfo
- getBrandsInfo
- getAttrIdArray
- getPrintAttr
- getMustAttr
- getCatIdInfo
- valTypeId
- valsTypeId
- getCatNoInfo
- getCatInfo
- getAttrArr
- getAttrInfo
- getValInfo
- getAttrId
- getValId
- getAttrSeaon
- getValueId
- PointsLog
- pointsIn
- pointsUp
- EcGoodsLib
- getSkuInventory
- Tools
- CsvTools
- csvImport
- csvExport
- ExcelTools
- importExcel
- exportExcel
- exportHeadExcel
- MailTools
- SmsTools
- sendMessage
- UploadTools
- ExportTools
- exportData
- TaobaoTools
- getOnsaleItems
- getSkusItems
- PicturesTools
- uploadPicture
- Plugins
- WxBase
- Taobao
- 问题反馈