### 根據商品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;
}
~~~
- 模版
- 前言
- 項目架構
- 項目規范
- 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
- 問題反饋