257 lines
8.8 KiB
PHP
257 lines
8.8 KiB
PHP
<?php
|
||
|
||
namespace addon\futures\model;
|
||
use addon\futures\model\order\FuturesOrderCreate as OrderCreateModel;
|
||
use app\model\BaseModel;
|
||
use app\model\system\Pay as PayModel;
|
||
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{
|
||
$futuresModel = new Futures();
|
||
$time = time();
|
||
for($i=0;$i<$info['order_num'];$i++){
|
||
$futuresModel->add([
|
||
'site_id' => $this->site_id,
|
||
'seller_uid' => $memberId,
|
||
'member_id' => $memberId,
|
||
'goods_id' => (int)$info['goods_id'],
|
||
'total' => (int)$info['goods_num'],
|
||
'price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
|
||
'unit_price' => sprintf("%.2f",$info['unit_price'] * $info['goods_num']),
|
||
'status' => 1,
|
||
'created_time' => $time,
|
||
]);
|
||
}
|
||
return $this->success();
|
||
}catch(Exception $e){
|
||
return $this->error('',$e->getMessage());
|
||
}
|
||
}
|
||
/**
|
||
* 回购
|
||
* @return array
|
||
*/
|
||
public function buyBack(){
|
||
$nowTime = time() - strtotime("today");
|
||
$futuresModel = new Futures();
|
||
$basics = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
||
if($basics['auto_buyback'] == 0){
|
||
return $this->success('未达开启回购');
|
||
}
|
||
$status = 0;
|
||
foreach($basics['times'] as $times){
|
||
if($nowTime <= $times['jianlou_end_time'] && $nowTime >= $times['jianlou_end_time'] - $basics['auto_buyback_time'] * 60){// 配置在结束时间前多久开始回购
|
||
$status = 7;
|
||
break;
|
||
}
|
||
if($nowTime <= $times['miaosha_end_time'] && $nowTime >= $times['miaosha_end_time'] - $basics['auto_buyback_time'] * 60){// 配置在结束时间前多久开始回购
|
||
$status = 2;
|
||
break;
|
||
}
|
||
}
|
||
if($status == 0){
|
||
return $this->success('未达到回购时间');
|
||
}
|
||
$menberList = model('futures_user')->getList([['is_special', '=', 1]]);
|
||
$futuresList = model('futures')->getList([
|
||
['status', '=', $status],
|
||
['release_time', '<', time()]
|
||
]);
|
||
$log = [];
|
||
foreach($futuresList as $futures){
|
||
//创建订单
|
||
$order_create = new OrderCreateModel();
|
||
$data = [
|
||
'futures_id' => $futures[ 'id' ],
|
||
'member_id' => $menberList[0]['member_id'],
|
||
'site_id' => $this->site_id,//站点id
|
||
'order_from' => 'weapp',
|
||
'order_from_name' => '微信小程序',
|
||
'is_balance' => 0,//是否使用余额
|
||
'buyer_message' => '',
|
||
'delivery' => [],
|
||
'coupon' => [],
|
||
'member_address' => [],
|
||
'latitude' => '',
|
||
'longitude' => '',
|
||
'is_invoice' => 0,
|
||
'invoice_type' => 0,
|
||
'invoice_title' => '',
|
||
'taxpayer_number' => '',
|
||
'invoice_content' => '',
|
||
'invoice_full_address' => '',
|
||
'is_tax_invoice' => 0,
|
||
'invoice_email' => '',
|
||
'invoice_title_type' => 1,
|
||
'buyer_ask_delivery_time' => '',
|
||
'form_data' => [],
|
||
'goods_sku_list' => [],
|
||
'sku_id' => '',
|
||
];
|
||
$res = $order_create->create($data);
|
||
//支付订单
|
||
$pay_type = 'wechatpay';
|
||
$out_trade_no = $res['data'];
|
||
$app_type = 'weapp';
|
||
$scene = 0;
|
||
$is_balance = 1;
|
||
$hb_fq_num = 0;
|
||
$pay = new PayModel();
|
||
$info = $pay->pay($pay_type, $out_trade_no, $app_type, $menberList[0]['member_id'], null, $is_balance, $scene, $hb_fq_num);
|
||
$log[] = [
|
||
'create_order' => $res,
|
||
'pay' => $info
|
||
];
|
||
}
|
||
return $this->success([
|
||
'member_list' => $menberList,
|
||
'futures_list' => $futuresList,
|
||
'log' => $log
|
||
]);
|
||
}
|
||
/**
|
||
* Common: 获取违规记录
|
||
* Author: wu-hui
|
||
* Time: 2023/03/23 13:46
|
||
* @return array
|
||
* @throws \think\db\exception\DbException
|
||
*/
|
||
public function violationRecords(){
|
||
// 参数获取
|
||
$page = input('page',1);
|
||
$pageSize = input('page_size',PAGE_LIST_ROWS);
|
||
$memberId = input('member_id');
|
||
// 条件生成
|
||
$where = [
|
||
['site_id','=',$this->site_id],
|
||
['member_id','=',$memberId]
|
||
];
|
||
// 列表获取
|
||
$field = [
|
||
'id',
|
||
'created_time'
|
||
];
|
||
$result = Db::name('futures_user_violation_records')
|
||
->field($field)
|
||
->where($where)
|
||
->order(['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();
|
||
}
|
||
|
||
|
||
} |