123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
- use app\common\controller\Api;
- use function GuzzleHttp\Psr7\uri_for;
- use think\Db;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- //轮播图
- public function banner()
- {
- $list = Db::name('banner')->field('id, title, image, url')->order('weigh', 'desc')->select();
- $list = list_domain_image($list, ['image']);
- $this->success('轮播图', $list);
- }
-
- //接线员
- public function operator()
- {
- $province = input('province', '', 'trim'); //省
- $city = input('city', '', 'trim'); //市
- $area = input('area', '', 'trim'); //区
- $keyword = input('keyword', '', 'trim'); //关键字
- $where['status'] = 1;
- if ($province) {
- $where['province'] = $province;
- }
- if ($city) {
- $where['city'] = $city;
- }
- if ($area) {
- $where['area'] = $area;
- }
- if ($keyword !== '') {
- $where['name|mobile'] = ['like', '%'.$keyword.'%'];
- }
- $list = Db::name('operator')->field('id, name, mobile, avatar, province, city, area')->where($where)
- ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select();
- $list = list_domain_image($list, ['avatar']);
- $this->success('接线员', $list);
- }
- //价格走势
- public function pricetrend()
- {
- $info = Db::name('platform_info')->field('title, content')->where(['type' => 2])->find();
- $this->success('价格走势', $info);
- }
- //精选推荐列表
- public function mark()
- {
- $province = input('province', '', 'trim'); //省
- $keyword = input('keyword', '', 'trim'); //关键字
- $where['endtime'] = ['gt', time()];
- $where['status'] = 1;
- if ($province) {
- $where['province'] = $province;
- }
- if ($keyword !== '') {
- $where['name|pig_type|pig_breed_type|province|city|area|address'] = ['like', '%'.$keyword.'%'];
- }
- $list = Db::name('mark')->field('id, name, image, pig_type, heft, price, province, city, area')
- ->where($where)->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select();
- $list = list_domain_image($list, ['image']);
- $mark_bid = Db::name('mark_bid');
- foreach ($list as &$v) {
- $v['bid_count'] = $mark_bid->where(['mark_id' => $v['id']])->count('id');
- }
- $this->success('精选推荐列表', $list);
- }
- //招标详情
- public function markinfo()
- {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('mark')->find($id);
- if (!$info) {
- $this->error('数据不存在');
- }
- $info = info_domain_image($info, ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
- $info['createtime'] = date('Y-m-d H:i:s', $info['createtime']);
- $info['remaintime'] = $info['endtime'] - time() > 0 ? $info['endtime'] - time() : 0; //投标剩余时间
- $info['again_bid'] = process_time($info['again_bid']); //再次投标间隔时间处理
- $this->success('招标详情', $info);
- }
- //投标
- public function markbid()
- {
- $id = input('id', 0, 'intval'); //招标id
- $price = input('price', '', 'trim'); //报价/斤
- $number = input('number', 0, 'intval'); //购买数量
- $pig_pulling_time = input('pig_pulling_time', '', 'strtotime'); //预计拉猪时间
- if (!$id) {
- $this->error('参数缺失');
- }
- if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price <= 0) {
- $this->error('请输入正确报价');
- }
- if ($number <= 0) {
- $this->error('请输入购买数量');
- }
- if ($pig_pulling_time < time()) {
- $this->error('请选择正确拉猪时间');
- }
- if ($this->auth->is_auth != 2) {
- $this->error('请先完成实名认证');
- }
- $info = Db::name('mark')->find($id);
- if (!$info) {
- $this->error('招标信息不存在');
- }
- if ($info['status'] != 1) {
- $this->error('招标已经结束');
- }
- if ($info['endtime'] < time()) {
- $this->error('招标已经结束');
- }
- //查询是否投过标
- $bid_info = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->order('createtime', 'desc')->find();
- if ($bid_info) {
- if ($price <= $bid_info['price']) {
- $this->error('价格不能低于上次报价');
- }
- if ($info['again_bid'] > 0) {
- if (time() - $bid_info['updatetime'] < $info['again_bid']) {
- $this->error('您刚投标过,请稍等一会');
- }
- }
- }
- $data['user_id'] = $this->auth->id;
- $data['mark_id'] = $id;
- $data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
- $data['price'] = $price;
- $data['number'] = $number;
- $data['pig_pulling_time'] = $pig_pulling_time;
- $data['province'] = $info['province'];
- $data['city'] = $info['city'];
- $data['area'] = $info['area'];
- $data['createtime'] = time();
- $data['updatetime'] = time();
- //开启事务
- Db::startTrans();
- //添加投标记录
- $rs = Db::name('mark_bid_record')->insertGetId($data);
- if (!$rs) {
- Db::rollback();
- $this->error('投标失败');
- }
- if ($bid_info) {
- //已经投标过, 更新实时投标数据
- $_data['order_sn'] = $data['order_sn'];
- $_data['price'] = $price;
- $_data['number'] = $number;
- $_data['pig_pulling_time'] = $pig_pulling_time;
- $_data['updatetime'] = time();
- $result = Db::name('mark_bid')->where(['id' => $bid_info['id'], 'user_id' => $this->auth->id, 'price' => $bid_info['price']])->setField($_data);
- } else {
- $result = Db::name('mark_bid')->insertGetId($data);
- }
- if (!$result) {
- Db::rollback();
- $this->error('投标失败');
- }
- $rt = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->count('id');
- if ($rt != 1) {
- Db::rollback();
- $this->error('投标失败');
- }
- Db::commit();
- $this->success('投标成功');
- }
- //猪只类型
- public function pigbreedtype()
- {
- $list = Db::name('pig_breed_type')->field('id, name')->order('weigh', 'desc')->select();
- $this->success('猪只类型', $list);
- }
-
- //立即投标筛选列表
- public function marklist()
- {
- $pig_breed_type = input('pig_breed_type', '', 'trim'); //猪只类型
- $province = input('province', '', 'trim'); //省
- $city = input('city', '', 'trim'); //市
- $area = input('area', '', 'trim'); //区
- if (!$pig_breed_type) {
- $this->error('请选择猪只类型');
- }
- if (!$province && !$city && !$area) {
- $this->error('请选择地区');
- }
- $where['pig_breed_type'] = $pig_breed_type;
- $where['endtime'] = ['gt', time()];
- $where['status'] = 1;
- if ($province) {
- $where['province'] = $province;
- }
- if ($city) {
- $where['city'] = $city;
- }
- if ($area) {
- $where['area'] = $area;
- }
- $list = Db::name('mark')->field('id, area, pig_type, heft, number, price')
- ->where($where)->order('createtime', 'desc')->select();
- $this->success('立即投标筛选列表', $list);
- }
- //立即投标页面备注
- public function bidremark()
- {
- $info = Db::name('platform_info')->field('content')->where(['type' => 3])->find();
- $this->success('立即投标页面备注', $info);
- }
- //投标管理列表
- public function bidlist()
- {
- $type = input('type', 1, 'intval'); //类型 1全部 2竞标中 3=中标 4=未中标
- $time = input('time', '', 'strtotime'); //时间
- $province = input('province', '', 'trim'); //省
- $city = input('city', '', 'trim'); //市
- $area = input('area', '', 'trim'); //区
- $where['user_id'] = $this->auth->id;
- if ($type > 1) {
- $where['status'] = $type - 2; //状态:0=竞标中,1=中标,2=未中标
- }
- if (!$time) {
- $time = strtotime(date('Y-m-d 0:0:0', time()));
- }
- $where['createtime'] = ['between', [$time, $time + 86400]];
- if ($province) {
- $where['province'] = $province;
- }
- if ($city) {
- $where['city'] = $city;
- }
- if ($area) {
- $where['area'] = $area;
- }
- $list = Db::name('mark_bid')->where($where)
- ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
- $mark = Db::name('mark');
- $mark_bid = Db::name('mark_bid');
- foreach ($list as &$v) {
- $v['pig_pulling_time'] = date('Y-m-d H:i:s', $v['pig_pulling_time']);
- //排名
- $v['ranking'] = $mark_bid->where(['mark_id' => $v['mark_id'], 'price' => ['egt', $v['price']]])->count('id');
- $v['mark'] = $mark->find($v['mark_id']);
- $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
- $v['mark']['endtime'] = date('Y-m-d H:i:s', $v['mark']['endtime']);
- }
- $this->success('投标管理列表', $list);
- }
- //投标记录
- public function bidrecord()
- {
- $id = input('id', 0, 'intval'); //招标id
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('mark')->find($id);
- if (!$info) {
- $this->error('招标信息不存在');
- }
- $list = Db::name('mark_bid')->field('id, price, number, createtime')
- ->where(['user_id' => $this->auth->id, 'mark_id' => $id])
- ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
- foreach ($list as &$v) {
- $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
- }
- $this->success('投标记录', $list);
- }
-
- //投标详情
- public function bidinfo()
- {
- $id = input('id', 0, 'intval'); //投标记录id
- if (!$id) {
- $this->error('参数缺失');
- }
- $where['user_id'] = $this->auth->id;
- $where['id'] = $id;
- $info = Db::name('mark_bid')->where($where)->find();
- if (!$info) {
- $this->error('记录不存在');
- }
- $mark = Db::name('mark');
- $info['pig_pulling_time'] = date('Y-m-d H:i:s', $info['pig_pulling_time']);
- $info['mark'] = $mark->find($info['mark_id']);
- $info['mark'] = info_domain_image($info['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
- $info['mark']['endtime'] = date('Y-m-d H:i:s', $info['mark']['endtime']);
- $this->success('投标详情', $info);
- }
- }
|