General.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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::initialize();
  14. parent::check_login();
  15. }
  16. /**
  17. * @title 提交订单转换
  18. * @desc 提交订单转换
  19. * @author qc
  20. * @url /api/General/orderShift
  21. * @method POST
  22. * @tag 订单转换
  23. * @header name:Authorization require:1 desc:Token
  24. * @param name:order_sn type:string require:1 default:-- desc:第三方订单号
  25. */
  26. public function orderShift()
  27. {
  28. $order_no = input('post.order_sn');
  29. if(!$order_no) $this->error('请填写订单号');
  30. $ck = Db::table('order_shift')->where('order_no',$order_no)->value('id');
  31. if($ck) $this->error('您已提交过相同的订单ID,请核实后重新提交,有疑问咨询专属客服哦~');
  32. Db::table('order_shift')->insert(['uid'=>$this->uid,'create_at'=>date('Y-m-d H:i:s'),'order_no'=>$order_no]);
  33. $this->success('订单提交成功,等待审核!');
  34. }
  35. /**
  36. * @title 获取提交的转换记录
  37. * @desc 获取提交的转换记录
  38. * @author qc
  39. * @url /api/General/getOrderShiftList
  40. * @method GET
  41. * @header name:Authorization require:1 desc:Token
  42. * @param name:page type:int : default:1 desc:页数
  43. * @param name:page_num type:int : default:20 desc:每页数
  44. * @param name:ck_status type:int : default:-1 desc:审核状态(默认全部)0待审核,1审核通过,2审核不通过,
  45. * @return name:id type:int default:-- desc:记录id
  46. * @return name:uid type:string default:-- desc:会员id
  47. * @return name:order_no type:string default:-- desc:提交的订单号
  48. * @return name:sh_status type:int default:-- desc:审核状态(0待审核,1审核通过,2审核不通过)
  49. * @return name:remark type:string default:-- desc:审核备注
  50. * @return name:ck_time type:string default:-- desc:审核时间
  51. * @return name:integral type:int default:-- desc:转化多少积分
  52. * @return name:growth type:int default:-- desc:转化多少成长值
  53. */
  54. public function getOrderShiftList()
  55. {
  56. $where['o.uid'] = $this->uid;
  57. $ck_status = input('ck_status',-1);
  58. if(in_array($ck_status,[0,1,2]))$where['o.sh_status'] =$ck_status;
  59. $list = Db::table('order_shift')
  60. ->field('o.id,o.order_no,o.sh_status,ck_time,integral,growth,d.title as remark')
  61. ->alias('o')
  62. ->join('audit_desc d','d.id = o.audit_id',"LEFT")
  63. ->where($where)
  64. ->limit($this->off_set,$this->page_num)
  65. ->order('o.id desc')
  66. ->select();
  67. $this->success('ok',$list);
  68. }
  69. /**
  70. * @title 获取许愿分类
  71. * @desc 获取许愿分类
  72. * @author qc
  73. * @url /api/General/getWishCate
  74. * @method GET
  75. * @header name:Authorization require:1 desc:Token
  76. * @return name:id type:int default:-- desc:分类id
  77. * @return name:title type:string default:-- desc:分类名称
  78. */
  79. public function getWishCate()
  80. {
  81. $list = Db::table('wish_cate')
  82. ->field('id,title')
  83. ->where('is_deleted',0)->where('status',1)
  84. ->order('sort desc,id desc')->select();
  85. $this->success('提交成功',['list'=>$list]);
  86. }
  87. /**
  88. * @title 提交许愿单
  89. * @desc 提交许愿单
  90. * @author qc
  91. * @url /api/General/proWish
  92. * @method POST
  93. * @header name:Authorization require:1 desc:Token
  94. * @param name:phone type:string require:1 default:-- desc:手机号
  95. * @param name:first_classify type:int require:1 default:-- desc:分类id
  96. * @param name:detail type:string require:1 default:-- desc:详情
  97. */
  98. public function proWish()
  99. {
  100. $phone = input('post.phone');
  101. $first_classify = input('post.first_classify');
  102. $detail = input('post.detail');
  103. if(!$detail ) $this->error('请填写愿望号');
  104. $ck = Db::table('user_wish')
  105. ->where(['uid'=>$this->uid,'first_classify'=>$first_classify,'detail'=>$detail])
  106. ->value('id');
  107. if($ck) $this->error('愿望不能重复提交');
  108. Db::table('user_wish')->insert(['uid'=>$this->uid,'phone'=>$phone,'first_classify'=>$first_classify,'detail'=>$detail,'create_at'=>date('Y-m-d H:i:s')]);
  109. $this->success('提交成功');
  110. }
  111. /**
  112. * @title 获取物流详情
  113. * @desc 获取物流详情
  114. * @author qc
  115. * @url /api/General/deliveryDetails
  116. * @method GET
  117. * @header name:Authorization require:1 desc:Token
  118. * @param name:company_id type:int require:1 default:-- desc:快递id(订单express_company_id字段)
  119. * @param name:send_no type:string require:1 default:-- desc:物流单号
  120. * @return name:number type:string default:-- desc:单号
  121. * @return name:type type:string default:-- desc:快递类型
  122. * @return name:list type:array default:-- desc:数据列表
  123. * @return name:list.time type:string default:-- desc:时间
  124. * @return name:list.status type:string default:-- desc:内容
  125. * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收
  126. * @return name:issign type:int default:-- desc:是否签收(1.是否签收)
  127. * @return name:expName type:string default:-- desc:快递公司名称
  128. * @return name:expSite type:string default:-- desc:快递公司官网
  129. * @return name:expPhone type:string default:-- desc:快递公司电话
  130. * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空)
  131. * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空)
  132. * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间
  133. * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹)
  134. * @return name:logo type:string default:-- desc:快递公司LOGO
  135. */
  136. public function deliveryDetails(){
  137. $send_no = input('get.send_no');
  138. $data = get_delivery($send_no);
  139. $this->success('ok',$data);
  140. }
  141. /**
  142. * @title 验证会员当天是否签到
  143. * @desc 验证会员当天是否签到
  144. * @author qc
  145. * @url /api/General/checkSign
  146. * @method GET
  147. * @header name:Authorization require:1 desc:Token
  148. * @return name:is_sign type:int default:0 desc:是否签到0未签到,1已签到
  149. */
  150. public function checkSign()
  151. {
  152. $year = date('Y');
  153. $month = date('m');
  154. $day = date('d');
  155. $ck_sign = Db::table('user_sign')
  156. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'day'=>$day,'type'=>1])
  157. ->count();
  158. $this->success('ok',['is_sign'=>$ck_sign]);
  159. }
  160. /**
  161. * @title 会员当月签到详情
  162. * @desc 会员当月签到详情
  163. * @author qc
  164. * @url /api/General/getUserMonthSign
  165. * @method GET
  166. * @header name:Authorization require:1 desc:Token
  167. * @return name:month_data type:array default:-- desc:日历
  168. * @return name:month_data.date_str type:array default:-- desc:时间
  169. * @return name:month_data.date type:array default:-- desc:日期
  170. * @return name:month_data.prefix_date type:array default:-- desc:日期
  171. * @return name:month_data.week type:string default:-- desc:星期几
  172. * @return name:month_data.live_num type:int default:-- desc:当天直播场数(没有直播是0)
  173. * @return name:month_data.is_sign type:int default:-- desc:是否签到(未签到是0,签到是1)
  174. * @return name:month_data.live_sign type:string default:-- desc:标签
  175. * @return name:today_sign type:int default:0 desc:当天是否签到(未签到是0,签到是1)
  176. * @return name:count type:int default:0 desc:月签到次数
  177. * @return name:acc_data type:array default:-- desc:月累计签到签到
  178. * @return name:acc_data.seven type:int default:0 desc:累计7天奖励是否领取(0未领取,1已领取)
  179. * @return name:acc_data.seventeen type:int default:0 desc:累计17天奖励是否领取(0未领取,1已领取)
  180. * @return name:acc_data.twenty_seven type:int default:0 desc:累计27天奖励是否领取(0未领取,1已领取)
  181. * @return name:sign_set type:array default:0 desc:签到设置
  182. * @return name:sign_set.type type:int default:0 desc:签到类型(1每日签到,2累积签到)
  183. * @return name:sign_set.day type:int default:0 desc:天数
  184. * @return name:sign_set.integral type:int default:0 desc:积分
  185. * @return name:sign_set.growth type:int default:0 desc:成长值
  186. */
  187. public function getUserMonthSign()
  188. {
  189. $year = date('Y');
  190. $month = date('m');
  191. $month_data = get_month_days();
  192. $today_sign = 0;
  193. foreach ($month_data as &$v) {
  194. $is_live = Db::table('store_live')
  195. ->where('start_at','>= time',$v['date_str'].' 00:00:00')
  196. ->where('start_at','<= time',$v['date_str'].' 23:59:59')
  197. ->find();
  198. $v['live_num'] = !empty($is_live) ? 1:0;
  199. $v['live_sign'] = !empty($is_live) ? $is_live['title_sign']:'';
  200. $v['is_sign'] = Db::table('user_sign')
  201. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'set_id'=>1,'day'=>$v['prefix_date']])
  202. ->count();
  203. if($v['date_str'] == date('Y-m-d') )$today_sign = $v['is_sign'] ;
  204. }
  205. $acc = Db::table('user_sign')
  206. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'set_id'=>[2,3,4]])
  207. ->select();
  208. $acc_data =['seven'=>0,'seventeen'=>0,'twenty_seven'=>0];
  209. array_map(function ($val)use (&$acc_data){
  210. switch ($val['set_id']){
  211. case 2:
  212. $acc_data['seven']=1;
  213. break;
  214. case 3:
  215. $acc_data['seventeen']=1;
  216. break;
  217. case 4:
  218. $acc_data['twenty_seven']=1;
  219. break;
  220. }
  221. },$acc);
  222. $sign_set = Db::table('store_sign')->select();
  223. $this->success('ok',['month_data'=>$month_data,'today_sign'=>$today_sign,'count'=>array_sum(array_column($month_data,'is_sign')),'acc_data'=>$acc_data,'sign_set'=>$sign_set]);
  224. }
  225. /**
  226. * @title 会员签到
  227. * @desc 会员签到
  228. * @author qc
  229. * @url /api/General/userSign
  230. * @method POST
  231. * @header name:Authorization require:1 desc:Token
  232. * @param name:type type:int require:1 default:1 desc:签到类型1普通签到,2累计7天,3,累计17天,4累计27天
  233. * @return name:send_integral type:int default:0 desc:发放积分数
  234. */
  235. public function userSign()
  236. {
  237. $type = input('post.type',1);
  238. $year = date('Y');
  239. $month = date('m');
  240. $day = date('d');
  241. $send_integral = 0;
  242. $daily_set = Db::table('store_sign')->where(['type'=>1])->find();//每日签到
  243. $cumulant_set = Db::table('store_sign')->where(['type'=>2])->select();// 累积签到
  244. $ck_sign = Db::table('user_sign')
  245. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'day'=>$day,'type'=>$type])
  246. ->count();
  247. if($ck_sign) $this->error('已签到');
  248. $sign_data=[
  249. 'uid' =>$this->uid,
  250. 'year' =>$year,
  251. 'month' =>$month,
  252. 'day' =>$day,
  253. 'type' =>$type,
  254. 'create_at' => date('Y-m-d H:i:s'),
  255. 'desc' => '每日签到',
  256. 'integral' => $daily_set['integral'],
  257. 'set_id' => $daily_set['id'],
  258. 'growth' => $daily_set['growth'],
  259. ];
  260. Db::table('user_sign')->insert($sign_data);// 签到日志
  261. $int_id = Db::getLastInsID();
  262. $send_integral = bcadd($send_integral,$daily_set['integral']);
  263. update_user_integral($this->uid,$daily_set['integral'],3,'恭喜亲通过每日签到获得'.$daily_set['integral'].'积分',$int_id);// 更新积分
  264. if($daily_set['growth'] > 0) update_user_growth($this->uid,$daily_set['growth'],3,'恭喜亲通过每日签到获得'.$daily_set['growth'].'成长值');// 更新成长值
  265. /**
  266. * 累积签到
  267. */
  268. // 当月每日签到
  269. $month_sign = Db::table('user_sign')
  270. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'type'=>1])
  271. ->count();
  272. foreach ($cumulant_set as $val)
  273. {
  274. if($val['day'] <= $month_sign){
  275. // 当月的累积签到是否发放
  276. $ck_sign = Db::table('user_sign')
  277. ->where(['uid'=>$this->uid,'year'=>$year,'month'=>$month,'set_id'=>$val['id']])
  278. ->count();
  279. if($ck_sign) continue;
  280. $sign_data=[
  281. 'uid' =>$this->uid,
  282. 'year' =>$year,
  283. 'month' =>$month,
  284. 'day' =>$day,
  285. 'type' =>$val['id'],
  286. 'create_at' => date('Y-m-d H:i:s'),
  287. 'desc' => '恭喜亲通过累积签到'.$val['day'].'天获得'.$val['integral'].'积分',
  288. 'integral' => $val['integral'],
  289. 'growth' => $val['growth'],
  290. 'set_id' => $val['id'],
  291. ];
  292. Db::table('user_sign')->insert($sign_data);
  293. $int_id = Db::getLastInsID();
  294. // 更新积分余额
  295. $send_integral = bcadd($send_integral,$val['integral']);
  296. update_user_integral($this->uid, $val['integral'],3,$sign_data['desc'],$int_id);
  297. if($val['growth'] > 0) update_user_growth($this->uid,$val['growth'],3,'恭喜亲通过累积签到'.$val['day'].'天获得'.$val['growth'].'成长值');// 更新成长值
  298. }
  299. }
  300. $this->success('签到成功',['send_integral'=>intval($send_integral)]);
  301. }
  302. /**
  303. * @title 积分兑换
  304. * @desc 积分兑换
  305. * @author qc
  306. * @url /api/General/integralConvert
  307. * @method POST
  308. * @tag 积分兑换
  309. * @header name:Authorization require:1 desc:Token
  310. * @param name:title type:string require:1 default:-- desc:标题
  311. * @param name:desc type:string require:1 default:-- desc:描述
  312. * @param name:image type:string require:1 default:-- desc:图片(1张)
  313. */
  314. public function integralConvert()
  315. {
  316. $title = input('post.title');
  317. $desc = input('post.desc');
  318. $image = input('post.image');
  319. $info = [
  320. 'user_id' => $this->uid,
  321. 'title' =>$title,
  322. 'desc' =>$desc,
  323. 'image' =>$image,
  324. ];
  325. Db::name('integral_convert')->insert($info);
  326. $this->success('ok',['已提交等待审核']);
  327. }
  328. /**
  329. * @title 积分兑换详情
  330. * @desc 积分兑换详情
  331. * @author qc
  332. * @url /api/General/getIntegralConvertDetail
  333. * @method GET
  334. * @tag
  335. * @header name:Authorization require:1 desc:Token
  336. * @param name:id type:int : default:1 desc:记录id
  337. * @return name:title type:string require:1 default:-- desc:标题
  338. * @return name:desc type:string require:1 default:-- desc:描述
  339. * @return name:image type:string require:1 default:-- desc:图片(1张)
  340. * @return name:sh_status type:int require:1 default:-- desc:审核状态(0 待审核1审核通过2审核不通过)
  341. * @return name:ck_time type:string require:1 default:-- desc:审核时间
  342. * @return name:remark type:string require:1 default:-- desc:审核备注
  343. * @return name:integral type:int require:1 default:-- desc:积分数
  344. */
  345. public function getIntegralConvertDetail()
  346. {
  347. $id = input('post.id');
  348. $detail = Db::name('integral_convert')->where(['user_id'=>$this->uid,'id'=>$id])->find();
  349. $this->success('ok',['detail'=>$detail]);
  350. }
  351. /**
  352. * @title 积分兑换记录
  353. * @desc 积分兑换记录
  354. * @author qc
  355. * @url /api/General/getIntegralConvertList
  356. * @method GET
  357. * @tag 积分兑换
  358. * @header name:Authorization require:1 desc:Token
  359. * @param name:page type:int : default:1 desc:页数
  360. * @param name:page_num type:int : default:20 desc:每页数
  361. * @return name:title type:string require:1 default:-- desc:标题
  362. * @return name:desc type:string require:1 default:-- desc:描述
  363. * @return name:image type:string require:1 default:-- desc:图片(1张)
  364. * @return name:sh_status type:int require:1 default:-- desc:审核状态(0 待审核1审核通过2审核不通过)
  365. * @return name:ck_time type:string require:1 default:-- desc:审核时间
  366. * @return name:remark type:string require:1 default:-- desc:审核备注
  367. * @return name:integral type:int require:1 default:-- desc:积分数
  368. */
  369. public function getIntegralConvertList()
  370. {
  371. $list = Db::name('integral_convert')->where(['user_id'=>$this->uid,'is_deleted'=>0])
  372. ->order('id desc')
  373. ->limit($this->off_set,$this->page_num)
  374. ->select();
  375. $this->success('ok',['list'=>$list]);
  376. }
  377. /**
  378. * @title 删除积分兑换记录
  379. * @desc 删除积分兑换记录
  380. * @author qc
  381. * @url /api/General/delIntegralConvert
  382. * @method POST
  383. * @tag 积分兑换
  384. * @header name:Authorization require:1 desc:Token
  385. * @param name:id type:int require:1 default:-- desc:积分兑换记录id
  386. */
  387. public function delIntegralConvert()
  388. {
  389. $id = input('post.id');
  390. Db::name('integral_convert')->where(['user_id'=>$this->uid,'id'=>$id])->update(['is_deleted'=>1]);
  391. $this->success('删除成功');
  392. }
  393. }