General.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. * @return name:sign_crystal type:int default:-- desc:明信片
  104. * @return name:coupon_id type:int default:-- desc:券id(没有券是0)
  105. */
  106. public function userSign()
  107. {
  108. $year = date('Y');
  109. $month = date('m');
  110. $day = date('d');
  111. $ck_sign = Db::table('user_sign')
  112. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'day'=>$day])
  113. ->count();
  114. if($ck_sign) $this->error('已签到');
  115. $sign_crystal = rand(1,5);
  116. $sign_data=[
  117. 'uid' =>$this->uid,
  118. 'year' =>$year,
  119. 'month' =>$month,
  120. 'day' =>$day,
  121. 'day_time'=>date('Y-m-d'),
  122. 'create_at' => date('Y-m-d H:i:s'),
  123. 'desc' => '每日签到',
  124. 'crystal'=>$sign_crystal
  125. ];
  126. Db::table('user_sign')->insert($sign_data);// 签到日志
  127. //
  128. Db::table('store_member')->where('id',$this->uid)->setInc('crystal',$sign_crystal);
  129. crystal_log($this->uid,$sign_crystal,'每日签到奖励',10);
  130. // 连续签到7天送券
  131. $week_sign = 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. ->order('id desc')
  136. ->count();
  137. $coupon_id = 0;
  138. if($week_sign == 7) {
  139. Db::table('user_sign')
  140. ->where('uid','=',$this->uid)
  141. ->where('create_at','>= time',date('Y-m-d 00:00:00',strtotime('-6 days')))
  142. ->where('status','=',0)
  143. ->update(['status'=>1]);
  144. // 送券
  145. $ticket_day = intval(sysconf('ticket_days'));// 获取设置天数
  146. if($ticket_day > 0) {
  147. $coupon_data=[
  148. 'user_id' => $this->uid,
  149. 'low_day' => $ticket_day ,
  150. 'create_at'=> date('Y-m-d H:i:s'),
  151. 'past_at' => date('Y-m-d H:i:s',strtotime("+$ticket_day days"))
  152. ];
  153. Db::table('user_coupon_list')->insert($coupon_data);
  154. $coupon_id = Db::getLastInsID();
  155. }
  156. }
  157. $this->success('签到成功',['sign_crystal'=>$sign_crystal,'coupon_id'=>$coupon_id]);
  158. }
  159. /**
  160. * @title 会员签到列表
  161. * @desc 会员签到列表
  162. * @author qc
  163. * @url /api/General/getSignList
  164. * @method GET
  165. * @header name:Authorization require:1 desc:Token
  166. * @param name:page type:int default:1 desc:页数
  167. * @param name:page_num type:int : default:20 desc:每页数
  168. * @return name:create_at type:string default:-- desc:时间
  169. * @return name:desc type:string default:-- desc:描述
  170. */
  171. public function getSignList()
  172. {
  173. $list = Db::table('user_sign')
  174. ->field('id,create_at,desc')
  175. ->where('uid','=',$this->uid)
  176. ->order('id desc')
  177. ->limit($this->off_set,$this->page_num)
  178. ->select();
  179. $this->success('ok',['list'=>$list]);
  180. }
  181. /**
  182. * @title 获取运费
  183. * @desc 获取运费
  184. * @author qc
  185. * @url /api/General/getFreight
  186. * @method GET
  187. * @header name:Authorization require:1 desc:Token
  188. * @param name:num type:int require:1 default:1 desc:商品数量
  189. * @return name:all_freight type:int default:-- desc:总运费
  190. * @return name:first_freight type:int default:-- desc:首件运费
  191. * @return name:later_freight type:int default:-- desc:续件运费
  192. */
  193. public function getFreight()
  194. {
  195. $freight_data = get_freight(input('num',1));
  196. $this->success('ok',$freight_data);
  197. }
  198. /**
  199. * @title 获取消息
  200. * @desc 获取消息
  201. * @author qc
  202. *
  203. * @url /api/General/getUserMessage
  204. * @method GET
  205. * @header name:Authorization require:1 desc:Token
  206. * @param name:page type:int default:1 desc:页数
  207. * @param name:page_num type:int : default:20 desc:每页数
  208. * @return name:create_at type:string default:-- desc:时间
  209. * @return name:content type:string default:-- desc:内容
  210. * @return name:type_id type:int default:-- desc:类型(1中奖消息2平台消息)
  211. */
  212. public function getUserMessage()
  213. {
  214. Db::table('user_message')->where('user_id',$this->uid)->where('is_read',0)->update(['is_read'=>1]);
  215. $list = Db::table('user_message')
  216. ->where('user_id',$this->uid)
  217. ->limit($this->off_set,$this->page_num)
  218. ->order('id desc')
  219. ->select();
  220. $this->success('ok',['list'=>$list]);
  221. }
  222. }