CardUser.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 CardUser extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_allwin_card_user';
  13. /**
  14. * 好店
  15. * @return void
  16. */
  17. public function store(){
  18. return $this->hasOne('AllwinStore','id','store_id');
  19. }
  20. /**
  21. * 储值卡
  22. * @return void
  23. */
  24. public function card(){
  25. return $this->hasOne('Card','id','card_id');
  26. }
  27. /**
  28. * 优惠券
  29. * @return void
  30. */
  31. public function couponUser(){
  32. return $this->hasOne('CouponUser','id','user_coupon_id');
  33. }
  34. //用户
  35. public function user(){
  36. return $this->hasOne('app\common\model\SystemUser','id','user_id');
  37. }
  38. /**
  39. * 待删除
  40. * 某个用户的会员卡列表(关联查询性能较慢)
  41. * @param array $condition
  42. * @param integer $page
  43. * @return void
  44. */
  45. public static function userCardList(array $condition,int $page = 10){
  46. return self::view('allwin_card_user', '*')
  47. ->view('allwin_store', 'name as store_name', 'allwin_store.id = allwin_card_user.store_id')
  48. ->view('allwin_card', 'name,tips', 'allwin_card.id = allwin_card_user.card_id')
  49. ->where($condition)->paginate($page,true);
  50. }
  51. /**
  52. * 待删除
  53. * 读取某个用户的单个储值卡信息
  54. * @param array $condition
  55. * @param integer $page
  56. * @return void
  57. */
  58. public static function userCard(array $condition){
  59. return self::view('allwin_card_user', '*')
  60. ->view('allwin_store', 'name as store_name,img,address,telphone,state_text,is_top,tags', 'allwin_store.id = allwin_card_user.store_id')
  61. ->view('allwin_card', 'name,discount,tips', 'allwin_card.id = allwin_card_user.card_id')
  62. ->where($condition)->find();
  63. }
  64. }