123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\service\card;
- use app\api\model\GoodsCategoryRel as GoodsCategoryRelModel;
- use app\common\library\helper;
- use app\common\service\BaseService;
- /**
- *
- * Class Order
- * @package app\common\service
- */
- class UserRiceCard extends BaseService {
- private $notExceptGoodsId; // 不在配送范围的商品ID
- /**
- * 构造方法
- * Express constructor.
- * @param $goodsList
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function __construct($goodsList)
- {
- parent::__construct();
- // 赋值传参
- $this->goodsList = $goodsList;
- }
- /**
- * 判断商品是否在现金卡之外
- */
- public function isExceptGoods($riceCard)
- {
- $exceptGoodsId = helper::getArrayColumn($riceCard['riceCardGoodsExcept'],'goods_id');
- //判断当前商品是否在可使用范围内
- foreach ($this->goodsList as $key => $goods) {
- if(in_array($goods['goods_id'],$exceptGoodsId)){
- $this->notExceptGoodsId = $goods['goods_id'];
- return false;
- }
- }
- return true;
- }
- /**
- * 判断商品是否在现金卡之外
- */
- public function isIncludeGoods($riceCard)
- {
- if(!empty($riceCard['dk_cat_ids'])){
- //包含
- $includeGoodsId = GoodsCategoryRelModel::where('category_id','in',explode(',',$riceCard['dk_cat_ids']))->column('goods_id');
- foreach ($this->goodsList as $goods) {
- if(!in_array($goods['goods_id'],$includeGoodsId)){
- $this->notExceptGoodsId = $goods['goods_id'];
- return false;
- }
- }
- }
- return true;
- }
- /**
- * 获取不在配送范围的商品名称
- * @return null
- */
- public function getExceptGoodsName()
- {
- $item = helper::getArrayItemByColumn($this->goodsList, 'goods_id', $this->notExceptGoodsId);
- return !empty($item) ? $item['goods_name'] : null;
- }
- }
|