// +---------------------------------------------------------------------- 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; } }