| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace app\common\model;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use app\common\model\UserPathModel;
- use think\Exception;
- use app\common\model\LedgerWalletModel;
- use think\Model;
- /**
- * 会员模型
- */
- class UserModel extends Model
- {
- // // 开启自动写入时间戳字段
- // protected $autoWriteTimestamp = 'int';
- // // 定义时间戳字段名
- // protected $createTime = 'createtime';
- // protected $updateTime = 'updatetime';
- // // 追加属性
- // protected $append = [
- // 'url',
- // ];.
- //0未开始 1进行中 2已结束 Not started
- const NOTSTOP = 0;
- const NORMAL = 1;
- const STOP = 2;
- protected $name = 'user';
- public function getById($userID)
- {
- return $this->where('id', $userID)->find();
- }
- public function getByAddress($address)
- {
- return $this->where("address", $address)->find();
- }
- public static function getByParentId(int $uid): int
- {
- return self::where('id', $uid)->value("parent_id");
- }
- public function getAllAddress()
- {
- $all_list = $this->field('id,address')->select();
- $arr = [];
- foreach ($all_list as $item){
- $arr[$item['address']] = $item['id'];
- }
- return $arr;
- }
- //获取用户RWA
- public static function getUserRwaNum(int $uid): int
- {
- return self::where('id', $uid)->value("rwa_num");
- }
-
- /**
- * RWA更新数据
- * @param int $uid
- * @param string $power
- * @return void
- */
- public static function updateForRwaNum(int $uid, int $pid, string $score, string $action)
- {
- if($action == '+'){
- //更新自己Rwa
- self::where('id', $uid)->setInc('rwa_num', $score);
- //更新直推Rwa
- return self::where('id', $pid)->setInc('direct_rwa', $score);
- }else{
- //更新自己Rwa
- self::where('id', $uid)->setDec('rwa_num', $score);
- //更新直推Rwa
- return self::where('id', $pid)->setDec('direct_rwa', $score);
- }
- }
- /**
- * 添加用户上级标识
- * @param int $uid
- * @param string $parentId
- * @return void
- */
- public static function updateUserSuper(int $uid, int $parentId)
- {
- self::where('id', $uid)->update(['is_super'=>self::NORMAL]);
- return self::where('id', $parentId)->setInc('direct_super', self::NORMAL);
- }
- /**
- * 获取直推用户黄金标识数量 direct_super >= 10
- * @param int $uid
- * @return void
- */
- public static function getDirectGoldNum(int $uid)
- {
- return self::where('parent_id', $uid)->where('direct_super', '>=' , 10)->column('direct_super');
- }
- //社区向上发放奖励津贴
- public static function setCommunityRewards($uid, $pv, $token)
- {
- $paths = UserPathModel::where('user_id', $uid)->where('distance', '<', 11)->order('distance', 'asc')->column('distance,parent_id');
- if (!empty($paths)) {
- $model = new LedgerWalletModel();
- foreach ($paths as $kk=>$item) {
- if($kk== 1){
- $model->changeWalletAccount($item, $token, $pv, $model::Community, $uid);
- }else{
- //间接推荐有效会员大于层级
- if(self::where('parent_id', $item)->where('rwa_num','>', 0)->count() >= $kk){
- $model->changeWalletAccount($item, $token, $pv, $model::Community, $uid);
- }
- }
- }
- }
- }
- }
|