Demo.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = ['*'];
  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. $this->success('返回成功', $this->request->param());
  40. }
  41. /**
  42. * 无需登录的接口
  43. *
  44. */
  45. public function test1()
  46. {
  47. $this->success('返回成功', ['action' => 'test1']);
  48. }
  49. /**
  50. * 需要登录的接口
  51. *
  52. */
  53. public function test2()
  54. {
  55. $this->success('返回成功', ['action' => 'test2']);
  56. }
  57. /**
  58. * 需要登录且需要验证有相应组的权限
  59. *
  60. */
  61. public function test3()
  62. {
  63. $this->success('返回成功', ['action' => 'test3']);
  64. }
  65. //订单算奖金。计划任务的逻辑
  66. public function test4(){
  67. $order_id = 488359520289034240;
  68. $product_list = Db::name('unishop_order_product')->where('order_id',$order_id)->select();//已支付
  69. foreach($product_list as $key => $product){
  70. //收益
  71. $shouyi = bcmul($product['number'],$product['pifa_shouyi'],0);
  72. }
  73. $user_id = 1;
  74. //我的下级数量
  75. Db::name('user')->where('intro_uid',$user_id)->count();
  76. //我的上级id
  77. $my_intro_uid = Db::name('user')->where('id',$user_id)->value('intro_uid');
  78. //我的上上级id
  79. $two_intro_uid =Db::name('user')->where('id',$my_intro_uid)->value('intro_uid') ?: 0;
  80. //结算订单后,用户活跃时间更新
  81. Db::name('user_wallet')->where('user_id',$user_id)->update(['active_time'=>time()]);
  82. }
  83. public function auto_order(){
  84. $nowtime = time();
  85. $toweek = date('w',$nowtime);
  86. if($toweek == 0){
  87. //周日不结算(自动到下周一结算)
  88. exit;
  89. }
  90. $tendays_ago = $this->jiesuan_tendays_ago();
  91. //
  92. Db::startTrans();
  93. $order_map = [
  94. 'status' => 1,
  95. 'have_paid' => ['lt',$tendays_ago],
  96. 'jiesuantime' => 0,
  97. ];
  98. Db::name('unishop_order')->where($order_map)->select();
  99. }
  100. //结算要按10天算
  101. public function jiesuan_tendays_ago(){
  102. $nowtime = time();
  103. /*if(input('date','')){
  104. $nowtime = strtotime(input('date',''));
  105. }*/
  106. $today = strtotime(date('Y-m-d',$nowtime));
  107. $toweek = date('w',$nowtime);
  108. $enum = [
  109. 1 => 11,
  110. 2 => 11,
  111. 3 => 11,
  112. 4 => 10,
  113. 5 => 10,
  114. 6 => 10,
  115. 0 => 10, //这一天没人结算
  116. ];
  117. $rs = $today - ($enum[$toweek] * 86400);
  118. // dump(date('Y-m-d',$rs));
  119. return $rs;
  120. }
  121. }