Demo.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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($order_amount,$rate,$user_id,$shop_id,$table)
  50. {
  51. //3-20%
  52. $amount = bcdiv(bcmul($order_amount,$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)->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. * 需要登录的接口
  76. *
  77. */
  78. public function test2()
  79. {
  80. echo 111;exit;
  81. $amount = 1000;
  82. $rate = 15;
  83. $data = [];
  84. for($i=1;$i<=40;$i++){
  85. $data[] = [
  86. 'amount' => $amount,
  87. ];
  88. $amount = bcdiv(bcmul($amount,$rate,2),100,2);
  89. }
  90. dump($data);
  91. // Db::name('back_base')->insertAll($data);
  92. }
  93. /**
  94. * 需要登录且需要验证有相应组的权限
  95. *
  96. */
  97. public function test3()
  98. {
  99. //$this->success('返回成功', ['action' => 'test3']);
  100. $data = [
  101. 'order_paidnum' => ['inc',1],
  102. 'order_total_amount' => ['inc',11.25],
  103. 'goods_sales' => ['inc',5],
  104. ];
  105. Db::name('live_room_log')->where('id',23)->update($data);
  106. }
  107. }