| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | <?phpnamespace app\index\controller;use think\Controller;use think\Db;use app\common\model\Wallet;class Plantask extends Controller{    public function index()    {        exit;    }    //推荐奖励    //订单支付回调之后的任务,每分钟运行    //烧伤    public function auto_order_paid(){        $map = [            'status' => 1,            'have_paid' => ['gt',0],            'paidtasktime' => 0,        ];        Db::startTrans();        $order_list = Db::name('unishop_order')->where($map)->order('id asc')->limit(10)->lock(true)->select();        if(empty($order_list)){            echo '没有数据';            Db::rollback();            exit;        }        $walletmodel = new Wallet();        foreach($order_list as $key => $order){            //本金立即到账给入金者            if($order['order_benjin'] > 0){                $remark = '本金:'.$order['order_benjin'];                $rs_wallet = $walletmodel->lockChangeAccountRemain($order['user_id'],'score',$order['order_benjin'],5,$remark,'unishop_order',$order['id'],$order['user_id']);                if($rs_wallet['status'] === false){                    echo $rs_wallet['msg'];                    Db::rollback();                    exit;                }            }            //直推代理商获益            $intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');            if($intro_uid){                //直推的第一单金额,烧伤                $map = [                    'status' => 1,                    'have_paid' => ['gt',0],                    'user_id' => $intro_uid,                ];                $first_order = Db::name('unishop_order')->where($map)->order('have_paid asc')->value('order_price');                $first_order = $first_order ?: 0;                $jishu = $order['order_price'];                $remark_shaoshang = '';                if($first_order < $order['order_price']){                    $jishu = $first_order;                    $remark_shaoshang = '(烧伤)';                }                //奖励                $bili = config('site.orderpaid_zhitui_bili') ?: 5;                $score = bcdiv(bcmul($jishu,$bili,0),100,0);                if($score > 0){                    $rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'score',$score,3,'直推代理奖励'.$remark_shaoshang,'unishop_order',$order['id'],$order['user_id']);                    if($rs_wallet['status'] === false){                        echo $rs_wallet['msg'];                        Db::rollback();                        exit;                    }                    $rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'shouyi',$score,31,'直推代理奖励'.$remark_shaoshang,'unishop_order',$order['id'],$order['user_id']);                    if($rs_wallet['status'] === false){                        echo $rs_wallet['msg'];                        Db::rollback();                        exit;                    }                }            }            //订单完成            $rs_order = Db::name('unishop_order')->where('id',$order['id'])->update(['paidtasktime'=>time()]);            if($rs_order === false){                echo '更新失败';                Db::rollback();                exit;            }            //循环结束        }        Db::commit();        echo '成功'.count($order_list);    }    //总代奖励    //自动结算10日前订单,每分钟运行    public function auto_jiesuan_order(){        $nowtime = time();        /*$toweek  = date('w',$nowtime);        if($toweek == 0){            //周日不结算(自动到下周一结算)            echo '周日不结算';            exit;        }*/        $tendays_ago = jiesuan_tendays_ago();        //        Db::startTrans();        $order_map = [            'status'      => 1,            'have_paid'   => ['lt',$tendays_ago],            'jiesuantime' => 0,        ];        $order_list = Db::name('unishop_order')->where($order_map)->where('have_paid','gt',0)->order('id asc')->lock(true)->limit(10)->select();        if(empty($order_list)){            echo '没有数据';            Db::rollback();            exit;        }        foreach($order_list as $key => $order){            //买家得到收益,两个数据同步加            if($order['order_shouyi'] > 0){                $shouyi = bcsub($order['order_shouyi'],$order['order_benjin']);  //总收益 - 本金 = 可提现收益                $remark = '收益:'.$shouyi;                if($shouyi > 0){                    $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'score',$shouyi,50,$remark,'unishop_order',$order['id'],$order['user_id']);                    if($rs_wallet['status'] === false){                        echo $rs_wallet['msg'];                        Db::rollback();                        exit;                    }                    $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'shouyi',$shouyi,51,$remark,'unishop_order',$order['id'],$order['user_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;            }            //循环结束            echo '完成'.$order['id'];        }        Db::commit();        echo '成功'.count($order_list);    }}
 |