206 lines
8.3 KiB
PHP
206 lines
8.3 KiB
PHP
<?php
|
||
|
||
namespace addon\futures\model;
|
||
use addon\futures\model\order\FuturesOrderCreate as OrderCreateModel;
|
||
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{
|
||
$futuresModel = new Futures();
|
||
$time = time();
|
||
// $insert = [];
|
||
for($i=0;$i<$info['order_num'];$i++){
|
||
$futuresModel->add([
|
||
'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,
|
||
]);
|
||
// $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());
|
||
}
|
||
}
|
||
// 回收
|
||
public function buyBack(){
|
||
$nowTime = time() - strtotime("today");
|
||
$futuresModel = new Futures();
|
||
$basics = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
|
||
$status = 0;
|
||
foreach($basics['times'] as $times){
|
||
if($nowTime <= $times['jianlou_end_time'] && $nowTime >= $times['jianlou_end_time'] - 5 * 60){//TODO 配置在结束时间前多久开始回购
|
||
$status = 7;
|
||
break;
|
||
}
|
||
|
||
if($nowTime <= $times['miaosha_end_time'] && $nowTime >= $times['miaosha_end_time'] - 5 * 60){//TODO 配置在结束时间前多久开始回购
|
||
$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()]
|
||
]);
|
||
foreach($futuresList as $futures){
|
||
//创建订单
|
||
$order_create = new OrderCreateModel();
|
||
$data = [
|
||
'futures_id' => $futures[ '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' => isset($this->params[ 'delivery' ]) && !empty($this->params[ 'delivery' ]) ? json_decode($this->params[ 'delivery' ], true) : [],
|
||
'coupon' => isset($this->params[ 'coupon' ]) && !empty($this->params[ 'coupon' ]) ? json_decode($this->params[ 'coupon' ], true) : [],
|
||
'member_address' => isset($this->params[ 'member_address' ]) && !empty($this->params[ 'member_address' ]) ? json_decode($this->params[ 'member_address' ], true) : [],
|
||
|
||
'latitude' => $this->params[ 'latitude' ] ?? '',
|
||
'longitude' => $this->params[ 'longitude' ] ?? '',
|
||
|
||
'is_invoice' => $this->params[ 'is_invoice' ] ?? 0,
|
||
'invoice_type' => $this->params[ 'invoice_type' ] ?? 0,
|
||
'invoice_title' => $this->params[ 'invoice_title' ] ?? '',
|
||
'taxpayer_number' => $this->params[ 'taxpayer_number' ] ?? '',
|
||
'invoice_content' => $this->params[ 'invoice_content' ] ?? '',
|
||
'invoice_full_address' => $this->params[ 'invoice_full_address' ] ?? '',
|
||
'is_tax_invoice' => $this->params[ 'is_tax_invoice' ] ?? 0,
|
||
'invoice_email' => $this->params[ 'invoice_email' ] ?? '',
|
||
'invoice_title_type' => $this->params[ 'invoice_title_type' ] ?? 0,
|
||
'buyer_ask_delivery_time' => $this->params[ 'buyer_ask_delivery_time' ] ?? '',
|
||
'form_data' => isset($this->params['form_data']) && !empty($this->params['form_data']) ? json_decode($this->params['form_data'], true) : [],
|
||
'goods_sku_list' => !empty($this->params['goods_sku_list']) ? json_decode($this->params['goods_sku_list'], true) : [],
|
||
'sku_id' => isset($this->params['sku_id']) ? $this->params['sku_id'] : '',
|
||
];
|
||
$res = $order_create->create($data);
|
||
}
|
||
|
||
}
|
||
} |