General.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use AliPay\Scan;
  7. use app\common\model\StoreGoods;
  8. use app\common\model\StoreGoodsItem;
  9. use app\common\model\User;
  10. use app\common\model\UserMessage;
  11. use app\common\model\UserTrack;
  12. use think\Db;
  13. use think\Exception;
  14. use EasyWeChat\Factory;
  15. use function AlibabaCloud\Client\value;
  16. /**
  17. * @title 其他接口
  18. * @controller General
  19. * @group base
  20. */
  21. class General extends Base
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. parent::checkLogin();
  27. }
  28. /**
  29. * @title 发送短信验证码
  30. * @desc 发送短信验证码
  31. * @author qc
  32. * @url /api/General/sendSms
  33. * @method POST
  34. * @tag 短信验证码
  35. * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
  36. * @return name:code type:string default:-- desc:验证码
  37. */
  38. public function sendSms(){
  39. $phone = input('post.phone');
  40. if(empty($phone)) $this ->error('参数错误');
  41. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  42. AlibabaCloud::accessKeyClient('LTAI5tEEfowhMkLu8auo6n6G', 'ch94CL3TEwNAxXNREweZl3gfk8jQ84')
  43. ->regionId('cn-hangzhou')->asDefaultClient();
  44. try {
  45. $result = AlibabaCloud::rpc()
  46. ->product('Dysmsapi')
  47. ->version('2017-05-25')
  48. ->action('SendSms')
  49. ->method('POST')
  50. ->host('dysmsapi.aliyuncs.com')
  51. ->options([
  52. 'query' => [
  53. 'RegionId' => "cn-hangzhou",
  54. 'PhoneNumbers' => $phone,
  55. 'SignName' => "康养食品",
  56. 'TemplateCode' => "SMS_241155218",
  57. 'TemplateParam' => json_encode(array("code"=>$code)),
  58. ],
  59. ])->request();
  60. $result = $result->toArray();
  61. if($result['Code'] == "OK") {
  62. $sms_data = array(
  63. 'phone'=>$phone,
  64. 'code'=>$code,
  65. 'result'=>$result['Message']
  66. );
  67. Db::name('store_member_sms')->insert($sms_data);
  68. $this->success('发送成功',$code);
  69. }else{
  70. $this->error('发送失败');
  71. }
  72. } catch (ClientException $e) {
  73. echo $e->getErrorMessage() . PHP_EOL;
  74. } catch (ServerException $e) {
  75. echo $e->getErrorMessage() . PHP_EOL;
  76. }
  77. }
  78. /**
  79. * @title 获取物流详情
  80. * @desc 获取物流详情
  81. * @author qc
  82. * @url /api/General/deliveryDetails
  83. * @method GET
  84. * @header name:Authorization require:1 desc:Token
  85. * @param name:send_no type:string require:1 default:-- desc:物流单号(订单express_send_no字段)
  86. * @return name:number type:string default:-- desc:单号
  87. * @return name:type type:string default:-- desc:快递类型
  88. * @return name:list type:array default:-- desc:数据列表
  89. * @return name:list.time type:string default:-- desc:时间
  90. * @return name:list.status type:string default:-- desc:内容
  91. * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收
  92. * @return name:issign type:int default:-- desc:是否签收(1.是否签收)
  93. * @return name:expName type:string default:-- desc:快递公司名称
  94. * @return name:expSite type:string default:-- desc:快递公司官网
  95. * @return name:expPhone type:string default:-- desc:快递公司电话
  96. * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空)
  97. * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空)
  98. * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间
  99. * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹)
  100. * @return name:logo type:string default:-- desc:快递公司LOGO
  101. */
  102. public function deliveryDetails(){
  103. $send_no = input('get.send_no');
  104. $data = get_delivery($send_no);
  105. $this->success('ok',$data);
  106. }
  107. /**
  108. * @title 获取足迹日历信息
  109. * @desc 获取足迹日历信息
  110. * @author qc
  111. * @url /api/General/getCalendar
  112. * @method GET
  113. * @header name:Authorization require:1 desc:Token
  114. * @param name:num type:int default:7 desc:时间(最近几天,默认7天)
  115. * @return name:day_time type:string default:-- desc:时间
  116. * @return name:week_day type:string default:-- desc:周几
  117. */
  118. public function getCalendar()
  119. {
  120. $num = input('num',7);
  121. $calendar = get_calendar($num);
  122. $this->success('ok',['list'=>$calendar]);
  123. }
  124. /**
  125. * @title 获取足迹
  126. * @desc 获取足迹
  127. * @author qc
  128. * @url /api/General/getUserTrack
  129. * @method GET
  130. * @header name:Authorization require:1 desc:Token
  131. * @param name:type type:int default:1 desc:查询类型1商品2资讯
  132. * @param name:day_time type:string default:-- desc:查询时间(2022-04-22)
  133. * @return name:id type:int default:-- desc:足迹id
  134. * @return name:rel_id type:float default:-- desc:浏览的id(商品类型是商品id,资讯类型是资讯的id)
  135. * @return name:low_price type:float default:-- desc:商品最低价
  136. * @return name:max_price type:float default:-- desc:商品下划线价格
  137. * @return name:goods_cover type:string default:-- desc:商品封面
  138. * @return name:goods_name type:string default:-- desc:商品名
  139. * @return name:article_title type:string default:-- desc:资讯标题
  140. * @return name:article_cover type:string default:-- desc:资讯封面
  141. * @return name:video_url type:string default:-- desc:视频地址
  142. * @return name:read_num type:int default:-- desc:阅读量
  143. * @return name:article_type type:int default:-- desc:资讯类型(1图文,2视频)
  144. */
  145. public function getUserTrack()
  146. {
  147. $type = input('get.type',1);
  148. $day_time = input('get.day_time',date('Y-m-d'));
  149. $where = [];
  150. $where[] = ['t.user_id','=',$this->user_id];
  151. $where[] = ['t.type','=',$type];
  152. $where[] = ['t.year','=',date('Y',strtotime($day_time))];
  153. $where[] = ['t.month','=',date('m',strtotime($day_time))];
  154. $where[] = ['t.day','=',date('d',strtotime($day_time))];
  155. if($type == 1){
  156. $list = UserTrack::field('t.*,g.low_price,g.name goods_name,g.cover goods_cover')->where($where)
  157. ->alias('t')
  158. ->leftJoin('StoreGoods g','t.rel_id = g.id')
  159. ->order('t.update_int desc')
  160. ->select()->toArray();
  161. foreach ($list as &$v){
  162. $v['max_price'] = StoreGoodsItem::where('goods_id',$v['rel_id'])->max('original_price');
  163. }
  164. }else{
  165. $list = UserTrack::field('t.*,i.title article_title,i.cover article_cover,i.video_url,i.type article_type,i.read_num')->where($where)
  166. ->alias('t')
  167. ->leftJoin('InformationArticle i','t.rel_id = i.id')
  168. ->order('t.update_int desc')
  169. ->select()->toArray();
  170. }
  171. $this->success('ok',['list'=>$list]);
  172. }
  173. /**
  174. * @title 删除足迹
  175. * @desc 删除足迹
  176. * @author qc
  177. * @url /api/General/delUserTrack
  178. * @method POST
  179. * @header name:Authorization require:1 desc:Token
  180. * @param name:ids type:string default:-- desc:足迹id(多个用逗号隔开)
  181. */
  182. public function delUserTrack()
  183. {
  184. $ids = input('post.ids');
  185. UserTrack::where('id','in',$ids)->delete();
  186. $this->success('删除成功');
  187. }
  188. }