|
@@ -106,7 +106,7 @@ class Plantask extends Controller
|
|
$intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');
|
|
$intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');
|
|
if($intro_uid){
|
|
if($intro_uid){
|
|
$bili = config('site.orderpaid_zhitui_bili') ?: 5;
|
|
$bili = config('site.orderpaid_zhitui_bili') ?: 5;
|
|
- $score = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
|
|
|
|
|
|
+ $score = bcdiv(bcmul($order['order_price'],$bili,2),100,2);
|
|
if($score > 0){
|
|
if($score > 0){
|
|
$rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'score',$score,3,'直推代理奖励','unishop_order',$order['id']);
|
|
$rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'score',$score,3,'直推代理奖励','unishop_order',$order['id']);
|
|
if($rs_wallet['status'] === false){
|
|
if($rs_wallet['status'] === false){
|
|
@@ -121,7 +121,7 @@ class Plantask extends Controller
|
|
$top_uid = Db::name('user')->where('id',$intro_uid)->value('intro_uid');
|
|
$top_uid = Db::name('user')->where('id',$intro_uid)->value('intro_uid');
|
|
if($top_uid){
|
|
if($top_uid){
|
|
$bili = config('site.orderpaid_jiantui_bili') ?: 1;
|
|
$bili = config('site.orderpaid_jiantui_bili') ?: 1;
|
|
- $score = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
|
|
|
|
|
|
+ $score = bcdiv(bcmul($order['order_price'],$bili,2),100,2);
|
|
if($score > 0){
|
|
if($score > 0){
|
|
$rs_wallet = $walletmodel->lockChangeAccountRemain($top_uid,'score',$score,4,'间推代理奖励','unishop_order',$order['id']);
|
|
$rs_wallet = $walletmodel->lockChangeAccountRemain($top_uid,'score',$score,4,'间推代理奖励','unishop_order',$order['id']);
|
|
if($rs_wallet['status'] === false){
|
|
if($rs_wallet['status'] === false){
|
|
@@ -147,4 +147,182 @@ class Plantask extends Controller
|
|
echo '成功';
|
|
echo '成功';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //自动结算10日前订单
|
|
|
|
+ public function auto_jiesuan_order(){
|
|
|
|
+ $nowtime = time();
|
|
|
|
+ $toweek = date('w',$nowtime);
|
|
|
|
+ if($toweek == 0){
|
|
|
|
+ //周日不结算(自动到下周一结算)
|
|
|
|
+ echo '周日不结算';
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tendays_ago = $this->jiesuan_tendays_ago();
|
|
|
|
+ //
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $order_map = [
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ 'have_paid' => ['lt',$tendays_ago],
|
|
|
|
+ 'jiesuantime' => 0,
|
|
|
|
+ ];
|
|
|
|
+ $order = Db::name('unishop_order')->where($order_map)->where('have_paid','gt',0)->order('id asc')->lock(true)->find();
|
|
|
|
+
|
|
|
|
+ //为上级做贡献,找到上级
|
|
|
|
+ $intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');
|
|
|
|
+ if(empty($intro_uid)){
|
|
|
|
+ //没有上级,结束
|
|
|
|
+ Db::name('unishop_order')->where('id',$order['id'])->update(['jiesuantime'=>time()]);
|
|
|
|
+ Db::commit();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取直推人数
|
|
|
|
+ $intro_number = Db::name('user')->where('intro_uid',$intro_uid)->count();
|
|
|
|
+
|
|
|
|
+ //获取业绩
|
|
|
|
+ $yeji = $this->jiesuan_yeji($intro_uid);
|
|
|
|
+
|
|
|
|
+ //确定代理商等级,拿对应比例
|
|
|
|
+ $rule = $this->jiesuan_daili_level($intro_number,$yeji);
|
|
|
|
+ if($rule['bili'] == 0){
|
|
|
|
+ //达不到第一级
|
|
|
|
+ Db::name('unishop_order')->where('id',$order['id'])->update(['jiesuantime'=>time()]);
|
|
|
|
+ Db::commit();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //给直推
|
|
|
|
+ $score = bcdiv(bcmul($order['order_shouyi'],$rule['bili'],2),100,2);
|
|
|
|
+ if($score > 0){
|
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($intro_uid,'score',$score,6,$rule['level'].'级代理','unishop_order',$order['id']);
|
|
|
|
+ if($rs_wallet['status'] === false){
|
|
|
|
+ echo $rs_wallet['msg'];
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //给间推
|
|
|
|
+ if($rule['level'] == 1){ //一级代理要有间推
|
|
|
|
+
|
|
|
|
+ $two_intro_uid = Db::name('user')->where('id',$intro_uid)->value('intro_uid');//上上级id
|
|
|
|
+ if($two_intro_uid > 0){
|
|
|
|
+ $two_intro_count = Db::name('user')->where('intro_uid',$two_intro_uid)->count();//上上级的直推
|
|
|
|
+ if($two_intro_count >= $rule['intronum']){
|
|
|
|
+ $score_2 = $score;//目前是一样的,不再次计算了
|
|
|
|
+ if($score_2 > 0){
|
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($two_intro_uid,'score',$score_2,7,$rule['level'].'级代理(间推)','unishop_order',$order['id']);
|
|
|
|
+ if($rs_wallet['status'] === false){
|
|
|
|
+ echo $rs_wallet['msg'];
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //标记为结算
|
|
|
|
+ $jiesuan = Db::name('unishop_order')->where('id',$order['id'])->update(['jiesuantime'=>$nowtime]);
|
|
|
|
+ if($jiesuan === false){
|
|
|
|
+ echo '修改状态失败';
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+ //批发的都卖出
|
|
|
|
+ $pifa = Db::name('unishop_order_product')->where('order_id',$order['id'])->update(['pifa_status'=>1]);
|
|
|
|
+ if($pifa === false){
|
|
|
|
+ echo '修改状态失败2';
|
|
|
|
+ Db::rollback();
|
|
|
|
+ exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ }
|
|
|
|
+ //获取业绩
|
|
|
|
+ private function jiesuan_yeji($user_id){
|
|
|
|
+ return 150000;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //确认代理等级及规则
|
|
|
|
+ private function jiesuan_daili_level($intronum,$yeji){
|
|
|
|
+ $data = [
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 0,
|
|
|
|
+ 'yeji' => 0,
|
|
|
|
+ 'bili' => 0,
|
|
|
|
+ 'level' => 0,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 5,
|
|
|
|
+ 'yeji' => 150000,
|
|
|
|
+ 'bili' => 1,
|
|
|
|
+ 'level' => 1,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 10,
|
|
|
|
+ 'yeji' => 500000,
|
|
|
|
+ 'bili' => 2,
|
|
|
|
+ 'level' => 2,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 15,
|
|
|
|
+ 'yeji' => 1000000,
|
|
|
|
+ 'bili' => 3,
|
|
|
|
+ 'level' => 3,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 20,
|
|
|
|
+ 'yeji' => 3000000,
|
|
|
|
+ 'bili' => 4,
|
|
|
|
+ 'level' => 4,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'intronum' => 25,
|
|
|
|
+ 'yeji' => 6000000,
|
|
|
|
+ 'bili' => 5,
|
|
|
|
+ 'level' => 5,
|
|
|
|
+ ],
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $return = $data[0]; //默认第0个
|
|
|
|
+ foreach($data as $key => $rule){
|
|
|
|
+ if($intronum >= $rule['intronum'] && $yeji >= $rule['bili']){
|
|
|
|
+ $return = $rule;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //结算要按10天算
|
|
|
|
+ private function jiesuan_tendays_ago(){
|
|
|
|
+
|
|
|
|
+ $nowtime = time();
|
|
|
|
+
|
|
|
|
+ /*if(input('date','')){
|
|
|
|
+ $nowtime = strtotime(input('date',''));
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ $today = strtotime(date('Y-m-d',$nowtime));
|
|
|
|
+
|
|
|
|
+ $toweek = date('w',$nowtime);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $enum = [
|
|
|
|
+ 1 => 11,
|
|
|
|
+ 2 => 11,
|
|
|
|
+ 3 => 11,
|
|
|
|
+ 4 => 10,
|
|
|
|
+ 5 => 10,
|
|
|
|
+ 6 => 10,
|
|
|
|
+ 0 => 10, //这一天没人结算
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $rs = $today - ($enum[$toweek] * 86400);
|
|
|
|
+// dump(date('Y-m-d',$rs));
|
|
|
|
+
|
|
|
|
+ return $rs;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|