Demo.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * */
  48. public function test1($order_amount,$rate,$user_id,$shop_id)
  49. {
  50. //3-20%
  51. $amount = bcdiv(bcmul($order_amount,$rate,2),100,2);
  52. //5倍
  53. $back_double = config('site.back_double');
  54. $amount = bcmul($amount,$back_double,2);
  55. //商务 + 锁客 + 网体 + 省代 + 市代 + 区代 = 40% (大约40%,具体看多少看各级配置)
  56. //商务 发给门店的上级 收益
  57. $shangwu_rate = config('site.back_shangwu');
  58. $shangwu_amount = bcdiv(bcmul($amount,$shangwu_rate,2),2);
  59. //锁客 发给消费者的上级 收益
  60. $suoke_rate = config('site.back_suoke');
  61. $suoke_amount = bcdiv(bcmul($amount,$suoke_rate,2),2);
  62. //网体 业务员逻辑 按月发 收益
  63. $wangti_rate = config('site.back_wangti');
  64. $wangti_amount = bcdiv(bcmul($amount,$wangti_rate,2),2);
  65. //省代
  66. //市代
  67. //区代
  68. //三个代理都 按月发 收益
  69. }
  70. /**
  71. * 需要登录的接口
  72. *
  73. */
  74. public function test2()
  75. {
  76. echo 111;exit;
  77. $amount = 1000;
  78. $rate = 15;
  79. $data = [];
  80. for($i=1;$i<=40;$i++){
  81. $data[] = [
  82. 'amount' => $amount,
  83. ];
  84. $amount = bcdiv(bcmul($amount,$rate,2),100,2);
  85. }
  86. dump($data);
  87. // Db::name('back_base')->insertAll($data);
  88. }
  89. /**
  90. * 需要登录且需要验证有相应组的权限
  91. *
  92. */
  93. public function test3()
  94. {
  95. //$this->success('返回成功', ['action' => 'test3']);
  96. $data = [
  97. 'order_paidnum' => ['inc',1],
  98. 'order_total_amount' => ['inc',11.25],
  99. 'goods_sales' => ['inc',5],
  100. ];
  101. Db::name('live_room_log')->where('id',23)->update($data);
  102. }
  103. }