admin/addon/futures/model/User.php

139 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace addon\futures\model;
use app\model\BaseModel;
use think\Exception;
use think\facade\Db;
class User extends BaseModel{
protected int $site_id;
public function __construct($site_id){
$this->site_id = (int)$site_id;
}
/**
* Common: 获取用户列表
* Author: wu-hui
* Time: 2023/02/23 9:33
* @return array
* @throws \think\db\exception\DbException
*/
public function getList(){
// 参数获取
$page = input('page',1);
$pageSize = input('page_size',PAGE_LIST_ROWS);
$nickname = (string)input('nickname','');
$status = (int)input('status',0);// 是否为特殊身份2=不是1=是
// 条件生成
$where = [
['m.site_id','=',$this->site_id],
['m.is_delete','=',0]
];
if($nickname) $where[] = ['m.username|m.nickname',"like","%{$nickname}%"];
if($status > 0) $where[] = ['fu.is_special',"=",($status == 2 ? 0 : 1 )];//是否为特殊身份0=不是1=是
// 列表获取
$field = [
'fu.id',
'm.member_id',
'IFNULL(fu.is_special,0) as is_special',
'IFNULL(fu.violation_num,0) as violation_num',
'IFNULL(fu.total_violation_num,0) as total_violation_num',
'IFNULL(fu.punish_time,0) as punish_time',
'IFNULL(fu.business_num,0) as business_num',
'IFNULL(fu.total_business_num,0) as total_business_num',
'm.username',
'm.nickname',
'm.headimg',
];
$result = Db::name('member')
->alias('m')
->join('futures_user fu','fu.member_id = m.member_id','left')
->field($field)
->where($where)
->order(['m.member_id'=>'DESC'])
->paginate(['list_rows' => $pageSize,'page' => $page]);
if($result) {
$result = $result->toArray();
$list = [
'count' => $result['total'],
'list' => $result['data'],
'page_count' => $result['last_page'],
];
return $this->success($list);
}
return $this->success();
}
/**
* Common: 特殊身份变更
* Author: wu-hui
* Time: 2023/02/23 9:24
* @return array
*/
public function changeSpecial(){
// 参数获取
$memberId = (int)input('member_id',0);
$isSpecial = (int)input('is_special',0);
// 修改信息
try{
$data['is_special'] = $isSpecial == 1 ? 0 : 1;
$isHas = (int)Db::name('futures_user')
->where('member_id',$memberId)
->value('id');
if($isHas > 0) Db::name('futures_user')->where('member_id',$memberId)->update($data);
else{
$data['member_id'] = $memberId;
$data['site_id'] = $this->site_id;
$data['created_time'] = time();
Db::name('futures_user')->insert($data);
}
return $this->success();
}catch(Exception $e){
return $this->error('',$e->getMessage());
}
}
/**
* Common: 赠送商品
* Author: wu-hui
* Time: 2023/02/23 13:58
* @return array
*/
public function sendGoods(){
// 获取参数信息
$info = (array)input('info',[]);
$memberId = (int)input('member_id',0);
if($memberId <= 0) return $this->error('','用户信息错误!');
// 赠送商品
try{
$time = time();
$insert = [];
for($i=0;$i<$info['order_num'];$i++){
$insert[] = [
'site_id' => $this->site_id,
'seller_uid' => $memberId,
'goods_id' => (int)$info['goods_id'],
'total' => (int)$info['goods_num'],
'unit_price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
'status' => 1,
'created_time' => $time,
];
}
Db::name('futures')->insertAll($insert);
return $this->success();
}catch(Exception $e){
return $this->error('',$e->getMessage());
}
}
}