MemberInvitationCodeLog.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2018/12/29
  6. * Time: 11:40
  7. */
  8. namespace app\common\models\member;
  9. use app\common\models\BaseModel;
  10. use app\framework\Database\Eloquent\Builder;
  11. use app\common\models\MemberShopInfo;
  12. class MemberInvitationCodeLog extends BaseModel
  13. {
  14. public $table = 'yz_member_invitation_log';
  15. public $search_fields = ['member_id', 'invitation_code', 'mid'];
  16. public $guarded = [''];
  17. public function getDates()
  18. {
  19. return ['created_at'];
  20. }
  21. public static function searchLog($params)
  22. {
  23. $res = self::select(['id', 'invitation_code', 'created_at', 'member_id', 'mid'])->uniacid();
  24. if ($params['code']) {
  25. $res->where('invitation_code', trim($params['code']));
  26. }
  27. if (!empty($params['times']['start']) && !empty($params['times']['end'])) {
  28. $res->where('created_at', '>=', $params['times']['start'])->where('created_at', '<=', $params['times']['end']);
  29. }
  30. if ($params['mid'] && $params['mid'] > 0) {
  31. $res->where('mid', $params['mid'])
  32. ->orWhere('member_id', $params['mid']);
  33. }
  34. $res = $res->with([
  35. 'yzMember' => function ($query) {
  36. $query->select(['inviter', 'member_id'])
  37. ->with([
  38. 'hasOneMember' => function ($query) {
  39. $query->select(['uid', 'avatar', 'nickname']);
  40. }
  41. ]);
  42. }
  43. ])
  44. ->with([
  45. 'hasOneMcMember' => function ($q) {
  46. $q->select(['member_id', 'inviter'])
  47. ->with([
  48. 'hasOneMember' => function ($q) {
  49. $q->select(['uid', 'avatar', 'nickname']);
  50. }
  51. ]);
  52. }
  53. ]);
  54. return $res;
  55. }
  56. public static function getLogByMemberId($member_id)
  57. {
  58. return self::uniacid()->where('member_id', $member_id)->first();
  59. }
  60. //使用邀请码用户id
  61. public function yzMember()
  62. {
  63. return $this->hasOne('\app\common\models\MemberShopInfo', 'member_id', 'member_id');
  64. }
  65. //推荐用户id
  66. public function hasOneMcMember()
  67. {
  68. return $this->hasOne('\app\common\models\MemberShopInfo', 'member_id', 'mid');
  69. }
  70. }