General.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. /**
  5. * @title 其他接口
  6. * @controller General
  7. * @group base
  8. */
  9. class General extends Base
  10. {
  11. public function initialize()
  12. {
  13. parent::check_login();
  14. }
  15. /**
  16. * @title 获取物流详情
  17. * @desc 获取物流详情
  18. * @author qc
  19. * @url /api/General/deliveryDetails
  20. * @method GET
  21. * @header name:Authorization require:1 desc:Token
  22. * @param name:send_no type:string require:1 default:-- desc:物流单号(订单express_send_no字段)
  23. * @return name:number type:string default:-- desc:单号
  24. * @return name:type type:string default:-- desc:快递类型
  25. * @return name:list type:array default:-- desc:数据列表
  26. * @return name:list.time type:string default:-- desc:时间
  27. * @return name:list.status type:string default:-- desc:内容
  28. * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收
  29. * @return name:issign type:int default:-- desc:是否签收(1.是否签收)
  30. * @return name:expName type:string default:-- desc:快递公司名称
  31. * @return name:expSite type:string default:-- desc:快递公司官网
  32. * @return name:expPhone type:string default:-- desc:快递公司电话
  33. * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空)
  34. * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空)
  35. * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间
  36. * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹)
  37. * @return name:logo type:string default:-- desc:快递公司LOGO
  38. */
  39. public function deliveryDetails(){
  40. $send_no = input('get.send_no');
  41. $data = get_delivery($send_no);
  42. $this->success('ok',$data);
  43. }
  44. /**
  45. * @title 验证会员当天是否签到
  46. * @desc 验证会员当天是否签到
  47. * @author qc
  48. * @url /api/General/checkSign
  49. * @method GET
  50. * @header name:Authorization require:1 desc:Token
  51. * @return name:is_sign type:int default:0 desc:是否签到0未签到,1已签到
  52. */
  53. public function checkSign()
  54. {
  55. $year = date('Y');
  56. $month = date('m');
  57. $day = date('d');
  58. $ck_sign = Db::table('user_sign')
  59. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'day'=>$day])
  60. ->count();
  61. $this->success('ok',['is_sign'=>$ck_sign]);
  62. }
  63. /**
  64. * @title 获取会员连续签到天数
  65. * @desc 获取会员连续签到天数
  66. * @author qc
  67. * @url /api/General/getContinuousSign
  68. * @method GET
  69. * @header name:Authorization require:1 desc:Token
  70. * @return name:is_sign type:int default:-- desc:当天是否签到(0签到,1已签到)
  71. * @return name:sign_num type:int default:-- desc:连续签到天数
  72. */
  73. public function getContinuousSign()
  74. {
  75. $today_sign = Db::table('user_sign')
  76. ->where(['uid'=>$this->uid,'day_time'=>date('Y-m-d')])
  77. ->find();
  78. $is_sign = !empty($today_sign) ? 1:0;
  79. $sign_num = 0;
  80. $week_sign = Db::table('user_sign')
  81. ->where('uid','=',$this->uid)
  82. ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
  83. ->where('status','=',0)
  84. ->order('id desc')
  85. ->select();
  86. $sign_date = array_column($week_sign,'day_time');
  87. for($i=0;$i<=6;$i++) {
  88. if(in_array(date('Y-m-d',strtotime("-$i days")),$sign_date)){
  89. $sign_num++;
  90. }else if($i>0){
  91. break;
  92. }
  93. }
  94. $this->success('ok',['sign_num'=>$sign_num,'is_sign'=>$is_sign]);
  95. }
  96. /**
  97. * @title 会员签到
  98. * @desc 会员签到
  99. * @author qc
  100. * @url /api/General/userSign
  101. * @method POST
  102. * @header name:Authorization require:1 desc:Token
  103. */
  104. public function userSign()
  105. {
  106. $year = date('Y');
  107. $month = date('m');
  108. $day = date('d');
  109. $ck_sign = Db::table('user_sign')
  110. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'day'=>$day])
  111. ->count();
  112. if($ck_sign) $this->error('已签到');
  113. $sign_data=[
  114. 'uid' =>$this->uid,
  115. 'year' =>$year,
  116. 'month' =>$month,
  117. 'day' =>$day,
  118. 'day_time'=>date('Y-m-d'),
  119. 'create_at' => date('Y-m-d H:i:s'),
  120. 'desc' => '每日签到',
  121. ];
  122. Db::table('user_sign')->insert($sign_data);// 签到日志
  123. // 连续签到7天送券
  124. $week_sign = Db::table('user_sign')
  125. ->where('uid','=',$this->uid)
  126. ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
  127. ->where('status','=',0)
  128. ->order('id desc')
  129. ->count();
  130. if($week_sign == 7) {
  131. Db::table('user_sign')
  132. ->where('uid','=',$this->uid)
  133. ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
  134. ->where('status','=',0)
  135. ->update(['status'=>1]);
  136. // 送券
  137. $ticket_day = intval(sysconf('ticket_days'));// 获取设置天数
  138. if($ticket_day > 0) {
  139. $coupon_data=[
  140. 'user_id' => $this->uid,
  141. 'low_day' => $ticket_day ,
  142. 'create_at'=> date('Y-m-d H:i:s'),
  143. 'past_at' => date('Y-m-d H:i:s',strtotime("+$ticket_day days"))
  144. ];
  145. Db::table('user_coupon_list')->insert($coupon_data);
  146. }
  147. }
  148. $this->success('签到成功');
  149. }
  150. /**
  151. * @title 会员签到列表
  152. * @desc 会员签到列表
  153. * @author qc
  154. * @url /api/General/getSignList
  155. * @method GET
  156. * @header name:Authorization require:1 desc:Token
  157. * @param name:page type:int default:1 desc:页数
  158. * @param name:page_num type:int : default:20 desc:每页数
  159. * @return name:create_at type:string default:-- desc:时间
  160. * @return name:desc type:string default:-- desc:描述
  161. */
  162. public function getSignList()
  163. {
  164. $list = Db::table('user_sign')
  165. ->field('id,create_at,desc')
  166. ->where('uid','=',$this->uid)
  167. ->order('id desc')
  168. ->limit($this->off_set,$this->page_num)
  169. ->select();
  170. $this->success('ok',['list'=>$list]);
  171. }
  172. /**
  173. * @title 获取运费
  174. * @desc 获取运费
  175. * @author qc
  176. * @url /api/General/getFreight
  177. * @method GET
  178. * @header name:Authorization require:1 desc:Token
  179. * @param name:num type:int require:1 default:1 desc:商品数量
  180. * @return name:all_freight type:int default:-- desc:总运费
  181. * @return name:first_freight type:int default:-- desc:首件运费
  182. * @return name:later_freight type:int default:-- desc:续件运费
  183. */
  184. public function getFreight()
  185. {
  186. $freight_data = get_freight(input('num',1));
  187. $this->success('ok',$freight_data);
  188. }
  189. /**
  190. * @title 获取消息
  191. * @desc 获取消息
  192. * @author qc
  193. * @url /api/General/getUserMessage
  194. * @method GET
  195. * @header name:Authorization require:1 desc:Token
  196. * @param name:page type:int default:1 desc:页数
  197. * @param name:page_num type:int : default:20 desc:每页数
  198. * @return name:create_at type:string default:-- desc:时间
  199. * @return name:content type:string default:-- desc:内容
  200. * @return name:type_id type:int default:-- desc:类型(1中奖消息2平台消息)
  201. */
  202. public function getUserMessage()
  203. {
  204. $list = Db::table('user_message')
  205. ->where('user_id',$this->uid)
  206. ->limit($this->off_set,$this->page_num)
  207. ->order('id desc')
  208. ->select();
  209. $this->success('ok',['list'=>$list]);
  210. }
  211. }