This commit is contained in:
yaooo 2023-11-16 11:03:05 +08:00
commit a84d83fa14
5 changed files with 316 additions and 10 deletions

View File

@ -4,11 +4,17 @@ namespace app\adminapi\controller\approve;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\approve\ApproveLists;
use app\common\enum\user\AccountLogEnum;
use app\common\logic\AccountLogLogic;
use app\common\logic\task\TaskLogic;
use app\common\model\Approve;
use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
use app\common\model\task\Task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use app\common\model\user\UserAccountLog;
use think\facade\Db;
class ApproveController extends BaseAdminController
@ -22,6 +28,11 @@ class ApproveController extends BaseAdminController
{
return $this->success('成功',(new ApproveLists())->lists2());
}
public function lists3()
{
return $this->success('成功',(new ApproveLists())->lists3());
}
public function audit()
{
try {
@ -161,4 +172,205 @@ class ApproveController extends BaseAdminController
]);
}
/**
* 股金任务审批
*/
public function shareholderMoneyTaskAudit()
{
// try {
$params = $this->request->param(); // id check_status remark
$approve = Approve::find($params['id']);
if (!empty($approve)) {
$this->fail('数据不存在');
}
// 拒绝通过 要让用户今天可以继续做任务
if ($params['check_status'] == 3) {
$this->refuse1($params, $approve);
}
if ($params['check_status'] == 2) {
$this->pass1($approve, $params);
}
// } catch (\Exception $e) {
// return $this->fail($e->getMessage());
// }
}
private function refuse1($params, $approve)
{
$approve->check_status = $params['check_status'];
$approve->remark = $params['remark'];
$approve->update_time = time();
$approve->save();
}
private function pass1($approve, $params)
{
Db::startTrans();
// 任务
$task = Task::find($approve['task_id']);
if ($task['status'] == 2) {
$task->status = 3;
$task->save();
}
// 小组服务公司股金上交
if ($approve->type == Approve::APPROVE_TYPE_10) {
// 上交股金的公司
$subordinateCompany = Company::where(['id'=>$approve->department_id])->find();
// 接收股金的公司
$parentCompany = Company::where(['village'=>$subordinateCompany['village'], 'company_type'=>17])->find();
}
$amount = $approve->amount; // 上交股金金额
$subordinateCompany->shareholder_money = $amount;
$subordinateCompany->save();
// 添加股金入股记录
$sharecapitalChangeLogInsertId = $this->addConpanyAccountLog($subordinateCompany, $parentCompany, $amount);
$approve->check_status = 2;
$approve->update_time = time();
$approve->business_id = $sharecapitalChangeLogInsertId; // 灵活运用业务主键id
$approve->remark = $params['remark'];
$approve->save();
// 任务结算
if ($approve->type == Approve::APPROVE_TYPE_10) {
$taskSchedulingPaln = TaskSchedulingPlan::where(['task_id' => $task->id])
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 18)
->where('is_pay',0)
->with(['template_info'])
->select()
->toArray()[0];
$taskInfo = $task->toArray();
$this->taskSettlement($taskInfo, $subordinateCompany, $taskSchedulingPaln);
}
Db::commit();
return $this->success('成功');
}
private function addConpanyAccountLog($subordinateCompany, $parentCompany, $amount)
{
$sharecapitalChangeLogData = [
'subordinate_company_id' => $subordinateCompany['id'],
'parent_company_id' => $parentCompany['id'],
'amount' => $amount,
'create_time' => time(),
'update_time' => time(),
];
$sharecapitalChangeLogInsertId = Db::name('company_sharecapital_change_log')->insertGetId($sharecapitalChangeLogData);
// 上交股金公司股金变更 + 公司股金减少记录
$leftAmount = bcsub($subordinateCompany['shareholder_money'], $amount, 2);
Company::where('id', $subordinateCompany['company_id'])->save(['shareholder_money'=> $leftAmount]);
$company_log1 = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $subordinateCompany['id'],
'change_object' => CompanyAccountLog::SHAREHOLDER, // 变动对象 1余额 2股金
'change_type' => CompanyAccountLog::SHAREHOLDER_DEC_DEPOSIT, //变动类型
'action' => CompanyAccountLog::DEC, //1-增加 2-减少
'left_amount' => $leftAmount, //变动后数量
'change_amount' => $amount, //变动数量
'extend' => json_encode(['company_sharecapital_change_log_id' => $sharecapitalChangeLogInsertId]),
'status' => 1,
];
CompanyAccountLog::create($company_log1);
// 接收股金公司股金变更 + 公司股金增加记录
$addAmount = bcadd($parentCompany['shareholder_money'], $amount, 2);
Company::where('id', $parentCompany['id'])->save(['shareholder_money'=>$addAmount]);
// 公司账户变动记录
$company_log2 = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $parentCompany['id'],
'change_object' => CompanyAccountLog::SHAREHOLDER, // 变动对象 1余额 2股金
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY, //变动类型
'action' => CompanyAccountLog::INC, //1-增加 2-减少
'left_amount' => $addAmount, //变动后数量
'change_amount' => $amount, //变动数量
'extend' => json_encode(['company_sharecapital_change_log_id' => $sharecapitalChangeLogInsertId]),
'status' => 1,
];
CompanyAccountLog::create($company_log2);
return $sharecapitalChangeLogInsertId;
}
public function taskSettlement($data, $company, $datas = [])
{
$proportion = 0;
$remark = '来自任务【' . $datas['template_info']['title'] . '】,';
//总金额除以2等于不可提现账号金额和收益
$master_money = bcdiv($data['money'], 2, 2);
//收益的百分之25为负责人的收益其余为成员的平分收益
$master_money_user = bcdiv($master_money, 2, 2);
//成员数量
$userAll = User::where('company_id', $data['company_id'])->where('admin_id', 0)->field('id,user_money')->select();
$yser_all_count = count($userAll);
$member_money_user = bcdiv($master_money_user, $yser_all_count, 2);
//负责人
$arr = [$company['user_id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $master_money_user, $datas['sn'], $remark . '获得收益' . $master_money_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->master($arr);
$arr_two = [$company['user_id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $master_money_user, $datas['sn'], $remark. '获得账户余额' . $master_money_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->Account($arr_two);
//成员
foreach ($userAll as $value) {
$arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $member_money_user, $datas['sn'], $remark . '获得收益' . $member_money_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->member($arr);
$arr_two = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $member_money_user, $datas['sn'], $remark. '获得账户余额' . $member_money_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->Account($arr_two);
}
//公司
$deposit_count = bcadd($company['deposit'], $master_money, 2);
$this->AccountLog($data['company_id'], $deposit_count, $master_money);
$company_money_count = bcadd($company['company_money'], $master_money, 2);
$this->AccountLog($data['company_id'], $company_money_count, $master_money);
Company::where('id', $data['company_id'])->update(['deposit' => Db::raw('deposit+' . $master_money), 'company_money' => Db::raw('company_money+' . $master_money)]);
}
public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1)
{
$company_log = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $companyId,
'change_object' => $change_object, //变动对象
'change_type' => $change_type, //变动类型
'action' => $action, //1-增加 2-减少
'left_amount' => $left_amount, //变动后数量
'change_amount' => $changeAmount, //变动数量
'status' => 1,
];
CompanyAccountLog::create($company_log);
}
/**负责人的分润
* @param $data
*/
private function master($data)
{
User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]);
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
/**成员分润
* @param $data
*/
private function member($data)
{
User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]);
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
private function Account($data)
{
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
}

View File

@ -48,7 +48,6 @@ class ApproveLists extends BaseAdminDataLists implements ListsSearchInterface
return Admin::where(['id' => $data['check_admin_ids']])->value('name');
})
->withAttr('company_name',function($value,$data){
$task = Task::where('id', $data['task_id'])->find();
return Company::where(['id' => $task['company_id']])->value('company_name');
})
@ -85,6 +84,40 @@ class ApproveLists extends BaseAdminDataLists implements ListsSearchInterface
];
}
public function lists3(): array
{
$list = Approve::where($this->searchWhere)
->where($this->queryWhere())
->with('task')
->field('*')
->append(['area_manager', 'company_a_name', 'company_b_name'], true)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->withAttr('area_manager',function($value,$data){
return Admin::where(['id' => $data['check_admin_ids']])->value('name');
})
->withAttr('company_b_name',function($value,$data){
$task = Task::where('id', $data['task_id'])->find();
return Company::where(['id' => $task['company_id']])->value('company_name');
})
->withAttr('company_a_name',function($value,$data){
$task = Task::where('id', $data['task_id'])->find();
$companyB = Company::where(['id' => $task['company_id']])->find();
return Company::where(['village' => $companyB['village'], 'company_type'=>17])->value('company_name');
})
->toArray();
$count = Approve::where($this->searchWhere)
->where($this->queryWhere())->count();
return [
'lists' => $list,
'count' => $count,
'page_no' => $this->pageNo,
'page_size' => $this->pageSize,
];
}
public function count(): int
{
return Approve::where($this->searchWhere)->count();

View File

@ -722,7 +722,10 @@ class TaskController extends BaseApiController
if (empty($task)) {
$this->fail('任务不存在');
}
$extend = ['is_commit'=>1, 'annex'=>$parmas['annex'], 'amount'=>$parmas['amount']];
$extend = json_decode($task->extend, true);
$extend['is_commit'] = 1;
$extend['annex'] = $parmas['annex'];
$extend['amount'] = $parmas['amount'];
Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend), 'update_time' => time(), 'director_uid' => $this->userId]); // director_uid 指派人

View File

@ -87,12 +87,15 @@ class TaskInformationJob
$task_35 = Task::where('id', $data['task_id'])->field('director_uid,status,money,start_time,end_time')->with('director_info')->find();
if($task_35){
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
if($task_35['status']==3 && $data['template_info']['day_count']<=$day){
$name = $task_35['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task_35['money'];
$arr['company_account_type'] = 2;
}else{
// if($task_35['status']==3 && $data['template_info']['day_count']<=$day){
// $name = $task_35['director_info']['nickname'];
// $arr['status'] = 1;
// $arr['money'] = $task_35['money'];
// $arr['company_account_type'] = 2;
// }else{
if ($task_35['status'] == 3) {
return true;
}
/**
* 判断入股任务 单次类型 是否超时
* 未超时时刷新开始结束时间
@ -114,7 +117,7 @@ class TaskInformationJob
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
return false;
}
}
// }
}else{
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
return false;
@ -133,7 +136,7 @@ class TaskInformationJob
if($data['template_info']['day_count'] >= $day){
Task::where('id', $data['task_id'])->update(['status' =>5]);
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
Log::info( $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
return false;
}

View File

@ -272,4 +272,59 @@
->toArray();
return $this->success('请求成功',$data);
}
public function responsibleArea(): Json
{
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
}
$params = $this->request->post(['key','value','company_type']);
if (empty($params['key']) || empty($params['value']) || empty($params['company_type'])) {
return $this->fail('参数错误');
}
if ($params['key'] == 'city') {
$where[] = ['area', '=', 0];
}
if ($params['value'] == '') {
return $this->fail('参数不能为空');
}
$where[] = [$params['key'], '=', $params['value']];
$where[] = ['company_type', '=', $params['company_type']];
switch ($params['key']) {
case 'city':
// $geo_area=Db::name('geo_area')->where('city_code', '=', $parmas['value'])->column('area_code');
// $where[] = ['area', 'in', $geo_area];
break;
case 'area':
$street_code = Db::name('geo_street')->where('area_code', '=', $params['value'])->column('street_code');
$where[] = ['street', 'in', $street_code];
$where[] = ['village', '=', 0];
break;
case 'street':
$street_code = Db::name('geo_village')->where('street_code', '=', $params['value'])->column('village_code');
$where[] = ['village', 'in', $street_code];
$where[] = ['brigade', '=', 0];
break;
case 'village':
// $street_code = Db::name('geo_brigade')->where('street_code', '=', $parmas['value'])->column('village_code');
$where[] = ['village', '=', $params['value']];
// $where[] = ['brigade', '=', 0];
break;
}
$res = Company::where($where)->column('responsible_area');
foreach ($res as $k => $v) {
$res[$k] = explode(',', $v);
}
$data = [];
foreach ($res as $k => $v) {
foreach ($v as $kk => $vv) {
if ($vv != '') {
$data[] = $vv;
}
}
}
return $this->success('success', array_unique($data));
}
}