Usergreet.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Config;
  8. use think\Validate;
  9. use app\common\library\Token;
  10. use think\Db;
  11. use app\common\model\UserDeviceInfo;
  12. use onlogin\onlogin;
  13. use addons\epay\library\Service;
  14. use app\common\library\Wechat;
  15. use TencentCloud\Common\Credential;
  16. use TencentCloud\Common\Profile\ClientProfile;
  17. use TencentCloud\Common\Profile\HttpProfile;
  18. use TencentCloud\Common\Exception\TencentCloudSDKException;
  19. use TencentCloud\Faceid\V20180301\FaceidClient;
  20. use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  21. use TencentCloud\Iai\V20200303\IaiClient;
  22. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  23. /**
  24. * 女性设置自己的打招呼
  25. */
  26. class Usergreet extends Api
  27. {
  28. protected $noNeedLogin = [''];
  29. protected $noNeedRight = '*';
  30. //添加打招呼内容,女性使用
  31. public function addgreetcontent() {
  32. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  33. $title = input('title', '', 'trim'); //标题(type=1必传)
  34. $content = input('content', '', 'trim'); //内容
  35. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  36. if (!in_array($type, [0, 1, 2])) {
  37. $this->error('您的网络开小差了');
  38. }
  39. if ($content === '') {
  40. $this->error('请设置打招呼内容');
  41. }
  42. if (iconv_strlen($content, 'utf-8') > 255) {
  43. $this->error('打招呼内容太长了');
  44. }
  45. if ($type == 1) {
  46. if ($title === '') {
  47. $this->error('请输入语音名称');
  48. }
  49. if (iconv_strlen($title, 'utf-8') > 50) {
  50. $this->error('语音名称太长了');
  51. }
  52. if (!$duration) {
  53. $this->error('参数缺失');
  54. }
  55. }
  56. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  57. if ($count > 10) {
  58. $this->error('同一类型打招呼最多设置10条');
  59. }
  60. $data['user_id'] = $this->auth->id;
  61. $data['type'] = $type;
  62. $data['content'] = $content;
  63. if ($type == 1) {
  64. $data['title'] = $title;
  65. $data['duration'] = $duration;
  66. }
  67. $data['createtime'] = time();
  68. //查询是否有默认打招呼内容
  69. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  70. if (!$default_greet_count) {
  71. $data['is_default'] = 1;
  72. }
  73. $rs = Db::name('user_greet_content')->insertGetId($data);
  74. if (!$rs) {
  75. $this->error('您的网络开小差了');
  76. }
  77. $this->success('设置成功');
  78. }
  79. //查询打招呼内容,女性使用
  80. public function getgreetcontent() {
  81. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  82. if (!in_array($type, [0, 1, 2, 3])) {
  83. $this->error('您的网络开小差了');
  84. }
  85. if ($type == 3) {
  86. $list = Db::name('user_greet_content')->where(function ($query) {
  87. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  88. })->whereOr(function ($query) {
  89. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  90. })->select();
  91. } else {
  92. $where['user_id'] = $this->auth->id;
  93. $where['type'] = $type;
  94. $list = Db::name('user_greet_content')->where($where)->select();
  95. }
  96. if ($list) {
  97. foreach ($list as &$v) {
  98. if ($v['type'] != 0) {
  99. $v['content'] = one_domain_image($v['content']);
  100. }
  101. }
  102. }
  103. $this->success('打招呼内容', $list);
  104. }
  105. //设置默认打招呼内容,女性使用
  106. public function setdefaultgreet() {
  107. $id = input('id', 0, 'intval'); //打招呼id
  108. if (!$id) {
  109. $this->error('您的网络开小差了');
  110. }
  111. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  112. if (!$count) {
  113. $this->error('您的网络开小差了');
  114. }
  115. //开启事务
  116. Db::startTrans();
  117. //清除之前默认
  118. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  119. if ($rs === false) {
  120. Db::rollback();
  121. $this->error('您的网络开小差了');
  122. }
  123. //设置
  124. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  125. if ($rt === false) {
  126. Db::rollback();
  127. $this->error('您的网络开小差了');
  128. }
  129. Db::commit();
  130. $this->success('设置成功');
  131. }
  132. //删除打招呼内容,女性使用
  133. public function deldefaultgreet() {
  134. $id = input('id', 0, 'intval'); //打招呼id
  135. if (!$id) {
  136. $this->error('您的网络开小差了');
  137. }
  138. $mt_user_greet_content = Db::name('user_greet_content');
  139. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  140. if (!$info) {
  141. $this->error('您的网络开小差了');
  142. }
  143. //开启事务
  144. Db::startTrans();
  145. //删除
  146. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  147. if ($rs === false) {
  148. Db::rollback();
  149. $this->error('您的网络开小差了');
  150. }
  151. //若为默认打招呼内容则重新设置一条
  152. if ($info['is_default'] == 1) {
  153. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  154. if ($first_greet) {
  155. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  156. if ($rt === false) {
  157. Db::rollback();
  158. $this->error('您的网络开小差了');
  159. }
  160. }
  161. }
  162. Db::commit();
  163. $this->success('删除成功');
  164. }
  165. }