Coupon.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 优惠券管理
  7. */
  8. namespace app\allwin\model;
  9. use think\Model;
  10. class Coupon extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_allwin_coupon';
  13. /**
  14. * 好店信息
  15. * @return void
  16. */
  17. public function store(){
  18. return $this->hasOne('AllwinStore','id','store_id');
  19. }
  20. //搜索好店名称
  21. public function searchNameAttr($query,$value){
  22. if(!empty($value)){
  23. $query->where('name','like', '%'.$value .'%');
  24. }
  25. }
  26. //添加或编辑
  27. public function edit($param){
  28. $data['store_id'] = trim($param['store_id']);
  29. $data['name'] = trim($param['name']);
  30. $data['pay_price'] = trim($param['pay_price']);
  31. $data['img'] = trim($param['img']);
  32. $data['update_time'] = time();
  33. if(isset($param['id'])){
  34. $condition['id'] = $param['id'];
  35. $condition['member_miniapp_id'] = $param['miniapp_id'];
  36. return self::save($data,$condition);
  37. }else{
  38. $data['create_time'] = time();
  39. $data['member_miniapp_id'] = $param['miniapp_id'];
  40. return self::insert($data);
  41. }
  42. }
  43. /**
  44. * 店铺和优惠券联查(API) 带翻页,不包含店铺信息
  45. * VIP\Coupon
  46. * @return void
  47. */
  48. public static function couponList(array $condition,int $page = 6){
  49. return self::where($condition)->order('is_top desc,sort desc,sort desc')->paginate($page,true);
  50. }
  51. /**
  52. * 店铺和优惠券联查(API) 带翻页,包含店铺信息
  53. * VIP\Coupon
  54. * @return void
  55. */
  56. public static function storeCoupon(array $condition,int $page = 6){
  57. return self::with('store')->where($condition)->order('is_top desc,sort desc,size desc')->paginate($page,true);
  58. }
  59. }