Demo.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 示例接口
  7. */
  8. class Demo extends Api
  9. {
  10. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  11. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  12. //如果接口已经设置无需登录,那也就无需鉴权了
  13. //
  14. // 无需登录的接口,*表示全部
  15. protected $noNeedLogin = ['*'];
  16. // 无需鉴权的接口,*表示全部
  17. protected $noNeedRight = ['test2'];
  18. /**
  19. * 测试方法
  20. *
  21. * @ApiTitle (测试名称)
  22. * @ApiSummary (测试描述信息)
  23. * @ApiMethod (POST)
  24. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  25. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  26. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  27. * @ApiParams (name="name", type="string", required=true, description="用户名")
  28. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  29. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  30. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  31. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  32. * @ApiReturn ({
  33. 'code':'1',
  34. 'msg':'返回成功'
  35. })
  36. */
  37. public function test()
  38. {
  39. $order_amount = 1000; //消费额
  40. $rate = 10; //商家比例
  41. $user_id = 10; //消费者id
  42. $shop_id = 10; //门店id
  43. $this->test1($order_amount,$rate,$user_id,$shop_id);
  44. }
  45. /*
  46. * 订单额,返利比例
  47. * $table : offline_shop ,
  48. * */
  49. public function test1($total_amount,$back_rate,$user_id,$shop_id,$table_name)
  50. {
  51. //3-20%
  52. $amount = bcdiv(bcmul($total_amount,$back_rate,2),100,2);
  53. //5倍
  54. // $back_double = config('site.back_double');
  55. // $amount = bcmul($amount,$back_double,2);
  56. //商务 + 锁客 + 网体 + 省代 + 市代 + 区代 = 40% (大约40%,具体看多少看各级配置)
  57. //商务 发给门店的上级 收益
  58. $shangwu_rate = config('site.back_shangwu');
  59. $shangwu_amount = bcdiv(bcmul($amount,$shangwu_rate,2),2);
  60. $shangwu_invite_id = Db::name($table_name)->where('id',$shop_id)->value('invite_id');
  61. //发钱给 $shangwu_invite_id
  62. if($shangwu_invite_id && $shangwu_amount > 0){
  63. }
  64. //锁客 发给消费者的上级 收益
  65. $suoke_rate = config('site.back_suoke');
  66. $suoke_amount = bcdiv(bcmul($amount,$suoke_rate,2),2);
  67. $suoke_invite_id = Db::name('user')->where('id',$user_id)->value('invite_id');
  68. //发钱给 $suoke_invite_id
  69. if($suoke_invite_id && $suoke_amount > 0){
  70. }
  71. //网体 业务员逻辑 按月发 收益
  72. //省代,市代,区代 三个代理 都按月发 收益
  73. }
  74. //每月初执行,跑代理辅助表,把上个月的数据全部推送到 代理队列
  75. public function task_agent(){
  76. $last_month = date('Ym',strtotime(date('Y-m-01')) - 86400); //上个月一号,202502
  77. $agent_month = Db::name('agent_month')->where('month_date',$last_month)->where('status',0)->column('id');
  78. //推送到代理job
  79. //修改状态
  80. Db::name('agent_month')->where('id','IN',$agent_month)->update([
  81. 'status' => 1,
  82. 'updatetime' => time(),
  83. ]);
  84. }
  85. //代理job,跑完代理队列里的每一条
  86. public function job_agent($agent_month_id){
  87. $agent_month = Db::name('agent_month')->where('id',$agent_month_id)->find();
  88. if($agent_month['status'] != 1){
  89. //结束
  90. return;
  91. }
  92. $area = Db::name('shopro_data_area')
  93. ->where('id','IN',[$agent_month['province_id'],$agent_month['city_id'],$agent_month['district_id']])
  94. ->where('user_id','>',0)
  95. ->where('back_rate','>',0)
  96. ->select();
  97. if(empty($area)){
  98. //结束
  99. return;
  100. }
  101. //省市县执行三次
  102. foreach($area as $key => $agent){
  103. $agent_money = bcdiv(bcmul($agent_month['back_amount'],$agent['back_rate'],2),100,2);
  104. //发钱
  105. if($agent_money > 0){
  106. $agent['user_id'];
  107. }
  108. }
  109. //状态改为已发放
  110. Db::name('agent_month')->where('id',$agent_month_id)->update([
  111. 'status' => '2',
  112. 'exec_time' => time(),
  113. ]);
  114. }
  115. /**
  116. * 需要登录的接口
  117. *
  118. */
  119. public function test2()
  120. {
  121. echo 111;exit;
  122. $amount = 1000;
  123. $rate = 15;
  124. $data = [];
  125. for($i=1;$i<=40;$i++){
  126. $data[] = [
  127. 'amount' => $amount,
  128. ];
  129. $amount = bcdiv(bcmul($amount,$rate,2),100,2);
  130. }
  131. dump($data);
  132. // Db::name('back_base')->insertAll($data);
  133. }
  134. /**
  135. * 需要登录且需要验证有相应组的权限
  136. *
  137. */
  138. public function test3()
  139. {
  140. //$this->success('返回成功', ['action' => 'test3']);
  141. $data = [
  142. 'order_paidnum' => ['inc',1],
  143. 'order_total_amount' => ['inc',11.25],
  144. 'goods_sales' => ['inc',5],
  145. ];
  146. Db::name('live_room_log')->where('id',23)->update($data);
  147. }
  148. }