ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 根据SKUID获取最优限时折扣活动价格相关信息(结算用) **位置:** Common\Lib\EventLib.class.php **参数:** * @param $sku_id int 商品SKUID * @param $use int 用途 2POS结算 3小程序结算 * @param $customer_id int 顾客ID **调用:** * $event = new EventLib(); * $ac_price = $event->orderTimeEventPrice($sku_id, 2, 14983); **完整代码:** ~~~ /** * * 获取最优限时折扣活动价格相关信息 * QJM 2018-07-23 * @param $no_id int 商品ID,其中POS结算必须传唯一码ID,商城结算必须传SKUID * @param $use int 用途 2POS结算 3商城结算 * @param $customer_id int 顾客ID * @return $min array 最优限时折扣信息 * 异常返回 异常2001:未找传入的顾客ID * 异常2002:传入商品ID的SPUID不存在 * 异常2003:传入商品ID的SKCID不存在 * 异常2004:传入商品ID的SKUID不存在 */ public function orderTimeEvent($no_id, $use, $customer_id) { // 根据customer_id获取会员级别ID if (empty($customer_id) || $customer_id == 0) { $vip_type = 0; // 0表示普通顾客 } else { $important = $this->getVipType($customer_id); if ($important == -1) { return '异常2001:未找到该顾客信息,请新增顾客信息'; } $vip_type = $important['ber_id']; // 会员级别ID } // 2表示POS结算,传入的$no_id是唯一码ID,3表示商城结算,传入的$no_id是SKUID if ($use == 2) { $spu_id = M('goods_item')->where('id=' . $no_id)->getField('spu_id'); // 获取SPUID $skc_id = M('goods_item')->where('id=' . $no_id)->getField('skc_id'); // 获取SKCID $sku_id = M('goods_item')->where('id=' . $no_id)->getField('sku_id'); // 获取SKCID $item_id = $no_id; // 获取唯一码ID } elseif ($use == 3) { $spu_id = M('goods_sku')->where('id=' . $no_id)->getField('spu_id'); // 获取SPUID $skc_id = M('goods_sku')->where('id=' . $no_id)->getField('skc_id'); // 获取SKCID $sku_id = $no_id; // 获取SKUID } if (empty($spu_id)) { return '异常2002:传入商品ID的SPUID不存在'; } if (empty($skc_id)) { return '异常2003:传入商品ID的SKCID不存在'; } if (empty($sku_id)) { return '异常2004:传入商品ID的SKUID不存在'; } // 获取商品基本信息 $goods['price'] = M('goods_sku')->where('id=' . $sku_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 // 根据用途,获取限时折扣活动基本信息 $event_result = $this->getEvent(1, $use, $vip_type); 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;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) { $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); $where_c['menu_id'] = array('eq', $sku_id); // 在限时折扣款号表中查询该SKU $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) { // $use值为2表示POS结算,传入的$no_id是唯一码ID,为3表示商城结算,传入的$no_id是SKUID if ($use == 2) { // 在限时折扣款号表中查询该唯一码 $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); } } } // 如果查询到活动信息为空直接返回 if (empty($active)) { return array(); } // 判断价格最低的活动 $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(); // 查询最优活动参与门店 $event_shops = M('event_shop')->where('event_id='.$min['id'])->getField('shops_id',true); $min['start_time'] = $event_basic['start_time']; // 活动开始时间 $min['end_time'] = $event_basic['end_time']; // 活动结束时间 $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; } ~~~