123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Areahot;
- use app\admin\model\Arealog;
- use app\admin\model\Method;
- use app\admin\model\method\Fish;
- use app\admin\model\method\Time;
- use app\admin\model\Pingjia;
- use app\admin\model\Shoucang;
- use app\common\controller\Api;
- use \app\admin\model\Yutang as YutangModel;
- use app\common\model\Area;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- /**
- * 鱼塘接口
- */
- class Yutang extends Api
- {
- protected $noNeedLogin = ['config_data'];
- protected $noNeedRight = ['*'];
- /**
- * 鱼塘添加
- * @ApiMethod (POST)
- * @param string $image 鱼塘主图
- * @param string $name 鱼塘名称
- * @param int $province 省id
- * @param int $city 市id
- * @param int $area 区id
- * @param string $addrss 详细地址
- * @param string $lat 经度
- * @param string $lon 维度
- * @param string $phone 联系方式
- * @param string $license 营业知晓
- * @param string $video 视频文件
- * @return void
- */
- public function config_data(){
- $data=['release_price'=>config('site.release_price')];
- $this->success('系统参数',$data);
- }
- public function add_yutang(){
- $yutang_model = new YutangModel();
- $data = input();
- $yutang_data = [
- 'image'=>$data['image'],
- 'name'=>$data['name'],
- 'province'=>$data['province'],
- 'city'=>$data['city'],
- 'area'=>$data['area'],
- 'address'=>$data['address'],
- 'latitude'=>$data['lat'],
- 'longitude'=>$data['lon'],
- 'phone'=>$data['phone'],
- 'video'=>$data['video'],
- 'license'=>$data['license'],
- 'price'=>config('site.release_price'),
- 'status'=>1,
- 'user_id'=>$this->auth->id,
- 'order_no'=> time().$this->auth->id,
- ];
- $yutang_id = $yutang_model->insertGetId($yutang_data);
- $this->success('鱼塘创建成功',$yutang_data['order_no']);
- }
- /**
- * 鱼塘列表
- * @return void
- */
- public function yutang_list(){
- $yutang_model = new YutangModel();
- $area_model = new \app\admin\model\shopro\Area();
- $list = $yutang_model->where(array('user_id'=>$this->auth->id,'status'=>2))->paginate();
- foreach ($list as &$v){
- $v['sheng'] = $area_model->where('id',$v['province'])->value('name');
- $v['shi'] = $area_model->where('id',$v['city'])->value('name');
- $v['qu'] = $area_model->where('id',$v['area'])->value('name');
- }
- $this->success('我的鱼塘列表',$list);
- }
- public function yutang_edit(){
- $yutang_model = new YutangModel();
- $data = input();
- $yutang_data = [
- 'image'=>$data['image'],
- 'name'=>$data['name'],
- 'province'=>$data['province'],
- 'city'=>$data['city'],
- 'area'=>$data['area'],
- 'address'=>$data['address'],
- 'latitude'=>$data['lat'],
- 'longitude'=>$data['lon'],
- 'phone'=>$data['phone'],
- 'video'=>$data['video'],
- 'license'=>$data['license'],
- 'status'=>2,
- ];
- $yutang_model->isUpdate('true',['id'=>$data['id']])->save($yutang_data);
- $this->success('鱼塘编辑成功');
- }
- public function yutang_delete(){
- $yutang_model = new YutangModel();
- $data = input();
- $yutang_model->isUpdate('true',['id'=>$data['id']])->save(['status'=>1]);
- $this->success('鱼塘删除成功');
- }
- /**
- *鱼塘详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function yutang_info(){
- $id = input('id');
- $yuntang_model = new YutangModel();
- $area_model = new \app\admin\model\shopro\Area();
- $info = $yuntang_model->where('id',$id)->find();
- $info['sheng'] = $area_model->where('id',$info['province'])->value('name');
- $info['shi'] = $area_model->where('id',$info['city'])->value('name');
- $info['qu'] = $area_model->where('id',$info['area'])->value('name');
- $this->success('我的鱼塘详情',$info);
- }
- /**
- * 发布玩法
- */
- public function method_add(){
- $method_model = new Method();
- $yutang_model = new \app\admin\model\Yutang();
- $Notification_model = new Notification();
- $area_model = new \app\admin\model\shopro\Area();
- $data = input();
- $info = $yutang_model->where('id',$data['yutang_id'])->field('latitude,longitude,name,city')->find();
- $yutang_city=$area_model->where('id',$info['city'])->value('name');
- $method_data = [
- 'type'=>$data['type'],
- 'video'=>$data['video'],
- 'show_images'=>$data['show_images'],
- 'put_time'=>$data['put_time'],
- 'sta_number'=>$data['sta_number'],
- 'biaoyu'=>$data['biaoyu'],
- 'shouprice'=>$data['shouprice'],
- 'eat'=>$data['eat'],
- 'eat_price' => $data['eat_price'],
- 'kongwei'=>$data['kongwei'],
- 'yajin'=>$data['yajin'],
- 'yutang_id'=>$data['yutang_id'],
- 'yutang_name'=>$info['name'],
- 'desc'=>$data['desc'],
- 'yingye'=>$data['yingye'],
- 'moshi'=>$data['moshi'],
- 'tuisong'=>$data['tuisong'],
- 'latitude'=>$info['latitude'],
- 'longitude'=>$info['longitude'],
- 'max'=>$data['max'],
- 'min'=>$data['min'],
- 'tianqi'=> $data['tianqi'],
- 'createtime'=>time(),
- 'huodong_time'=>$data['huodong_time'],
- 'user_id'=>$this->auth->id,
- ];
- // $data['fish']=[['fish_name'=>'草鱼','fish_weight'=>'100','fish_dan'=>'10']];
- // $data['time']=[['title'=>'啊啊啊啊','price'=>'100','type'=>1,'number'=>10,'is_set'=>1]];
- Db::startTrans();
- try {
- if($data['moshi']!=1){
- $method_model->isUpdate('true',['yutang_id'=>$data['yutang_id'],'status'=>1])->save(['status'=>2]);
- }
- $method_id = $method_model->insertGetId($method_data);
- $fish=0;
- foreach ($data['fish'] as &$v){
- $fish_data[]=[
- 'm_id'=>$method_id,
- 'fish_name'=>$v['fish_name'],
- 'fish_weight'=>$v['fish_weight'],
- 'fish_dan'=>$v['fish_dan']
- ];
- $fish +=$v['fish_weight'];
- }
- $method_fish_model = new Fish();
- $method_fish_model->insertAll($fish_data);
- foreach ($data['time'] as &$v){
- $time_data[] = [
- 'm_id'=>$method_id,
- 'title'=>$v['title'],
- 'price'=>$v['price'],
- 'type'=>$v['type'],
- 'seat_num'=>$v['number'],
- 'sale_num'=>$v['number'],
- 'is_set'=>$v['is_set']
- ];
- }
- $method_time_model = new Time();
- $method_time_model->insertAll($time_data);
- $Notification_model->dingyuexiaoxi($data['type'],$data['tuisong'],$info['name'],$fish,$data['time'][0]['price'],$data['moshi'],$yutang_city,$this->auth->id);
- Db::commit();
- $this->success('发布成功');
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error('发布失败');
- }
- }
- /**
- * 发布玩法
- */
- public function method_edit(){
- $method_model = new Method();
- $yutang_model = new \app\admin\model\Yutang();
- $Notification_model = new Notification();
- $area_model = new \app\admin\model\shopro\Area();
- $data = input();
- $info = $yutang_model->where('id',$data['yutang_id'])->field('latitude,longitude,name,city')->find();
- $yutang_city=$area_model->where('id',$info['city'])->value('name');
- $method_data = [
- 'type'=>$data['type'],
- 'show_images'=>$data['show_images'],
- 'put_time'=>$data['put_time'],
- 'sta_number'=>$data['sta_number'],
- 'biaoyu'=>$data['biaoyu'],
- 'shouprice'=>$data['shouprice'],
- 'eat'=>$data['eat'],
- 'eat_price' => $data['eat_price'],
- 'kongwei'=>$data['kongwei'],
- 'yajin'=>$data['yajin'],
- 'yutang_id'=>$data['yutang_id'],
- 'yutang_name'=>$info['name'],
- 'desc'=>$data['desc'],
- 'yingye'=>$data['yingye'],
- 'moshi'=>$data['moshi'],
- 'tuisong'=>$data['tuisong'],
- 'latitude'=>$info['latitude'],
- 'longitude'=>$info['longitude'],
- 'max'=>$data['max'],
- 'min'=>$data['min'],
- 'tianqi'=> $data['tianqi'],
- 'createtime'=>time(),
- 'huodong_time'=>$data['huodong_time'],
- 'user_id'=>$this->auth->id,
- ];
- // $data['fish']=[['fish_name'=>'草鱼','fish_weight'=>'100','fish_dan'=>'10']];
- // $data['time']=[['title'=>'啊啊啊啊','price'=>'100']];
- Db::startTrans();
- try {
- $method_model->isUpdate('true',['id'=>$data['method_id']])->save($method_data);
- foreach ($data['fish'] as &$v){
- $fish_data[]=[
- 'fish_name'=>$v['fish_name'],
- 'fish_weight'=>$v['fish_weight'],
- 'fish_dan'=>$v['fish_dan']
- ];
- $method_fish_model = new Fish();
- $method_fish_model->isUpdate('true',['id'=>$v['id']])->save($fish_data);
- }
- foreach ($data['time'] as &$v){
- $time_data[] = [
- 'title'=>$v['title'],
- 'price'=>$v['price'],
- ];
- $method_time_model = new Time();
- $method_time_model->isUpdate('true',['id'=>$v['id']])->save($time_data);
- }
- Db::commit();
- $this->success('发布成功');
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error('发布失败');
- }
- }
- /**
- * 上次发布信息
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function last_method(){
- $method_model = new Method();
- $fish_model =new Fish();
- $method_time_model = new Time();
- $yutang_model = new \app\admin\model\Yutang();
- $info = $method_model->where('user_id',$this->auth->id)->order('id','DESC')->find();
- if(empty($info)){
- $this->error('还没有发布过鱼塘');
- }
- $info['fish'] = $fish_model->where('m_id',$info['id'])->select();
- $info['time'] = $method_time_model->where('m_id',$info['id'])->select();
- $info['yutang'] = $yutang_model->alias('y')
- ->join('area a','a.id=y.province','left')
- ->join('area r','r.id=y.city','left')
- ->join('area e','e.id=y.area','left')
- ->where('y.id',$info['yutang_id'])->field('y.*,a.name sheng,r.name shi,e.name qu')->find();
- $this->success('上次发布信息',$info);
- }
- /**
- * 发布内容详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function method_info(){
- $method_model = new Method();
- $fish_model = new Fish();
- $time_model = new Time();
- $shoucang_model = new Shoucang();
- $yutang_model = new \app\admin\model\Yutang();
- $pingjia_model = new Pingjia();
- $id = input('id');
- $info = $method_model->where('id',$id)->find();
- $info['fish']=$fish_model->where('m_id',$info['id'])->select();
- $info['time']=$time_model->where('m_id',$info['id'])->select();
- $info['is_have']=0;
- $rebate = rebate($info['type'],$info['moshi']);
- $info['lijianjin']= $rebate['reduction'];;
- $is_have =$shoucang_model->where(['method_id'=>$id,'user_id'=>$this->auth->id])->find();
- if($is_have){
- $info['is_have']=1;
- }
- $info['yutang'] = $yutang_model->alias('y')
- ->join('area a','a.id=y.province','left')
- ->join('area r','r.id=y.city','left')
- ->join('area e','e.id=y.area','left')
- ->where('y.id',$info['yutang_id'])->field('y.*,a.name sheng,r.name shi,e.name qu')->find();
- $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();
- $this->success('发布内容详情',$info);
- }
- /**
- * 鱼塘玩法列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function method_list(){
- $seach = input('seach');
- $type = input('type');
- $moshi = input('moshi');
- $lat = input('latitude');
- $lng = input('longitude');
- $method_model = new Method();
- $fish_model = new Fish();
- $yutang_model = new \app\admin\model\Yutang();
- $shoucang_model = new Shoucang();
- $time_model = new Time();
- $where = [];
- if($type){
- $where['type'] = ['=', $type];
- }
- if($moshi){
- $where['moshi'] = ['=', $moshi];
- }
- if($seach){
- $where['yutang_name'] = ['like', '%'.$seach.'%'];
- }
- $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))))";
- $list = $method_model->alias('s')->order('id','desc')->where('s.status',1)->where($where)->field( ['s.*',
- $distance.'juli'
- ])->order('juli','desc')->paginate();
- $list=$list->items();
- foreach ($list as &$v){
- $rebate = rebate($v['type'],$v['moshi']);
- $v['lijianjin']= $rebate['reduction'];
- $v['is_have']=0;
- $is_have =$shoucang_model->where(['method_id'=>$v['id'],'user_id'=>$this->auth->id])->find();
- if($is_have){
- $v['is_have']=1;
- }
- $v['fist_list'] = $fish_model->where('m_id',$v['id'])->select();
- $v['time_list'] = $time_model->where('m_id',$v['id'])->select();
- $v['price'] = $time_model->where('m_id',$v['id'])->where('type',1)->order('price','asc')->value('price');;
- $v['count'] = 110;
- $v['pingfen']=$yutang_model->where('id',$v['yutang_id'])->value('pingjie');
- }
- $yutang=$yutang_model->alias('s')->field(['s.*', $distance.'juli'])->order('juli','desc')->select();
- foreach ($yutang as $k=>$vv){
- if($yutang[$k]['juli']>10){
- unset($vv);
- }
- }
- $count = count($yutang);
- $data=['list'=>$list,'yutang'=>$yutang,'count'=>$count];
- // dump($data['yutang']);die;
- $this->success('玩法列表',$data);
- }
- /**
- * 鱼塘玩法列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shop_method_list(){
- $method_model = new Method();
- $fish_model = new Fish();
- $yutang_model = new \app\admin\model\Yutang();
- $area_model = new \app\admin\model\shopro\Area();
- $list = $method_model->order('id','desc')->where('user_id',$this->auth->id)->paginate();
- $list=$list->items();
- foreach ($list as &$v){
- $v['fist_list'] = $fish_model->where('m_id',$v['id'])->select();
- $yutang_info = $yutang_model->where('id',$v['yutang_id'])->find();
- $sheng = $area_model->where('id',$yutang_info['province'])->value('name');
- $shi = $area_model->where('id',$yutang_info['city'])->value('name');
- $qu = $area_model->where('id',$yutang_info['area'])->value('name');
- $v['address'] = $sheng.$shi.$qu.$yutang_info['address'];
- }
- $data=['list'=>$list];
- $this->success('玩法列表',$data);
- }
- /**
- * 搜索历史
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException\
- */
- public function arealog_list(){
- $arealog_model = new Arealog();
- $list = $arealog_model->where('user_id',$this->auth->id)->select();
- $this->success('搜索历史',$list);
- }
- /**
- * 添加搜素历史
- * @return void
- */
- public function address_log(){
- $arealog_model = new Arealog();
- $data = input();
- $log_data = ['city'=>$data['city'],'user_id'=>$this->auth->id];
- $arealog_model->insert($log_data);
- }
- /**
- * 热门城市
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function area_hot(){
- $areahot_model = new Areahot();
- $list = $areahot_model->order('id','desc')->select();
- $this->success('热门城市',$list);
- }
- public function shoucang(){
- $method_id = input('method_id');
- $shoucang_model = new Shoucang();
- $is_have =$shoucang_model->where(['method_id'=>$method_id,'user_id'=>$this->auth->id])->find();
- if($is_have){
- $shoucang_model->where(['method_id'=>$method_id,'user_id'=>$this->auth->id])->delete();
- $this->success('收藏取消');
- }
- else{
- $shoucang_model->insert(['method_id'=>$method_id,'user_id'=>$this->auth->id]);
- $this->success('收藏成功');
- }
- }
- }
|