123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- *
- *
- * @category xxx
- * @package PSR
- * @subpackage Documentation\API
- * @author xxx <xxx@xxx.com>
- * @license GPL https://xxx.com
- * @link https://xxx.com
- * @ctime: 2020/4/15 11:52
- */
- namespace App\Repositories;
- use App\Models\InviteNewUser;
- use App\Models\InviteNewUsersConfig;
- use App\Models\Order;
- use App\Models\RentOrder;
- class InviteNewUserRepository extends BaseRepository
- {
- public function __construct(InviteNewUser $inviteNewUser)
- {
- $this->model = $inviteNewUser;
- }
- public function create($invite_id, $register_id, $source = 1)
- {
- if($invite_id != 0){
- $data = [
- 'invite_id' => $invite_id,
- 'register_id' => $register_id,
- 'source' => $source,
- ];
- return $this->model->create($data);
- }
- }
- /**
- * 更新实名 updateCardCertified
- *
- * @param $register_id
- * @return mixed
- * @author Fx
- *
- */
- public function updateCardCertified($register_id)
- {
- return $this->model
- ->where('register_id', $register_id)
- ->update(['is_card_certified' => $this->model::CARD_CERTIFIED_OK]);
- }
- /**
- * 更新首单 updateFirstOrder
- *
- * @param $register_id
- * @return mixed
- * @author Fx
- *
- */
- public function updateFirstOrder($register_id)
- {
- return $this->model
- ->where('register_id', $register_id)
- ->update(['is_first_order' => $this->model::FIRST_ORDER_OK]);
- }
- /**
- * 是否达成条件 isCondition
- *
- * @param $invite_id integer 邀请人id
- * @param $condition int 条件
- * @param $num int 需要数量
- * @return bool|array
- * @author Fx
- *
- */
- public function isCondition($invite_id, $condition, $num)
- {
- if ($condition == InviteNewUsersConfig::CONDITION_IDCARD) {
- // 实名认证
- $res = $this->model->query()
- ->where('invite_id', $invite_id)
- ->where('status', $this->model::STATUS_OK)
- ->where('is_card_certified', $this->model::CARD_CERTIFIED_OK)
- ->limit($num)
- ->pluck('register_id')
- ->toArray();
- if (count($res) == $num) {
- return $res;
- } else {
- return false;
- }
- } elseif ($condition == InviteNewUsersConfig::CONDITION_NEW_ORDER) {
- // 验证首单完成并更新
- $this->verifyFirstOrder($invite_id);
- // 完成首单人数
- $res = $this->model->query()
- ->where('invite_id', $invite_id)
- ->where('status', $this->model::STATUS_OK)
- ->where('is_card_certified', $this->model::CARD_CERTIFIED_OK)
- ->where('is_first_order', $this->model::FIRST_ORDER_OK)
- ->limit($num)
- ->pluck('register_id')
- ->toArray();
- if (count($res) == $num) {
- return $res;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- /**
- * 验证首单完成并更新 verifyFirstOrder
- *
- * @param $invite_id
- * @return void
- * @author Fx
- *
- */
- public function verifyFirstOrder($invite_id)
- {
- // 实名认证人数
- $user_ids = $this->model->query()
- ->where('invite_id', $invite_id)
- ->where('status', $this->model::STATUS_OK)
- ->where('is_card_certified', $this->model::CARD_CERTIFIED_OK)
- ->pluck('register_id');
- if (!empty($user_ids)) {
- foreach ($user_ids as $v) {
- $order = Order::query()->where('user_id', $v)->where('status', Order::STATUS_COMPLETE_ORDER)->first();
- $orderRent = RentOrder::query()->where('user_id', $v)->where('status', RentOrder::STATUS_COMPLETE_ORDER)->first();
- if (!empty($order) || !empty($orderRent)) {
- $this->updateFirstOrder($v);
- }
- }
- }
- }
- /**
- * 更新用户名额失效 updateStatus
- *
- * @param $register_ids array 注册用户ids
- * @return void
- * @author Fx
- *
- */
- public function updateStatus($register_ids){
- return $this->model->whereIn('register_id',$register_ids)->update(['status'=>$this->model::STATUS_NO]);
- }
- public function getInviteUsers($invite_id){
- $this->verifyFirstOrder($invite_id);
- return $this->model->where('invite_id',$invite_id)->get();
- }
- }
|