UserCoupon.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class UserCoupon extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_user_coupon';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. public static function checkCoupon($id,$goods)
  14. {
  15. $coupon = self::where(['id'=>$id,'state'=>0])->find();
  16. if(!$coupon)
  17. {
  18. return false;
  19. }
  20. if(in_array($coupon['type'],[1,3]) && $coupon['goods_id'] != $goods['goods']['id'])
  21. {
  22. return false;
  23. }
  24. if($coupon['type'] == 2 && $coupon['shop_id'] != $goods['goods']['shop_id'])
  25. {
  26. return false;
  27. }
  28. return $coupon;
  29. }
  30. public static function getCount($params)
  31. {
  32. return self::where($params)->count();
  33. }
  34. public static function getList($params)
  35. {
  36. $list = self::where(['state'=>$params['state'],'user_id'=>$params['user_id']])->field('id,coupon_id,type,goods_id,shop_id,achieve,reduce,exittime,state,createtime')->order('id desc')->page($params['page'])->limit(10)->select();
  37. foreach ($list as &$value)
  38. {
  39. $value['goodsName'] = $value['goods_id']?\app\api\model\service\Goods::where(['id'=>$value['goods_id']])->value('name'):'';
  40. $value['shopName'] = $value['shop_id']?\app\api\model\service\Shop::getName($value['shop_id']):'';
  41. }
  42. return $list;
  43. }
  44. public static function getInfo($id)
  45. {
  46. return self::where(['id'=>$id])->field('id,achieve,reduce,goods_id,shop_id,type,state,createtime')->find();
  47. }
  48. }