### 根據商品編碼ID查詢限時折扣價格信息(詳情頁展示活動價用)
**位置:**
Common\Lib\EventLib.class.php
**參數:**
* @param $no_id int 商品編碼ID
* @param $type int 商品編碼ID類型, 1表示傳入的是唯一碼,2表示傳入的是SKU, 3表示傳入的是SKC
**調用:**
* $event = new EventLib();
* $time_event = $event->getTimeEventPrice($skc_id, 3);
**返回:**
返回最優限時折扣信息$min數組,數組各項含義如下:
$min['id'] // 最優限時折扣活動ID
$min['ac_price'] // 最優限時折扣價格
$min['ac_discount'] // 最優限時折扣
$min['event_name'] // 活動名稱
$min['start_time'] // 活動開始時間
$min['end_time'] // 活動結束時間
$min['shops_ids'] // 參與門店ID
$min['shops'] // 參與門店數組
$min['actor'] // 參與人員數組,為空表示所有人都參與
$min['enjoy'] // 是否同時參與會員折扣,1表示是,0表示否
$min['prior'] // 會員是否優先參與活動,1表示是,0表示否
$min['prior_days'] // 會員優先天數
如果是會員優先活動
$min['normal_start'] //0表示非會員活動未開始,1表示非會員活動已開始 $min['rate'] // 積分倍率
**完整代碼:**
~~~
/**
*
* 獲取最優限時折扣活動價格相關信息(商城展示用)
* QJM 2018-07-11
* @param $no_id int 商品ID
* @param $type int ID類型, 1表示傳入的是唯一碼,2表示傳入的是SKU,3表示傳入的SKC,(活動范圍為唯一碼時必須傳入唯一碼)
* @return $min array 最優限時折扣信息
* 異常返回 異常:傳入商品ID的SPUID不存在
* 異常:傳入商品ID的SKUID不存在
* 異常:傳入商品ID的SKCID不存在
*/
public function getTimeEventPrice($no_id, $type) {
// 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;
}
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) { // 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_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) { // 3活動范圍為SKU
$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_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;
}
// 判斷價格最低的活動
$min = null;
foreach ($active as $key => $value) {
if ($key == 0) {
$min = $active[$key];
continue;
}
if ($active[$key]['ac_price'] < $min['ac_price']) {
$min = $active[$key];
}
}
// 查詢最優活動基本信息
$event_basic = M('event_basic')->where('id='.$min['id'])->find();
// 查詢活動參與門店
$shops_ids = M('event_shop')->where('event_id='.$value['id'])->getField('shops_id',true);
foreach ($shops_ids as $kk => $vv) {
if ($vv == 1) {
$event_shops = array(
0 => '全部門店'
);
break;
}
$event_shops[$kk] = M('shops')->where('id='.$vv)->getField('shops_name');
}
$min['event_name'] = $event_basic['event_name']; // 活動名稱
$min['start_time'] = $event_basic['start_time']; // 活動開始時間
$min['end_time'] = $event_basic['end_time']; // 活動結束時間
$min['shops_ids'] = $shops_ids; // 參與門店ID
$min['shops'] = $event_shops; // 參與門店
$actor = explode(",", $event_basic['actor']); // 參與人員
if ($actor[0] == 0) {
$min['actor'] = ''; // 參與人員
} else {
$min['actor'] = $actor; // 參與人員
}
$min['enjoy'] = $event_basic['enjoy']; // 會員顧客可同時參與會員折扣
$min['prior'] = $event_basic['prior']; // 會員優先參與活動
// 如果是會員優先活動
if ($min['prior'] == 1) {
// 判斷非會員是否已經可以參與最優活動價
$time = time();
if ($time < $event_basic['start_time'] + $event_basic['prior_days'] * 86400) {
$min['normal_start'] = 0; // 0表示非會員活動未開始,1表示非會員活動已開始
} else {
$min['normal_start'] = 1; // 0表示非會員活動未開始,1表示非會員活動已開始
}
}
$min['prior_days'] = $event_basic['prior_days']; // 會員優先天數
$min['rate'] = $event_basic['rate']; // 積分倍率
return $min;
}
~~~
- 模版
- 前言
- 項目架構
- 項目規范
- 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
- 問題反饋