123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use app\utils\RedisUtil;
- class Demo extends Api
- {
-
-
-
-
-
- protected $noNeedLogin = ['*'];
-
- protected $noNeedRight = ['test2'];
-
- public function test()
- {
- $total_amount = 1000;
- $back_rate = 10;
- $user_id = 1;
- $shop_id = 1;
- $this->task_bill($total_amount,$back_rate,$user_id,$shop_id,'hotel_order');
- }
-
- public function task_bill($total_amount,$back_rate,$user_id,$shop_id,$table_name)
- {
-
- $amount = bcdiv(bcmul($total_amount,$back_rate,2),100,2);
-
-
-
- $shangwu_rate = config('site.back_shangwu');
- $shangwu_amount = bcdiv(bcmul($amount,$shangwu_rate,2),100,2);
- $shop_info = (new \app\common\business\PaymentBusiness)->getShopInfo($table_name,$shop_id);
- if($shop_info && $shop_info['invite_id'] && $shangwu_amount > 0){
-
- }
-
- $suoke_rate = config('site.back_suoke');
- $suoke_amount = bcdiv(bcmul($amount,$suoke_rate,2),100,2);
- $suoke_invite_id = Db::name('user')->where('id',$user_id)->value('invite_id');
- if($suoke_invite_id && $suoke_amount > 0){
-
- }
-
-
- $map_agent = [
- 'month_date' => date('Ym'),
- 'province_id' => $shop_info['province_id'],
- 'city_id' => $shop_info['city_id'],
- 'district_id' => $shop_info['district_id'],
- ];
- $agent_month = Db::name('agent_month')->where($map_agent)->order('id asc')->find();
- if(empty($agent_month)){
- $map_agent['back_amount'] = $amount;
- $map_agent['updatetime'] = time();
- $map_agent['status'] = 0;
- Db::name('agent_month')->insertGetId($map_agent);
- }else{
- Db::name('agent_month')->where('id',$agent_month['id'])->update([
- 'updatetime' => time(),
- 'back_amount' => bcadd($agent_month['back_amount'],$amount,2)
- ]);
- }
- }
-
- public function yewuyuan(){
- $user_id = 1;
- $last_month = date('Ym',strtotime(date('Y-m-01')) - 86400);
-
- $invite_count = Db::name('offline_shop')->where('invite_id',$user_id)->count();
-
- $invite_count_mon = Db::name('offline_shop')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
-
- $invite_amount = Db::name('bill')->where('shop_invite_id',$user_id)->where('table_name','offline_shop_order')->where('back_status','neq',0)
- ->whereTime('createtime','last month')->sum('back_amount');
-
- $invite_uids = $this->get_all_down_uids($user_id);
- $invite_amount_tuandui = Db::name('bill')->where('shop_invite_id','IN',$invite_uids)->where('table_name','offline_shop_order')->where('back_status','neq',0)
- ->whereTime('createtime','last month')->sum('back_amount');
-
- $butie = 0;
- $yeji = 0;
- $yingxiao_level = 0;
-
- $level_list = Db::name('yingxiao_level')->order('id asc')->select();
- foreach($level_list as $level){
- if($level['type'] == 1 || 1==1){
-
- if($invite_amount_tuandui >= $level['invite_amount_tuandui'] && $invite_amount >= $level['invite_amount'] && $invite_count >= $level['invite_count']){
- $butie = $level['butie'];
- $yeji_rate = $level['yeji_rate'];
- $yeji = bcdiv(bcmul($invite_amount,$yeji_rate,2),100,2);
- $yingxiao_level = $level['id'];
-
- $redis_key_a = $last_month . '_yingxiao_a_' . $yingxiao_level;
- RedisUtil::getInstance($redis_key_a)->lPush($user_id);
-
- $redis_key_b = $last_month . '_yingxiao_b_' . $yingxiao_level;
- RedisUtil::getInstance($redis_key_b)->lPush([
- 'user_id' => $user_id,'invite_amount_tuandui' => $invite_amount_tuandui,
- ]);
- continue;
- }
- }else{
-
- if($invite_amount >= 60000 && $invite_count_mon >= 5){
- $butie = $level['butie'];
- $yeji_rate = $level['yeji_rate'];
- $yeji = bcdiv(bcmul($invite_amount,$yeji_rate,2),100,2);
- $yingxiao_level = $level['id'];
- continue;
- }
- }
- }
- if($yingxiao_level != 0){
- if($butie > 0){
-
- }
- if($yeji > 0){
-
- }
- }
- }
- private function get_all_down_uids($user_id){
- return $user_id;
- }
-
- public function task_agent(){
- $last_month = date('Ym',strtotime(date('Y-m-01')) - 86400);
- $agent_month = Db::name('agent_month')->where('month_date',$last_month)->where('status',0)->column('id');
-
-
- Db::name('agent_month')->where('id','IN',$agent_month)->update([
- 'status' => 1,
- 'updatetime' => time(),
- ]);
- }
-
- public function job_agent($agent_month_id){
- $agent_month = Db::name('agent_month')->where('id',$agent_month_id)->find();
- if($agent_month['status'] != 1){
-
- return;
- }
- $area = Db::name('shopro_data_area')
- ->where('id','IN',[$agent_month['province_id'],$agent_month['city_id'],$agent_month['district_id']])
- ->where('user_id','>',0)
- ->where('back_rate','>',0)
- ->select();
- if(empty($area)){
-
- return;
- }
-
- foreach($area as $key => $agent){
- $agent_money = bcdiv(bcmul($agent_month['back_amount'],$agent['back_rate'],2),100,2);
-
- if($agent_money > 0){
- $agent['user_id'];
- }
- }
-
- Db::name('agent_month')->where('id',$agent_month_id)->update([
- 'status' => '2',
- 'exec_time' => time(),
- ]);
- }
-
- public function test2()
- {
- echo 111;exit;
- $amount = 1000;
- $rate = 15;
- $data = [];
- for($i=1;$i<=40;$i++){
- $data[] = [
- 'amount' => $amount,
- ];
- $amount = bcdiv(bcmul($amount,$rate,2),100,2);
- }
- dump($data);
- }
-
- public function test3()
- {
-
- $data = [
- 'order_paidnum' => ['inc',1],
- 'order_total_amount' => ['inc',11.25],
- 'goods_sales' => ['inc',5],
- ];
- Db::name('live_room_log')->where('id',23)->update($data);
- }
- }
|