Index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\api\model\service\SearchLog;
  4. use app\common\controller\Api;
  5. use app\common\library\Sms;
  6. use think\Validate;
  7. /**
  8. * 首页接口
  9. */
  10. class Index extends Api
  11. {
  12. protected $noNeedLogin = ['getConfig','getText','trainList','trainDetail','help','templateConfig','getAppid'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 获取资料配置
  16. * @return void
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function getConfig()
  22. {
  23. if (!$this->request->isPost()) {
  24. $this->error('请求方式异常');
  25. }
  26. $row = model('app\api\model\service\ProjectConfig')
  27. ->where(['state'=>1])
  28. ->field('service_mobile,cooperate_mobile,user_image,user_name,refund_notice,user_intro,skill_image,skill_name,skill_intro,shop_image,shop_name,shop_intro,user_notice,skill_notice,shop_notice,skill_equity_info_id,shop_equity_info_id,user_privacy_info_id,user_agreement_info_id,service_privacy_info_id,service_agreement_info_id,shop_privacy_info_id,shop_agreement_info_id,plus_info_id,service_ensure_info_id,shop_ensure_info_id,recharge_info_id,withdraw_info_id,exchange_info_id')
  29. ->find();
  30. if(!$row){
  31. $this->error('未设置相关配置');
  32. }
  33. $this->success('请求成功',$row);
  34. }
  35. /**
  36. * 获取服务者商家appid
  37. * @return void
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public function getAppid()
  43. {
  44. $info = \app\api\model\service\ProjectConfigure::where('state',1)->field('skillappid,shopappid')->find();
  45. !$info && $this->error('管理员未配置');
  46. $this->success('信息返回成功',$info);
  47. }
  48. /**
  49. * 获取文本协议
  50. * @return void
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. public function getText()
  56. {
  57. if (!$this->request->isPost()) {
  58. $this->error('请求方式异常');
  59. }
  60. $id = $this->request->post('id/d','');
  61. !$id && $this->error('参数缺失');
  62. $row = model('app\api\model\service\ConfigText')
  63. ->where(['id'=>$id])
  64. ->field('content')
  65. ->find();
  66. !$row && $this->error('未找到相关协议');
  67. $row['content'] = htmlspecialchars_decode($row['content']);
  68. $this->success('信息返回成功',$row);
  69. }
  70. public function templateConfig()
  71. {
  72. if (!$this->request->isPost()) {
  73. $this->error('请求方式异常');
  74. }
  75. $templateConfig = db('service_mini_template')->where(['state'=>1])
  76. ->field('user_notice_template,user_order_template,order_finish_template,user_sales_template,user_complaint_template,skill_order_template,skill_sales_template,shop_order_template,shop_finish_template,shop_sales_template')
  77. ->find();
  78. $config = [];
  79. foreach ($templateConfig as $key=>$value)
  80. {
  81. $info = \app\api\model\service\MiniTemplate::getTemplateConfig($key);
  82. if($info['template_id'])
  83. {
  84. $config[$key] = $info['template_id'];
  85. }
  86. }
  87. $this->success('信息已处理',$config);
  88. }
  89. public function help()
  90. {
  91. if (!$this->request->isPost()) {
  92. $this->error('请求方式异常');
  93. }
  94. $page = input('page/d',1);
  95. $list = \app\api\model\service\CommonQuestions::where(['state'=>1])->field('id,title,content,createtime')->order('id desc')->page($page)->limit(30)->select();
  96. $this->success('信息返回成功',$list);
  97. }
  98. /**
  99. * 用户端个人中心
  100. * @return void
  101. * @throws \think\db\exception\DataNotFoundException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. * @throws \think\exception\DbException
  104. */
  105. public function userIndex()
  106. {
  107. $user = $this->auth->getUserinfo();
  108. $user['money'] = \app\api\model\service\User::where(['id'=>$user['id']])->value('money');
  109. $user['plusInfo'] = model('app\api\model\service\UserInfo')->where(['user_id'=>$user['id']])->field('is_plus,plustime,plusname')->find();
  110. $user['skillFollow'] = \app\api\model\service\Follow::getCount(['user_id'=>$user['id'],'state'=>1,'type'=>0]);
  111. $user['goodsFollow'] = \app\api\model\service\Follow::getCount(['user_id'=>$user['id'],'state'=>1,'type'=>1]);
  112. $user['shopFollow'] = \app\api\model\service\Follow::getCount(['user_id'=>$user['id'],'state'=>1,'type'=>2]);
  113. $user['orderCount'] = \app\api\model\service\Order::getCount(['user_id'=>$user['id']]);
  114. $user['couponCount'] = \app\api\model\service\UserCoupon::getCount(['user_id'=>$user['id'],'state'=>0]);
  115. $user['packageCount'] = \app\api\model\service\PackageOrder::getCount(['user_id'=>$user['id'],'status'=>1]);
  116. $this->success('信息返回成功',$user);
  117. }
  118. /**
  119. * 用户余额记录
  120. * @return void
  121. */
  122. public function moneyList()
  123. {
  124. $uid = $this->auth->id;
  125. $page = input('page/d',1);
  126. $list = \app\api\model\service\MoneyLog::getList(['user_id'=>$uid,'page'=>$page]);
  127. $this->success('信息返回成功',$list);
  128. }
  129. /**
  130. * 服务者/商户保证金记录
  131. * @return void
  132. */
  133. public function scoreList()
  134. {
  135. $uid = $this->auth->id;
  136. $page = input('page/d',1);
  137. $list = \app\api\model\service\ScoreLog::getList(['user_id'=>$uid,'page'=>$page]);
  138. $this->success('信息返回成功',$list);
  139. }
  140. /**
  141. * 用户修改信息
  142. * @return void
  143. */
  144. public function updateUserInfo()
  145. {
  146. $userInfo = $this->auth->getUserinfo();
  147. $type = input('type','');
  148. if($type == 'update')
  149. {
  150. if (!$this->request->isPost()) {
  151. $this->error('请求方式异常');
  152. }
  153. $post = input('post.','','trim,strip_tags');
  154. $isUpdate = \app\api\model\service\UserInfo::where(['user_id'=>$userInfo['id']])->value('is_update');
  155. $user = new \app\api\model\service\User();
  156. $user->allowField('avatar,nickname')->save($post,['id'=>$userInfo['id']]);
  157. if($isUpdate == 0)
  158. {
  159. \app\api\model\service\UserInfo::where(['user_id'=>$userInfo['id']])->update(['is_update'=>1]);
  160. }
  161. $this->success('信息已更新');
  162. }
  163. $this->success('信息返回成功',$user);
  164. }
  165. /**
  166. * 获取服务者商户培训资料
  167. * @return void
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\ModelNotFoundException
  170. * @throws \think\exception\DbException
  171. */
  172. public function trainList()
  173. {
  174. if (!$this->request->isPost()) {
  175. $this->error('请求方式异常');
  176. }
  177. $type = input('type/d',0);
  178. $page = input('page/d',0);
  179. $list = model('app\api\model\service\Train')
  180. ->where(['type'=>$type,'state'=>1])
  181. ->field('id,title,createtime,image,videofile')
  182. ->page($page)
  183. ->limit(10)
  184. ->select();
  185. $this->success('信息返回成功',$list);
  186. }
  187. /**
  188. * 搜索记录列表
  189. * @return void
  190. */
  191. public function searchLog()
  192. {
  193. $uid = $this->auth->id;
  194. $type = input('type','');
  195. if($type == 'del')
  196. {
  197. $id = input('id/d','');
  198. \app\api\model\service\SearchLog::where(['id'=>$id])->delete();
  199. $this->success('记录已删除');
  200. }
  201. $list = SearchLog::getList(['user_id'=>$uid]);
  202. $this->success('信息返回成功',$list);
  203. }
  204. public function updateUserMobile()
  205. {
  206. if (!$this->request->isPost()) {
  207. $this->error('请求方式异常');
  208. }
  209. $uid = $this->auth->id;
  210. $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,mobile')->find();
  211. $oldMobile = $this->request->post('oldmobile');
  212. $code = $this->request->post('code');
  213. !$oldMobile != $userInfo['mobile'] && $this->error('原有手机号输入错误');
  214. $mobile = $this->request->post('mobile');
  215. $captcha = $this->request->post('captcha');
  216. if (!$mobile || !$captcha) {
  217. $this->error(__('Invalid parameters'));
  218. }
  219. if (!Validate::regex($mobile, "^1\d{10}$")) {
  220. $this->error(__('Mobile is incorrect'));
  221. }
  222. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $userInfo['id'])->find()) {
  223. $this->error(__('Mobile already exists'));
  224. }
  225. $result = Sms::check($mobile, $captcha, 'changemobile');
  226. if (!$result) {
  227. $this->error(__('Captcha is incorrect'));
  228. }
  229. $user = $this->auth->getUser();
  230. $verification = $user->verification;
  231. $verification->mobile = 1;
  232. $user->verification = $verification;
  233. $user->mobile = $mobile;
  234. $user->save();
  235. model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->update(['mobile'=>$mobile]);
  236. Sms::flush($mobile, 'changemobile');
  237. }
  238. public function updateUser()
  239. {
  240. $uid = $this->auth->id;
  241. $userInfo = \app\api\model\service\UserInfo::getUserMoney($uid);
  242. $type = input('type','');
  243. if($type == 'update')
  244. {
  245. if (!$this->request->isPost()) {
  246. $this->error('请求方式异常');
  247. }
  248. $post = input('post.','','trim,strip_tags');
  249. $user = new \app\api\model\service\UserInfo();
  250. $user->allowField('alipay_name,alipay_account,bank_name,bank_user,bank_card')->save($post,['id'=>$userInfo['id']]);
  251. $this->success('信息已更新');
  252. }
  253. $this->success('信息返回成功',$userInfo);
  254. }
  255. }