155 lines
4.9 KiB
PHP
155 lines
4.9 KiB
PHP
<?php
|
|
namespace Yunshop\CulturalSpace\models;
|
|
use app\common\facades\Setting;
|
|
use app\common\models\BaseModel;
|
|
use app\common\models\Member;
|
|
use app\common\models\UniAccount;
|
|
use app\common\services\income\IncomeService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CulturalSpaceAreaBonus extends BaseModel
|
|
{
|
|
public $table = 'yz_cultural_space_area_bonus';
|
|
public $timestamps = true;
|
|
public $casts = [
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
'updated_at' => 'datetime:Y-m-d H:i:s'
|
|
];
|
|
protected $fillable = [
|
|
'uniacid',
|
|
'uid',
|
|
'cycle_id',
|
|
'area_amount',
|
|
'area_rate',
|
|
'get_amount',
|
|
'status',
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
/**
|
|
* Common: 获取信息列表
|
|
* Author: wu-hui
|
|
* Time: 2024/01/05 16:52
|
|
* @param $search
|
|
* @return mixed
|
|
*/
|
|
public function getList($search){
|
|
// 条件生成
|
|
$where = [];
|
|
if ($search['uid'] > 0) $where[] = ['uid', '=', $search['uid']];
|
|
if ($search['cycle_id'] > 0) $where[] = ['cycle_id', '=', $search['cycle_id']];
|
|
if($search['status'] >= 0 && $search['status'] != '') $where[] = ['status','=',(int)$search['status']];
|
|
// 查询model
|
|
return self::uniacid()
|
|
->where($where)
|
|
->with([
|
|
'member' => function ($query) {
|
|
$query->select(['uid', 'nickname', 'realname', 'avatar']);
|
|
},
|
|
'cycle' => function ($query) {
|
|
$query->select(['id', 'total_price', 'allocation_price', 'total_amount']);
|
|
}
|
|
])
|
|
->orderBy('id', 'DESC')
|
|
->paginate(10)
|
|
->toArray();
|
|
}
|
|
/**
|
|
* Common: 用户持有统计
|
|
* Author: wu-hui
|
|
* Time: 2024/01/05 17:20
|
|
* @param $search
|
|
* @return mixed
|
|
*/
|
|
public function getHoldList($search){
|
|
// 条件生成
|
|
$where = [];
|
|
if ($search['uid'] > 0) $where[] = ['uid', '=', $search['uid']];
|
|
// 查询model
|
|
return self::uniacid()
|
|
->select([
|
|
'uid',
|
|
DB::raw('sum(get_amount) as total_get_amount'),
|
|
])
|
|
->where($where)
|
|
->with([
|
|
'member' => function ($query) {
|
|
$query->select(['uid', 'nickname', 'realname', 'avatar']);
|
|
}
|
|
])
|
|
->orderBy('uid', 'DESC')
|
|
->paginate(10)
|
|
->toArray();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Common: 市场津贴结算
|
|
* Author: wu-hui
|
|
* Time: 2024/01/05 17:11
|
|
*/
|
|
public function bonusSettlement(){
|
|
set_time_limit(0);
|
|
DB::beginTransaction();
|
|
try{
|
|
// 循环平台 进行处理
|
|
$uniAccount = UniAccount::getEnable() ?: [];
|
|
foreach ($uniAccount as $u) {
|
|
Setting::$uniqueAccountId = \YunShop::app()->uniacid = $u->uniacid;
|
|
// 获取未结算列表
|
|
$list = self::uniacid()
|
|
->select(['id','uid','get_amount'])
|
|
->where('status',0)
|
|
->get()
|
|
->toArray();
|
|
if($list){
|
|
// 循环处理数据
|
|
$incomeData = [];
|
|
foreach($list as $item){
|
|
$incomeData[] = [
|
|
'uniacid' => \YunShop::app()->uniacid,
|
|
'member_id' => $item['uid'],
|
|
'amount' => $item['get_amount'],
|
|
'detail' => '',
|
|
'dividend_table_id' => $item['id'],
|
|
'dividend_code' => IncomeService::CULTURAL_SPACE_AREA_BONUS,
|
|
'order_sn' => '',
|
|
];
|
|
}
|
|
IncomeService::insertIncome($incomeData);
|
|
// 修改为已经结算
|
|
$ids = array_column($list,'id');
|
|
self::whereIn('id',$ids)->update([
|
|
'status' => 1
|
|
]);
|
|
}
|
|
}
|
|
DB::commit();
|
|
}catch(\Exception $e){
|
|
\Log::debug('--- 文创空间 - 市场津贴结算 - 错误:'.$e->getMessage());
|
|
DB::rollBack();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Common: 一对一关联 用户信息
|
|
* Author: wu-hui
|
|
* Time: 2024/01/05 16:49
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function member(){
|
|
return $this->hasOne(Member::class, 'uid', 'uid');
|
|
}
|
|
/**
|
|
* Common: 一对一关联 周期信息
|
|
* Author: wu-hui
|
|
* Time: 2024/01/05 16:51
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function cycle(){
|
|
return $this->hasOne(CulturalSpaceAreaCycle::class, 'id', 'cycle_id');
|
|
}
|
|
}
|