|
|
|
<?php
|
|
|
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\common\repositories\user;
|
|
|
|
|
|
|
|
use app\common\model\user\UserPartner;
|
|
|
|
use app\common\repositories\BaseRepository;
|
|
|
|
use app\common\dao\user\UserPartnerDao as dao;
|
|
|
|
use app\common\dao\system\admin\PartnerDao;
|
|
|
|
use FormBuilder\Factory\Elm;
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\facade\Route;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class UserAddressRepository
|
|
|
|
* @package app\common\repositories\user
|
|
|
|
* @day 2020/6/3
|
|
|
|
* @mixin dao
|
|
|
|
*/
|
|
|
|
class UserPartnerRepository extends BaseRepository
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var dao
|
|
|
|
*/
|
|
|
|
protected $dao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserAddressRepository constructor.
|
|
|
|
* @param dao $dao
|
|
|
|
*/
|
|
|
|
public function __construct(dao $dao)
|
|
|
|
{
|
|
|
|
$this->dao = $dao;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
* @param int $uid
|
|
|
|
* @return bool
|
|
|
|
* @author Qinii
|
|
|
|
*/
|
|
|
|
public function fieldExists(int $id, int $uid)
|
|
|
|
{
|
|
|
|
return $this->dao->userFieldExists($this->dao->getPk(), $id, $uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $uid
|
|
|
|
* @param $page
|
|
|
|
* @param $limit
|
|
|
|
* @return array
|
|
|
|
* @author Qinii
|
|
|
|
*/
|
|
|
|
public function getList($uid)
|
|
|
|
{
|
|
|
|
$list = $this->dao->getAll($uid)->order('id desc')->select();
|
|
|
|
return compact('list');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function changePartnerForm($uid)
|
|
|
|
{
|
|
|
|
/** @var UserLabelRepository $make */
|
|
|
|
$ids_list = UserPartner::getDB()->where('uid', $uid)->column('id') ?? [];
|
|
|
|
$data = UserPartner::getDB()->select()->toArray();
|
|
|
|
$list = [];
|
|
|
|
foreach ($data as $value => $label) {
|
|
|
|
$name = $label['partner_name'];
|
|
|
|
$value = (int)$label['id'];
|
|
|
|
$options[] = compact('value', 'name');
|
|
|
|
}
|
|
|
|
$data = ['partner_id' => $ids_list, 'uid' => $uid, 'option' => $options];
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editPartner(int $uid, array $user_role_id = [])
|
|
|
|
{
|
|
|
|
return Db::transaction(function () use ($uid, $user_role_id) {
|
|
|
|
//先清空
|
|
|
|
UserPartner::getInstance()->where('uid', $uid)->update(['partner_id' => '']);
|
|
|
|
//再更新
|
|
|
|
if (!empty($user_role_id)) {
|
|
|
|
foreach ($user_role_id as $k => $v) {
|
|
|
|
UserPartner::getInstance()->where('id', '=', $v)
|
|
|
|
->update(['uid' => $uid, 'create_time' => date("Y-m-d H:i:s")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|