StoreCoupon.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2018/01/22
  6. */
  7. namespace app\models\store;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\traits\ModelTrait;
  10. /**
  11. * TODO 优惠券Model
  12. * Class StoreCoupon
  13. * @package app\models\store
  14. */
  15. class StoreCoupon extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'store_coupon';
  27. use ModelTrait;
  28. /**
  29. * 优惠券过期
  30. * @return void
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public static function end_coupon()
  36. {
  37. $coupon = StoreCoupon::where('end_time', '<', time())->select();
  38. if ($coupon){
  39. foreach ($coupon as $item)
  40. {
  41. if ($item['end_time'] > 0){
  42. $product = StoreProduct::where('coupon', $item['id'])->where('is_show', 1)->find();
  43. if ($product){
  44. $product['is_show'] = 0;
  45. $product->save();
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }