Yutang.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\Areahot;
  4. use app\admin\model\Arealog;
  5. use app\admin\model\Method;
  6. use app\admin\model\method\Fish;
  7. use app\admin\model\method\Time;
  8. use app\admin\model\Pingjia;
  9. use app\admin\model\Shoucang;
  10. use app\common\controller\Api;
  11. use \app\admin\model\Yutang as YutangModel;
  12. use app\common\model\Area;
  13. use think\Db;
  14. use think\exception\PDOException;
  15. use think\exception\ValidateException;
  16. /**
  17. * 鱼塘接口
  18. */
  19. class Yutang extends Api
  20. {
  21. protected $noNeedLogin = ['config_data'];
  22. protected $noNeedRight = ['*'];
  23. /**
  24. * 鱼塘添加
  25. * @ApiMethod (POST)
  26. * @param string $image 鱼塘主图
  27. * @param string $name 鱼塘名称
  28. * @param int $province 省id
  29. * @param int $city 市id
  30. * @param int $area 区id
  31. * @param string $addrss 详细地址
  32. * @param string $lat 经度
  33. * @param string $lon 维度
  34. * @param string $phone 联系方式
  35. * @param string $license 营业知晓
  36. * @param string $video 视频文件
  37. * @return void
  38. */
  39. public function config_data(){
  40. $data=['release_price'=>config('site.release_price')];
  41. $this->success('系统参数',$data);
  42. }
  43. public function add_yutang(){
  44. $yutang_model = new YutangModel();
  45. $data = input();
  46. $yutang_data = [
  47. 'image'=>$data['image'],
  48. 'name'=>$data['name'],
  49. 'province'=>$data['province'],
  50. 'city'=>$data['city'],
  51. 'area'=>$data['area'],
  52. 'address'=>$data['address'],
  53. 'latitude'=>$data['lat'],
  54. 'longitude'=>$data['lon'],
  55. 'phone'=>$data['phone'],
  56. 'video'=>$data['video'],
  57. 'license'=>$data['license'],
  58. 'price'=>config('site.release_price'),
  59. 'status'=>1,
  60. 'user_id'=>$this->auth->id,
  61. 'order_no'=> time().$this->auth->id,
  62. ];
  63. $yutang_id = $yutang_model->insertGetId($yutang_data);
  64. $this->success('鱼塘创建成功',$yutang_data['order_no']);
  65. }
  66. /**
  67. * 鱼塘列表
  68. * @return void
  69. */
  70. public function yutang_list(){
  71. $yutang_model = new YutangModel();
  72. $area_model = new \app\admin\model\shopro\Area();
  73. $list = $yutang_model->where(array('user_id'=>$this->auth->id,'status'=>2))->paginate();
  74. foreach ($list as &$v){
  75. $v['sheng'] = $area_model->where('id',$v['province'])->value('name');
  76. $v['shi'] = $area_model->where('id',$v['city'])->value('name');
  77. $v['qu'] = $area_model->where('id',$v['area'])->value('name');
  78. }
  79. $this->success('我的鱼塘列表',$list);
  80. }
  81. public function yutang_edit(){
  82. $yutang_model = new YutangModel();
  83. $data = input();
  84. $yutang_data = [
  85. 'image'=>$data['image'],
  86. 'name'=>$data['name'],
  87. 'province'=>$data['province'],
  88. 'city'=>$data['city'],
  89. 'area'=>$data['area'],
  90. 'address'=>$data['address'],
  91. 'latitude'=>$data['lat'],
  92. 'longitude'=>$data['lon'],
  93. 'phone'=>$data['phone'],
  94. 'video'=>$data['video'],
  95. 'license'=>$data['license'],
  96. 'status'=>2,
  97. ];
  98. $yutang_model->isUpdate('true',['id'=>$data['id']])->save($yutang_data);
  99. $this->success('鱼塘编辑成功');
  100. }
  101. public function yutang_delete(){
  102. $yutang_model = new YutangModel();
  103. $data = input();
  104. $yutang_model->isUpdate('true',['id'=>$data['id']])->save(['status'=>1]);
  105. $this->success('鱼塘删除成功');
  106. }
  107. /**
  108. *鱼塘详情
  109. * @return void
  110. * @throws \think\db\exception\DataNotFoundException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. * @throws \think\exception\DbException
  113. */
  114. public function yutang_info(){
  115. $id = input('id');
  116. $yuntang_model = new YutangModel();
  117. $area_model = new \app\admin\model\shopro\Area();
  118. $info = $yuntang_model->where('id',$id)->find();
  119. $info['sheng'] = $area_model->where('id',$info['province'])->value('name');
  120. $info['shi'] = $area_model->where('id',$info['city'])->value('name');
  121. $info['qu'] = $area_model->where('id',$info['area'])->value('name');
  122. $this->success('我的鱼塘详情',$info);
  123. }
  124. /**
  125. * 发布玩法
  126. */
  127. public function method_add(){
  128. $method_model = new Method();
  129. $yutang_model = new \app\admin\model\Yutang();
  130. $Notification_model = new Notification();
  131. $area_model = new \app\admin\model\shopro\Area();
  132. $data = input();
  133. $info = $yutang_model->where('id',$data['yutang_id'])->field('latitude,longitude,name,city')->find();
  134. $yutang_city=$area_model->where('id',$info['city'])->value('name');
  135. $method_data = [
  136. 'type'=>$data['type'],
  137. 'video'=>$data['video'],
  138. 'show_images'=>$data['show_images'],
  139. 'put_time'=>$data['put_time'],
  140. 'sta_number'=>$data['sta_number'],
  141. 'biaoyu'=>$data['biaoyu'],
  142. 'shouprice'=>$data['shouprice'],
  143. 'eat'=>$data['eat'],
  144. 'eat_price' => $data['eat_price'],
  145. 'kongwei'=>$data['kongwei'],
  146. 'yajin'=>$data['yajin'],
  147. 'yutang_id'=>$data['yutang_id'],
  148. 'yutang_name'=>$info['name'],
  149. 'desc'=>$data['desc'],
  150. 'yingye'=>$data['yingye'],
  151. 'moshi'=>$data['moshi'],
  152. 'tuisong'=>$data['tuisong'],
  153. 'latitude'=>$info['latitude'],
  154. 'longitude'=>$info['longitude'],
  155. 'max'=>$data['max'],
  156. 'min'=>$data['min'],
  157. 'tianqi'=> $data['tianqi'],
  158. 'createtime'=>time(),
  159. 'huodong_time'=>$data['huodong_time'],
  160. 'user_id'=>$this->auth->id,
  161. ];
  162. // $data['fish']=[['fish_name'=>'草鱼','fish_weight'=>'100','fish_dan'=>'10']];
  163. // $data['time']=[['title'=>'啊啊啊啊','price'=>'100','type'=>1,'number'=>10,'is_set'=>1]];
  164. Db::startTrans();
  165. try {
  166. if($data['moshi']!=1){
  167. $method_model->isUpdate('true',['yutang_id'=>$data['yutang_id'],'status'=>1])->save(['status'=>2]);
  168. }
  169. $method_id = $method_model->insertGetId($method_data);
  170. $fish=0;
  171. foreach ($data['fish'] as &$v){
  172. $fish_data[]=[
  173. 'm_id'=>$method_id,
  174. 'fish_name'=>$v['fish_name'],
  175. 'fish_weight'=>$v['fish_weight'],
  176. 'fish_dan'=>$v['fish_dan']
  177. ];
  178. $fish +=$v['fish_weight'];
  179. }
  180. $method_fish_model = new Fish();
  181. $method_fish_model->insertAll($fish_data);
  182. foreach ($data['time'] as &$v){
  183. $time_data[] = [
  184. 'm_id'=>$method_id,
  185. 'title'=>$v['title'],
  186. 'price'=>$v['price'],
  187. 'type'=>$v['type'],
  188. 'seat_num'=>$v['number'],
  189. 'sale_num'=>$v['number'],
  190. 'is_set'=>$v['is_set']
  191. ];
  192. }
  193. $method_time_model = new Time();
  194. $method_time_model->insertAll($time_data);
  195. $Notification_model->dingyuexiaoxi($data['type'],$data['tuisong'],$info['name'],$fish,$data['time'][0]['price'],$data['moshi'],$yutang_city,$this->auth->id);
  196. Db::commit();
  197. $this->success('发布成功');
  198. } catch (ValidateException|PDOException|Exception $e) {
  199. Db::rollback();
  200. $this->error('发布失败');
  201. }
  202. }
  203. /**
  204. * 发布玩法
  205. */
  206. public function method_edit(){
  207. $method_model = new Method();
  208. $yutang_model = new \app\admin\model\Yutang();
  209. $Notification_model = new Notification();
  210. $area_model = new \app\admin\model\shopro\Area();
  211. $data = input();
  212. $info = $yutang_model->where('id',$data['yutang_id'])->field('latitude,longitude,name,city')->find();
  213. $yutang_city=$area_model->where('id',$info['city'])->value('name');
  214. $method_data = [
  215. 'type'=>$data['type'],
  216. 'show_images'=>$data['show_images'],
  217. 'put_time'=>$data['put_time'],
  218. 'sta_number'=>$data['sta_number'],
  219. 'biaoyu'=>$data['biaoyu'],
  220. 'shouprice'=>$data['shouprice'],
  221. 'eat'=>$data['eat'],
  222. 'eat_price' => $data['eat_price'],
  223. 'kongwei'=>$data['kongwei'],
  224. 'yajin'=>$data['yajin'],
  225. 'yutang_id'=>$data['yutang_id'],
  226. 'yutang_name'=>$info['name'],
  227. 'desc'=>$data['desc'],
  228. 'yingye'=>$data['yingye'],
  229. 'moshi'=>$data['moshi'],
  230. 'tuisong'=>$data['tuisong'],
  231. 'latitude'=>$info['latitude'],
  232. 'longitude'=>$info['longitude'],
  233. 'max'=>$data['max'],
  234. 'min'=>$data['min'],
  235. 'tianqi'=> $data['tianqi'],
  236. 'createtime'=>time(),
  237. 'huodong_time'=>$data['huodong_time'],
  238. 'user_id'=>$this->auth->id,
  239. ];
  240. // $data['fish']=[['fish_name'=>'草鱼','fish_weight'=>'100','fish_dan'=>'10']];
  241. // $data['time']=[['title'=>'啊啊啊啊','price'=>'100']];
  242. Db::startTrans();
  243. try {
  244. $method_model->isUpdate('true',['id'=>$data['method_id']])->save($method_data);
  245. foreach ($data['fish'] as &$v){
  246. $fish_data[]=[
  247. 'fish_name'=>$v['fish_name'],
  248. 'fish_weight'=>$v['fish_weight'],
  249. 'fish_dan'=>$v['fish_dan']
  250. ];
  251. $method_fish_model = new Fish();
  252. $method_fish_model->isUpdate('true',['id'=>$v['id']])->save($fish_data);
  253. }
  254. foreach ($data['time'] as &$v){
  255. $time_data[] = [
  256. 'title'=>$v['title'],
  257. 'price'=>$v['price'],
  258. ];
  259. $method_time_model = new Time();
  260. $method_time_model->isUpdate('true',['id'=>$v['id']])->save($time_data);
  261. }
  262. Db::commit();
  263. $this->success('发布成功');
  264. } catch (ValidateException|PDOException|Exception $e) {
  265. Db::rollback();
  266. $this->error('发布失败');
  267. }
  268. }
  269. /**
  270. * 上次发布信息
  271. * @return void
  272. * @throws \think\db\exception\DataNotFoundException
  273. * @throws \think\db\exception\ModelNotFoundException
  274. * @throws \think\exception\DbException
  275. */
  276. public function last_method(){
  277. $method_model = new Method();
  278. $fish_model =new Fish();
  279. $method_time_model = new Time();
  280. $yutang_model = new \app\admin\model\Yutang();
  281. $info = $method_model->where('user_id',$this->auth->id)->order('id','DESC')->find();
  282. if(empty($info)){
  283. $this->error('还没有发布过鱼塘');
  284. }
  285. $info['fish'] = $fish_model->where('m_id',$info['id'])->select();
  286. $info['time'] = $method_time_model->where('m_id',$info['id'])->select();
  287. $info['yutang'] = $yutang_model->alias('y')
  288. ->join('area a','a.id=y.province','left')
  289. ->join('area r','r.id=y.city','left')
  290. ->join('area e','e.id=y.area','left')
  291. ->where('y.id',$info['yutang_id'])->field('y.*,a.name sheng,r.name shi,e.name qu')->find();
  292. $this->success('上次发布信息',$info);
  293. }
  294. /**
  295. * 发布内容详情
  296. * @return void
  297. * @throws \think\db\exception\DataNotFoundException
  298. * @throws \think\db\exception\ModelNotFoundException
  299. * @throws \think\exception\DbException
  300. */
  301. public function method_info(){
  302. $method_model = new Method();
  303. $fish_model = new Fish();
  304. $time_model = new Time();
  305. $shoucang_model = new Shoucang();
  306. $yutang_model = new \app\admin\model\Yutang();
  307. $pingjia_model = new Pingjia();
  308. $id = input('id');
  309. $info = $method_model->where('id',$id)->find();
  310. $info['fish']=$fish_model->where('m_id',$info['id'])->select();
  311. $info['time']=$time_model->where('m_id',$info['id'])->select();
  312. $info['is_have']=0;
  313. $rebate = rebate($info['type'],$info['moshi']);
  314. $info['lijianjin']= $rebate['reduction'];;
  315. $is_have =$shoucang_model->where(['method_id'=>$id,'user_id'=>$this->auth->id])->find();
  316. if($is_have){
  317. $info['is_have']=1;
  318. }
  319. $info['yutang'] = $yutang_model->alias('y')
  320. ->join('area a','a.id=y.province','left')
  321. ->join('area r','r.id=y.city','left')
  322. ->join('area e','e.id=y.area','left')
  323. ->where('y.id',$info['yutang_id'])->field('y.*,a.name sheng,r.name shi,e.name qu')->find();
  324. $info['pingjia'] = $pingjia_model->alias('p')->join('user u','u.id=p.user_id')->where('p.yutang_id',$info['yutang_id'])->order('p.score','desc')->field('p.*,u.nickname,u.avatar')->find();
  325. $this->success('发布内容详情',$info);
  326. }
  327. /**
  328. * 鱼塘玩法列表
  329. * @return void
  330. * @throws \think\db\exception\DataNotFoundException
  331. * @throws \think\db\exception\ModelNotFoundException
  332. * @throws \think\exception\DbException
  333. */
  334. public function method_list(){
  335. $seach = input('seach');
  336. $type = input('type');
  337. $moshi = input('moshi');
  338. $lat = input('latitude');
  339. $lng = input('longitude');
  340. $method_model = new Method();
  341. $fish_model = new Fish();
  342. $yutang_model = new \app\admin\model\Yutang();
  343. $shoucang_model = new Shoucang();
  344. $time_model = new Time();
  345. $where = [];
  346. if($type){
  347. $where['type'] = ['=', $type];
  348. }
  349. if($moshi){
  350. $where['moshi'] = ['=', $moshi];
  351. }
  352. if($seach){
  353. $where['yutang_name'] = ['like', '%'.$seach.'%'];
  354. }
  355. $distance = "(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*(" . $lat . "-latitude)/360),2)+COS(3.1415926535898*" . $lat . "/180)* COS(latitude * 3.1415926535898/180)*POW(SIN(3.1415926535898*(" . $lng . "-longitude)/360),2))))";
  356. $list = $method_model->alias('s')->order('id','desc')->where('s.status',1)->where($where)->field( ['s.*',
  357. $distance.'juli'
  358. ])->order('juli','desc')->paginate();
  359. $list=$list->items();
  360. foreach ($list as &$v){
  361. $rebate = rebate($v['type'],$v['moshi']);
  362. $v['lijianjin']= $rebate['reduction'];
  363. $v['is_have']=0;
  364. $is_have =$shoucang_model->where(['method_id'=>$v['id'],'user_id'=>$this->auth->id])->find();
  365. if($is_have){
  366. $v['is_have']=1;
  367. }
  368. $v['fist_list'] = $fish_model->where('m_id',$v['id'])->select();
  369. $v['time_list'] = $time_model->where('m_id',$v['id'])->select();
  370. $v['price'] = $time_model->where('m_id',$v['id'])->where('type',1)->order('price','asc')->value('price');;
  371. $v['count'] = 110;
  372. $v['pingfen']=$yutang_model->where('id',$v['yutang_id'])->value('pingjie');
  373. }
  374. $yutang=$yutang_model->alias('s')->field(['s.*', $distance.'juli'])->order('juli','desc')->select();
  375. foreach ($yutang as $k=>$vv){
  376. if($yutang[$k]['juli']>10){
  377. unset($vv);
  378. }
  379. }
  380. $count = count($yutang);
  381. $data=['list'=>$list,'yutang'=>$yutang,'count'=>$count];
  382. // dump($data['yutang']);die;
  383. $this->success('玩法列表',$data);
  384. }
  385. /**
  386. * 鱼塘玩法列表
  387. * @return void
  388. * @throws \think\db\exception\DataNotFoundException
  389. * @throws \think\db\exception\ModelNotFoundException
  390. * @throws \think\exception\DbException
  391. */
  392. public function shop_method_list(){
  393. $method_model = new Method();
  394. $fish_model = new Fish();
  395. $yutang_model = new \app\admin\model\Yutang();
  396. $area_model = new \app\admin\model\shopro\Area();
  397. $list = $method_model->order('id','desc')->where('user_id',$this->auth->id)->paginate();
  398. $list=$list->items();
  399. foreach ($list as &$v){
  400. $v['fist_list'] = $fish_model->where('m_id',$v['id'])->select();
  401. $yutang_info = $yutang_model->where('id',$v['yutang_id'])->find();
  402. $sheng = $area_model->where('id',$yutang_info['province'])->value('name');
  403. $shi = $area_model->where('id',$yutang_info['city'])->value('name');
  404. $qu = $area_model->where('id',$yutang_info['area'])->value('name');
  405. $v['address'] = $sheng.$shi.$qu.$yutang_info['address'];
  406. }
  407. $data=['list'=>$list];
  408. $this->success('玩法列表',$data);
  409. }
  410. /**
  411. * 搜索历史
  412. * @return void
  413. * @throws \think\db\exception\DataNotFoundException
  414. * @throws \think\db\exception\ModelNotFoundException
  415. * @throws \think\exception\DbException\
  416. */
  417. public function arealog_list(){
  418. $arealog_model = new Arealog();
  419. $list = $arealog_model->where('user_id',$this->auth->id)->select();
  420. $this->success('搜索历史',$list);
  421. }
  422. /**
  423. * 添加搜素历史
  424. * @return void
  425. */
  426. public function address_log(){
  427. $arealog_model = new Arealog();
  428. $data = input();
  429. $log_data = ['city'=>$data['city'],'user_id'=>$this->auth->id];
  430. $arealog_model->insert($log_data);
  431. }
  432. /**
  433. * 热门城市
  434. * @return void
  435. * @throws \think\db\exception\DataNotFoundException
  436. * @throws \think\db\exception\ModelNotFoundException
  437. * @throws \think\exception\DbException
  438. */
  439. public function area_hot(){
  440. $areahot_model = new Areahot();
  441. $list = $areahot_model->order('id','desc')->select();
  442. $this->success('热门城市',$list);
  443. }
  444. public function shoucang(){
  445. $method_id = input('method_id');
  446. $shoucang_model = new Shoucang();
  447. $is_have =$shoucang_model->where(['method_id'=>$method_id,'user_id'=>$this->auth->id])->find();
  448. if($is_have){
  449. $shoucang_model->where(['method_id'=>$method_id,'user_id'=>$this->auth->id])->delete();
  450. $this->success('收藏取消');
  451. }
  452. else{
  453. $shoucang_model->insert(['method_id'=>$method_id,'user_id'=>$this->auth->id]);
  454. $this->success('收藏成功');
  455. }
  456. }
  457. }