123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php namespace Psource\Lib;
- use Dever;
- use Place;
- class Price
- {
- private $place;
- public function __construct(Place $place)
- {
- $this->place = $place;
- }
- # 获取价格
- public function get($info, $set, $buy_num = 1, $rebate = [])
- {
- # 生成范围
- $info['scope'] = $set['scope'] . ',' . $info['id'];
- # 查看库存
- if (isset($info['sku_id'])) {
- # 这种是资源传过来的
- $info['stock'] = Dever::load(\Pstock\Lib\Info::class)->yue($info['id'], $info['sku_id']);
- # 检测scope是否包含有parent_id
- if (isset($set['parent_id']) && $set['parent_id'] <= 0 && $info['cate_child_id']) {
- $info['scope'] = $set['scope'] . ',' . $info['cate_child_id'] . ',' . $info['id'];
- } else {
- $info['scope'] = $set['scope'] . ',' . $info['id'];
- }
- } elseif (isset($info['info_id'])) {
- # 这种是sku传过来的
- $info['stock'] = Dever::load(\Pstock\Lib\Info::class)->yue($info['info_id'], $info['id']);
- $info['scope'] = $set['scope'] . ',' . $info['info_id'];
- }
-
- # 原价
- $info['m_price'] = Dever::number($info['price']);
- # 促销 必须登录才有
- $info['promotion'] = $info['rebate'] = [];
- if ($this->place->uid) {
- $info['promotion'] = Dever::load(\Pbenefit\Lib\Item::class)->load('promotion')->get($this->place->uid, $info['scope'], $info['price'], $set['score']['exp']);
- if ($info['promotion']) {
- $info['price'] = $info['promotion']['price'];
- }
- }
- if ($info['price'] <= 0) {
- $info['price'] = 0;
- }
- if ($info['price'] == $info['m_price']) {
- $info['m_price'] = 0;
- }
- list($info['price_text'], $info['m_price_text']) = Dever::load(\Pscore\Lib\Info::class)->getText([$info['price'], $info['m_price']], $set['score']);
- # 获取促销描述
- $info['promotion_text'] = '';
- if ($info['promotion']) {
- $info['promotion_text'] = '<table class="rich-table" style="border-collapse: collapse; text-align: center; width: 100%;">';
- $info['promotion_text'] .= '<tr><td>原价</td><td></td><td>'.$info['m_price_text'].'</td></tr>';
- $promotion = [$info['promotion']];
- foreach ($promotion as $k => $v) {
- $text = Dever::load(\Pscore\Lib\Info::class)->getText($v['price'], $set['score']);
- $type = '<td></td>';
- if ($v['type'] != 3) {
- $type = '<td>'.$v['value'].'</td>';
- }
- $info['promotion_text'] .= '<tr><td>'.$v['name'].'</td>'.$type.'<td>'.$text.'</td></tr>';
- }
- $info['promotion_text'] .= '</table>';
- }
- # 购买数量
- $info['total_price'] = $info['price'];
- if ($buy_num >= 0) {
- if ($info['stock']['num'] >= 0 && $info['stock']['num'] <= $buy_num) {
- $buy_num = $info['stock']['num'];
- }
- $info['buy_num'] = Dever::number($buy_num);
- $info['total_price'] = Dever::math('mul', $info['price'], $buy_num);
- /*
- if (isset($info['unum'])) {
- $info['total_unum'] = Dever::math('mul', $info['unum'], $buy_num);
- }
- */
- } else {
- # 返利
- if ($this->place->uid) {
- $info['money'] = Dever::math('mul', $info['total_price'], $set['score']['exp']);
- $info['rebate'] = Dever::load(\Pbenefit\Lib\Item::class)->load('rebate')->get($this->place->uid, $info['scope'], $info['money'], $rebate);
- }
- # 获取促销标签
- $info['promotion_tag'] = Dever::load(\Pbenefit\Lib\Item::class)->load('promotion')->getInfoByTag($info['scope']);
- }
- return $info;
- }
- # 获取专享
- public function getHave($info)
- {
- $result['status'] = 1;
- if ($info['have_vip']) {
- $result['status'] = 2;
- $result['list'] = [];
- $where['id'] = ['in', $info['have_vip']];
- $level = Dever::db('prole/level')->select($where, ['col' => 'id,name,info_id']);
- if ($level) {
- if ($this->place->uid && !isset($this->place->user['role_level'])) {
- $this->place->user['role_level'] = Dever::db('puser/role')->getLevel($this->place->uid);
- }
- $role = [];
- foreach ($level as $v) {
- if (empty($role[$v['info_id']])) {
- $role[$v['info_id']] = Dever::db('prole/info')->find(['id' => $v['info_id']], ['col' => 'id,name']);
- $role[$v['info_id']]['list'] = [];
- }
- $role[$v['info_id']]['list'][] = $v;
- if ($this->place->user['role_level'] && in_array($v['id'], $this->place->user['role_level'])) {
- $result['status'] = 1;
- }
- }
- $result['list'] = array_values($role);
- }
- }
- return $result;
- }
- }
|