### 通过商品唯一码和顾客身份判断是否限时折扣营销活动的商品
**位置:**
Wpos\Controller\IndexController.class.php
**参数:**
* 判断是否限时折扣营销活动的商品
* @param $goods_no string 唯一码
* @param $customer int 顾客会员身份
* @return array
**调用:**
* $result = $this->check_goods_active($goods_no,$customer);
**完整代码:**
~~~
/**
* 对单个商品的营销活动判断封装
* 包括活动最优判断,折扣最低
* Lanson 2017-08-22
* @param $goods_no string 唯一码
* @param $customer int 顾客会员身份
* @return array
*/
public function check_goods_active($goods_no,$customer) {
// 1.调用营销活动公共方法
$event_result = $this->check_public_active();
if (empty($event_result)) {
return array('success' => false, 'msg' => '暂时不符合活动条件');
}
// 2.判断是否限时折扣活动
foreach ($event_result as $key => $value) {
// 判断活动是否包含限时折扣
if (empty($value['time_discount'])) {
unset($event_result[$key]);
}
}
if (empty($event_result)) {
return array('success' => false, 'msg' => '暂时不符合活动条件');
}
// 3.判断唯一码是否符合营销活动的范围内
// 查询输入的唯一码的基本信息
$goods = M('goods_no no')
->field("no.no,no.system_style_no,menu.brand,menu.large_class,menu.middle_class,menu.small_class,menu.sex,
no.company_retail_price as price,no.discount,no.color_name,no.size")
->join("coscia_goods_menu as menu on no.menu_id = menu.id","left")
->where("no.no = '{$goods_no}'")
->find();
// 将商品的品牌、大类、中类、小类、性别全部转化为ID值
$brand_id = M('goods_base_data_value_list')->where(" `key` = 'name_en' and `value` = '{$goods['brand']}'")->getField('base_data_id');
$large_class_id = M('goods_base_data_value_list')->where(" `key` = 'name' and `value` = '{$goods['large_class']}'")->getField('base_data_id');
$middle_class_id = M('goods_base_data_value_list as list')
->join("coscia_goods_base_data_mark as mark on mark.id = list.base_data_id")
->join("coscia_goods_base_data_list as b on mark.data_list_id = b.id")
->where("list.key = 'no' and list.value = '{$goods['middle_class']}' and b.name = '中类'")
->getField('base_data_id');
$small_class_id = M('goods_base_data_value_list as list')
->join("coscia_goods_base_data_mark as mark on mark.id = list.base_data_id")
->join("coscia_goods_base_data_list as b on mark.data_list_id = b.id")
->where("list.key = 'name' and list.value = '{$goods['small_class']}' and b.name = '小类'")
->getField('base_data_id');
$sex_id = M('goods_base_data_value_list as list')
->join("coscia_goods_base_data_mark as mark on mark.id = list.base_data_id")
->join("coscia_goods_base_data_list as b on mark.data_list_id = b.id")
->where("list.key = 'name' and list.value = '{$goods['sex']}' and b.name = '性别'")
->getField('base_data_id');
$goods['brand'] = $brand_id;
$goods['large_class'] = $large_class_id;
$goods['middle_class'] = $middle_class_id;
$goods['small_class'] = $small_class_id;
$goods['sex'] = $sex_id;
$active = array(); // 记录满足条件后活动ID和折后价
// 通过活动ID来查询对应的活动范围
foreach ($event_result as $keyA => $valueA) {
// 1为品类
if ($valueA['time_discount'] == 1) {
$whereC['event_id'] = array('eq',$valueA['id']);
$whereC['is_delete'] = array('eq',0);
$event_class = M('event_time_goods_class')->where($whereC)->select();
foreach ($event_class as $keyC => $valueC) {
// 判断大类ID是否相等
if (!empty($valueC['large_class'])) {
if ($valueC['large_class'] == 1) {
continue;
} elseif ($valueC['large_class'] != $goods['large_class']) {
unset($event_class[$keyC]);
continue;
}
}
// 判断品牌ID是否相等
if (!empty($valueC['brand'])) {
if ($valueC['brand'] != $goods['brand']) {
unset($event_class[$keyC]);
continue;
}
}
// 判断中类ID是否相等
if (!empty($valueC['middle_class'])) {
if ($valueC['middle_class'] != $goods['middle_class']) {
unset($event_class[$keyC]);
continue;
}
}
// 判断小类ID是否相等
if (!empty($valueC['small_class'])) {
if ($valueC['small_class'] != $goods['small_class']) {
unset($event_class[$keyC]);
continue;
}
}
// 判断性别ID是否相等
if (!empty($valueC['sex'])) {
if ($valueC['sex'] != $goods['sex']) {
unset($event_class[$keyC]);
continue;
}
}
}
if (empty($event_class)) {
unset($event_result[$keyA]);
} else {
// 多个满足活动范围的折扣设定进行最优判断
$discount = 0;
$key = 0;
foreach ($event_class as $keyE => $valueE) {
if (empty($discount)) {
$discount = $valueE['discount'];
$key = $keyE;
continue;
}
if ($valueE['discount'] >= $discount) {
unset($event_class[$keyE]);
} else {
unset($event_class[$key]);
$key = $keyE;
$discount = $valueE['discount'];
}
}
$id = array_column($event_class, 'event_id')[0];
$price = round(array_column($event_class, 'discount')[0]*$goods['price']/10,0);
$discount = round(array_column($event_class, 'discount')[0]/10,2);
$active[] = array('id' => $id,'price' => $price,'ac_discount' => $discount);
}
}
// 2为款号或SKU
else {
$whereB['event_id'] = array('eq',$valueA['id']);
$whereB['is_delete'] = array('eq',0);
$event_no = M('event_time_goods_no')->where($whereB)->select();
// 通过Mark字段来区分是SKU还是款号
foreach ($event_no as $keyB => $valueB) {
// 款号
if ($valueB['mark'] == 1) {
$system_no = $goods['system_style_no'];
if ($valueB['system_style_no'] == $system_no) {
continue;
} else {
unset($event_no[$keyB]);
}
}
// SKU
elseif ($valueB['mark'] == 2) {
$sku = $this->noToSku($valueB['no']); // 通过函数从唯一码截取SKU码
if ($valueB['system_style_no'] == $sku) {
continue;
} else {
unset($event_no[$keyB]);
}
}
}
// 范围判断商品没找到匹配时,会删除营销活动的键和值
if (empty($event_no)) {
unset($event_result[$keyA]);
} else {
$id = array_column($event_no, 'event_id')[0];
$price = array_column($event_no, 'discount_price')[0];
$discount = round($price/$goods['price'],2);
$active[] = array('id' => $id,'price' => $price,'ac_discount' => $discount);
}
}
}
if (empty($event_result)) {
return array('success' => false, 'msg' => '暂时不符合活动条件');
}
// 4.对满足条件的活动进行最优判断
foreach ($active as $keyF => $valueF) {
if (empty($ac_price)) {
$ac_price = $valueF['price'];
$key = $keyF;
continue;
}
if ($valueF['price'] >= $ac_price) {
unset($active[$keyF]);
} else {
unset($active[$key]);
$key = $keyF;
$ac_price = $valueF['price'];
}
}
// 把active活动信息转为一维数组
$activeA = array();
foreach ($active as $keyG => $valueG) {
$activeA = $valueG;
}
// 5.最终返回成功的数组数据有活动ID、活动商品的基本信息、最终的折后价
$data = array('success' => true,'active' => $activeA);
return $data;
}
~~~
- 模版
- 前言
- 项目架构
- 项目规范
- 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
- 问题反馈