截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TeamValidate.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\api\validate;
  3. use app\common\basics\Validate;
  4. use app\common\model\goods\Goods;
  5. use app\common\model\shop\Shop;
  6. class TeamValidate extends Validate
  7. {
  8. protected $rule = [
  9. 'team_id' => 'require|number',
  10. 'goods_id' => 'require|number|checkShop',
  11. 'item_id' => 'require|number',
  12. 'count' => 'require|number',
  13. ];
  14. protected $message = [
  15. 'team_id.require' => '缺少team_id',
  16. 'team_id.number' => 'team_id需为数字',
  17. 'goods_id.require' => '缺少goods_id',
  18. 'goods_id.number' => 'goods_id需为数字',
  19. 'item_id.require' => '缺少item_id',
  20. 'item_id.number' => 'item_id需为数字',
  21. 'count.require' => '缺少count',
  22. 'count.number' => 'count需为数字',
  23. ];
  24. protected $scene = [
  25. 'check' => ['goods_id', 'item_id', 'count']
  26. ];
  27. /**
  28. * @notes 检查商品所属店铺的营业状态
  29. * @param $goods_id
  30. * @return bool|string
  31. * @author Tab
  32. * @date 2021/7/19 14:08
  33. */
  34. public function checkShop($goods_id)
  35. {
  36. $shop_id = Goods::where('id', $goods_id)->value('shop_id');
  37. $shop = Shop::field('expire_time,is_run,is_freeze')->where(['del' => 0, 'id' => $shop_id])->findOrEmpty();
  38. if($shop->isEmpty()) {
  39. return '该商品所属店铺不存在';
  40. }
  41. // 获取原始数据(不经获取器)
  42. $shop = $shop->getData();
  43. if(!empty($shop['expire_time']) && ($shop['expire_time'] <= time())) {
  44. return '该商品所属店铺已到期';
  45. }
  46. if($shop['is_freeze']) {
  47. return '该商品所属店铺已被冻结';
  48. }
  49. if(!$shop['is_run']) {
  50. return '该商品所属店铺暂停营业中';
  51. }
  52. return true;
  53. }
  54. }