TaskSystem/app/common/logic/finance/ShareProfit.php
2023-08-17 15:30:58 +08:00

83 lines
3.5 KiB
PHP

<?php
namespace app\common\logic\finance;
use app\common\enum\user\AccountLogEnum;
use app\common\logic\AccountLogLogic;
use app\common\model\Company;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\user\User;
use think\facade\Db;
use think\facade\Log;
class ShareProfit
{
public function first($data,$company)
{
if($company['day_count']<=$data['proportion_one']){
$proportion=$data['proportion_one'];
}else{
$proportion=$data['proportion_two'];
}
//总金额除以2等于不可提现账号金额和收益
$master_maoney=bcdiv($data['money'],2,2);
//收益的百分之25为负责人的收益其余为成员的平分收益
$master_maoney_user=bcdiv($master_maoney,2,2);
//公司账户预存金
$company_money=$master_maoney;
//成员数量
$userAll=User::where('company_id',$data['company_id'])->where('admin_id',0)->field('id,user_money')->select();
$yser_all_count=count($userAll);
$member_maoney_user=bcdiv($master_maoney_user,$yser_all_count,2);
//负责人
Db::startTrans();
try {
$arr=[$company['user_id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC,$master_maoney_user,$data['sn'],$data['msg'].'获得收益'.$master_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->master($arr);
$arr=[$company['user_id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC,$master_maoney_user,$data['sn'],$data['msg'].'获得账户余额'.$master_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->master($arr);
//成员
foreach ($userAll as $key => $value) {
$arr=[$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC,$member_maoney_user,$data['sn'],$data['msg'].'获得收益'.$member_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->member($arr);
$arr=[$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC,$member_maoney_user,$data['sn'],$data['msg'].'获得账户余额'.$member_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->member($arr);
}
//公司
if($data['status']==1){
Company::where('id',$data['company_id'])->inc('deposit',$master_maoney)->inc('company_money',$master_maoney)->update();
TaskSchedulingPlan::where('id',$data['id'])->update(['is_pay'=>1]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error('任务结算失败:'.$e->getMessage());
return false;
}
}
/**负责人的分润
* @param $data
*/
private function master($data){
if($data[7]==1){
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update();
}
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){
if($data[7]==1){
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update();
}
return AccountLogLogic::add($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]);
}
}