Skill.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. use think\Loader;
  5. /**
  6. * 首页接口
  7. */
  8. class Skill extends Api
  9. {
  10. protected $noNeedLogin = ['nearSkill','searchSkill','skillInfo','getSampleSkill'];
  11. protected $noNeedRight = ['*'];
  12. public function _initialize()
  13. {
  14. parent::_initialize();
  15. }
  16. /**
  17. * 申请服务人员,完善资料
  18. * @return void
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function apply()
  24. {
  25. $uid = $this->auth->id;
  26. $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_skill')->find();
  27. $info = model('app\api\model\service\ApplySkill')->where(['user_id'=>$uid])->find();
  28. if (!$this->request->isPost()) {
  29. $this->error('请求方式异常');
  30. }
  31. $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
  32. $type = input('type','');
  33. $applySkill = new \app\api\model\service\ApplySkill();
  34. $post['user_id'] = $uid;
  35. $post['updatetime'] = time();
  36. if(in_array($type,['add','edit']))
  37. {
  38. $validate = Loader::validate('service.ApplySkill');
  39. if(!$validate->scene($type)->check($post)){
  40. $this->error($validate->getError());
  41. }
  42. }
  43. if($type == 'add')
  44. {
  45. $userInfo['is_skill'] == 1 && $this->error('请勿重复申请');
  46. unset($post['type']);
  47. $applySkill->data($post)->save();
  48. $this->success('申请已提交,等待审核');
  49. }elseif($type == 'edit') {
  50. unset($post['type']);
  51. $post['state'] = 0;
  52. $applySkill->allowField(true)->save($post,['id'=>$info['id']]);
  53. $this->success('申请已提交,等待审核');
  54. }elseif ($type == 'perfect') {
  55. $post['state'] = 0;
  56. $post['applytype'] = 1;
  57. $applySkill->allowField(true)->save($post,['id'=>$info['id']]);
  58. $this->success('申请已提交,等待审核');
  59. }
  60. if($info){
  61. $info['skillCateName'] = \app\api\model\service\SkillCate::getName($info['skill_cate_id']);
  62. }
  63. $this->success('信息返回成功',$info);
  64. }
  65. public function addGoodsTime()
  66. {
  67. $id = input('id/d','');
  68. $ids = input('ids','');
  69. $order = \app\api\model\service\Order::where(['id'=>$id,'state'=>['in',[2,3,4,5]]])->field('id,skill_id,actendtime')->find();
  70. $addIds = explode(',',$ids);
  71. $totalCostSeconds = 0;
  72. $payprice = 0;
  73. foreach ($addIds as $val)
  74. {
  75. $info = \app\api\model\service\GoodsAdd::where(['id'=>$val,'state'=>1])->find();
  76. if(!$info){
  77. $this->error('当前有附加项目无法使用,请刷新后重试');
  78. }
  79. $totalCostSeconds+=$info['cost_seconds'];
  80. $payprice+=$info['price'];
  81. }
  82. if($order)
  83. {
  84. $endTime = $order['actendtime']+$totalCostSeconds;
  85. $exist = \app\api\model\service\SkillTime::where(['skill_id'=>$order['skill_id'],'state'=>['>',0],'starttime'=>['between',[$order['actendtime'],$endTime]]])->value('id');
  86. $exist && $this->error('当前服务者已被预约,暂时无法接单');
  87. }
  88. $this->success('信息返回成功',['payprice'=>$payprice,'totalCostSeconds'=>$totalCostSeconds]);
  89. }
  90. /**
  91. * 首页附近服务人员
  92. * @return void
  93. */
  94. public function nearSkill()
  95. {
  96. if (!$this->request->isPost()) {
  97. $this->error('请求方式异常');
  98. }
  99. $post = input('post.','','trim,strip_tags');
  100. $post['limit'] = 10;
  101. !$post['city'] && $this->error('城市信息缺失');
  102. (!$post['lng'] || !$post['lat']) && $this->error('定位信息异常');
  103. $nearSkill = \app\api\model\service\Skill::nearSkill($post);
  104. if($nearSkill)
  105. {
  106. foreach ($nearSkill as &$value)
  107. {
  108. $value['skillCate'] = model('app\api\model\service\SkillCate')->where('id',$value['skill_cate_id'])->value('name');
  109. $value['skillTime'] = \app\api\model\service\SkillTime::getSkillTime($value['id']);
  110. $value['good_comment_percent'] = \app\api\model\service\Comment::skillGoodPercent(['skill_id'=>$value['id']]);
  111. }
  112. }
  113. $this->success('信息返回成功',$nearSkill);
  114. }
  115. /**
  116. * 查询服务人员列表
  117. * @return void
  118. */
  119. public function searchSkill()
  120. {
  121. if (!$this->request->isPost()) {
  122. $this->error('请求方式异常');
  123. }
  124. $post = input('post.','','trim,strip_tags');
  125. $post['limit'] = 10;
  126. $post['page'] = input('page/d',1);
  127. !$post['city'] && $this->error('城市信息缺失');
  128. (!$post['lng'] || !$post['lat']) && $this->error('定位信息异常');
  129. $list = \app\api\model\service\Skill::searchSkill($post);
  130. if($list)
  131. {
  132. foreach ($list as &$value)
  133. {
  134. $value['shopname'] = $value['shop_id']?\app\api\model\service\Shop::getName($value['shop_id']):'';
  135. $value['skillTime'] = \app\api\model\service\SkillTime::getSkillTime($value['id']);
  136. $value['skillCate'] = \app\api\model\service\SkillCate::where('id',$value['skill_cate_id'])->value('name');
  137. $value['commentCount'] = \app\api\model\service\Comment::getCount(['skill_id'=>$value['id'],'state'=>1]);
  138. $value['good_comment_percent'] = \app\api\model\service\Comment::skillGoodPercent(['skill_id'=>$value['id']]);
  139. }
  140. }
  141. $this->success('信息返回成功',$list);
  142. }
  143. /**
  144. * 获取服务人员详情
  145. * @return void
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\ModelNotFoundException
  148. * @throws \think\exception\DbException
  149. */
  150. public function skillInfo()
  151. {
  152. if (!$this->request->isPost()) {
  153. $this->error('请求方式异常');
  154. }
  155. $uid = $this->auth->isLogin()?$this->auth->id:'';
  156. $id = input('id/d','');
  157. $lng = input('lng');
  158. $lat = input('lat');
  159. $info = \app\api\model\service\Skill::getInfo($id,$uid);
  160. !$info && $this->error('服务人员信息异常');
  161. $info['distance'] = \addons\service\library\Common::distance($lng,$lat,$info['lng'],$info['lat']);
  162. $info['skillTime'] = \app\api\model\service\SkillTime::getSkillTime($info['id']);
  163. $info['good_comment_percent'] = \app\api\model\service\Comment::skillGoodPercent(['skill_id'=>$info['id']]);
  164. $this->success('信息返回成功',$info);
  165. }
  166. /**
  167. * 加入商户
  168. * @return void
  169. * @throws \think\db\exception\DataNotFoundException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. * @throws \think\exception\DbException
  172. */
  173. public function joinShop()
  174. {
  175. $uid = $this->auth->id;
  176. $skill = \app\api\model\service\Skill::getSkillShop($uid);
  177. $data['skill'] = $skill;
  178. $data['joinShop'] = \app\api\model\service\JoinShop::where(['skill_id'=>$skill['id']])->order('id desc')->find();
  179. $type = input('type','','trim,strip_tags');
  180. if(is_numeric($type)){
  181. if (!$this->request->isPost()) {
  182. $this->error('请求方式异常');
  183. }
  184. $skill['shop_id'] && $this->error('请勿重复申请');
  185. $info = \app\api\model\service\JoinShop::where(['skill_id'=>$skill['id'],'state'=>['>=',0]])->field('id,code,shop_name,state')->order('id desc')->find();
  186. ($info && $info['state']>=0) && $this->error('请勿重复申请');
  187. if($type)
  188. {
  189. $code = input('code/s','','trim,strip_tags');
  190. $shop = \app\api\model\service\Shop::where(['code'=>$code,'state'=>1])->field('id,name,code')->find();
  191. }else{
  192. $id = input('id/d','','trim,strip_tags');
  193. $shop = \app\api\model\service\Shop::where(['id'=>$id,'state'=>1])->field('id,name,code')->find();
  194. }
  195. !$shop && $this->error('所选商家信息异常');
  196. \app\api\model\service\JoinShop::create(['skill_id'=>$skill['id'],'skill_name'=>$skill['name'],'shop_id'=>$shop['id'],'code'=>$shop['code'],'shop_name'=>$shop['name']]);
  197. $this->success('申请已提交,等待审核');
  198. }
  199. $this->success('信息返回成功',$data);
  200. }
  201. public function skillIndex()
  202. {
  203. if (!$this->request->isPost()) {
  204. $this->error('请求方式异常');
  205. }
  206. $uid = $this->auth->id;
  207. $skill = \app\api\model\service\Skill::where(['user_id'=>$uid])->field('id,code,ensure_price,name,sex,image,goods_ids,skill_cate_id')->find();
  208. !$skill && $this->error('非服务者无法访问');
  209. $skill['skillCateName'] = \app\api\model\service\SkillCate::getName($skill['skill_cate_id']);
  210. $data['userInfo'] = \app\api\model\service\UserInfo::where(['user_id'=>$uid])->field('money,shop_money')->find();
  211. $data['skill'] = $skill;
  212. $data['goodsCount'] = count(explode(',',$skill['goods_ids']));
  213. $this->success('服务者信息返回成功',$data);
  214. }
  215. public function skillHome()
  216. {
  217. $uid = $this->auth->id;
  218. $skillId = input('skill_id/d','')?:\app\api\model\service\Skill::where(['user_id'=>$uid])->value('id');
  219. !$skillId && $this->error('非服务者无法访问');
  220. $data['orderCount'] = \app\api\model\service\Order::getSkillOrderCount(['skill_id'=>$skillId,'status'=>['in',[2,3,4,5]],'is_service'=>['in',[0,-1]]]);
  221. $this->success('信息返回成功',$data);
  222. }
  223. /**
  224. * 服务者获取时间更新时间状态
  225. * @return void
  226. * @throws \think\db\exception\DataNotFoundException
  227. * @throws \think\db\exception\ModelNotFoundException
  228. * @throws \think\exception\DbException
  229. */
  230. public function skillTime()
  231. {
  232. if (!$this->request->isPost()) {
  233. $this->error('请求方式异常');
  234. }
  235. $uid = $this->auth->id;
  236. $skillId = input('skill_id/d','');
  237. $skillId = $skillId?$skillId:\app\api\model\service\Skill::where(['user_id'=>$uid])->value('id');
  238. !$skillId && $this->error('非服务者无法访问');
  239. $timetype = input('timetype/d',0);
  240. $ids = input('ids','');
  241. $list = \app\api\model\service\SkillTime::where(['timetype'=>$timetype,'skill_id'=>$skillId])->field('id,timetype,number,state,starttime,endtime')->select();
  242. $type = input('type','');
  243. if($type)
  244. {
  245. $re = \app\api\model\service\SkillTime::updateTime($ids,$skillId,$type);
  246. !$re && $this->error('更新失败');
  247. $this->success('时间状态已更改');
  248. }
  249. $this->success('信息返回成功',$list);
  250. }
  251. /**
  252. * 更新服务者部分信息
  253. * @return void
  254. * @throws \think\db\exception\DataNotFoundException
  255. * @throws \think\db\exception\ModelNotFoundException
  256. * @throws \think\exception\DbException
  257. */
  258. public function updateSkillInfo()
  259. {
  260. if (!$this->request->isPost()) {
  261. $this->error('请求方式异常');
  262. }
  263. $uid = $this->auth->id;
  264. $skillId = input('skill_id/d','');
  265. $skillId = $skillId?$skillId:\app\api\model\service\Skill::where(['user_id'=>$uid])->value('id');
  266. $skill = \app\api\model\service\Skill::where(['id'=>$skillId])->field('id,province,city,district,address,lng,lat,is_rest,is_train,code,percent')->find();
  267. $type = input('type','');
  268. if($type == 'update')
  269. {
  270. $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
  271. model('app\api\model\service\Skill')->allowField('province,city,district,address,lng,lat,is_rest,percent')->save($post,['id'=>$skillId]);
  272. $this->success('信息已更新');
  273. }
  274. $this->success('信息返回成功',$skill);
  275. }
  276. public function getSampleSkill()
  277. {
  278. if (!$this->request->isPost()) {
  279. $this->error('请求方式异常');
  280. }
  281. $id = input('id/d','');
  282. $skill = \app\api\model\service\Skill::where(['id'=>$id])->field('id,mobile,code,name,idcard,health_image,certificate_image,image')->find();
  283. $skill['idcard'] = substr_replace($skill['idcard'],'******',6,6);
  284. $this->success('信息返回成功',$skill);
  285. }
  286. }