UserRiceCard.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\service\card;
  13. use app\api\model\GoodsCategoryRel as GoodsCategoryRelModel;
  14. use app\common\library\helper;
  15. use app\common\service\BaseService;
  16. /**
  17. *
  18. * Class Order
  19. * @package app\common\service
  20. */
  21. class UserRiceCard extends BaseService {
  22. private $notExceptGoodsId; // 不在配送范围的商品ID
  23. /**
  24. * 构造方法
  25. * Express constructor.
  26. * @param $goodsList
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. */
  31. public function __construct($goodsList)
  32. {
  33. parent::__construct();
  34. // 赋值传参
  35. $this->goodsList = $goodsList;
  36. }
  37. /**
  38. * 判断商品是否在现金卡之外
  39. */
  40. public function isExceptGoods($riceCard)
  41. {
  42. $exceptGoodsId = helper::getArrayColumn($riceCard['riceCardGoodsExcept'],'goods_id');
  43. //判断当前商品是否在可使用范围内
  44. foreach ($this->goodsList as $key => $goods) {
  45. if(in_array($goods['goods_id'],$exceptGoodsId)){
  46. $this->notExceptGoodsId = $goods['goods_id'];
  47. return false;
  48. }
  49. }
  50. return true;
  51. }
  52. /**
  53. * 判断商品是否在现金卡之外
  54. */
  55. public function isIncludeGoods($riceCard)
  56. {
  57. if(!empty($riceCard['dk_cat_ids'])){
  58. //包含
  59. $includeGoodsId = GoodsCategoryRelModel::where('category_id','in',explode(',',$riceCard['dk_cat_ids']))->column('goods_id');
  60. foreach ($this->goodsList as $goods) {
  61. if(!in_array($goods['goods_id'],$includeGoodsId)){
  62. $this->notExceptGoodsId = $goods['goods_id'];
  63. return false;
  64. }
  65. }
  66. }
  67. return true;
  68. }
  69. /**
  70. * 获取不在配送范围的商品名称
  71. * @return null
  72. */
  73. public function getExceptGoodsName()
  74. {
  75. $item = helper::getArrayItemByColumn($this->goodsList, 'goods_id', $this->notExceptGoodsId);
  76. return !empty($item) ? $item['goods_name'] : null;
  77. }
  78. }