Index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\ListCallTaskResponseBody\data;
  4. use app\common\controller\Api;
  5. use function GuzzleHttp\Psr7\uri_for;
  6. use think\Db;
  7. /**
  8. * 首页接口
  9. */
  10. class Index extends Api
  11. {
  12. protected $noNeedLogin = [];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. //轮播图
  23. public function banner()
  24. {
  25. $list = Db::name('banner')->field('id, title, image, url')->order('weigh', 'desc')->select();
  26. $list = list_domain_image($list, ['image']);
  27. $this->success('轮播图', $list);
  28. }
  29. //接线员
  30. public function operator()
  31. {
  32. $province = input('province', '', 'trim'); //省
  33. $city = input('city', '', 'trim'); //市
  34. $area = input('area', '', 'trim'); //区
  35. $keyword = input('keyword', '', 'trim'); //关键字
  36. $where['status'] = 1;
  37. if ($province) {
  38. $where['province'] = $province;
  39. }
  40. if ($city) {
  41. $where['city'] = $city;
  42. }
  43. if ($area) {
  44. $where['area'] = $area;
  45. }
  46. if ($keyword !== '') {
  47. $where['name|mobile'] = ['like', '%'.$keyword.'%'];
  48. }
  49. $list = Db::name('operator')->field('id, name, mobile, avatar, province, city, area')->where($where)
  50. ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select();
  51. $list = list_domain_image($list, ['avatar']);
  52. $this->success('接线员', $list);
  53. }
  54. //价格走势
  55. public function pricetrend()
  56. {
  57. $info = Db::name('platform_info')->field('title, content')->where(['type' => 2])->find();
  58. $this->success('价格走势', $info);
  59. }
  60. //精选推荐列表
  61. public function mark()
  62. {
  63. $province = input('province', '', 'trim'); //省
  64. $keyword = input('keyword', '', 'trim'); //关键字
  65. $where['endtime'] = ['gt', time()];
  66. $where['status'] = 1;
  67. if ($province) {
  68. $where['province'] = $province;
  69. }
  70. if ($keyword !== '') {
  71. $where['name|pig_type|pig_breed_type|province|city|area|address'] = ['like', '%'.$keyword.'%'];
  72. }
  73. $list = Db::name('mark')->field('id, name, image, pig_type, heft, price, province, city, area')
  74. ->where($where)->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select();
  75. $list = list_domain_image($list, ['image']);
  76. $mark_bid = Db::name('mark_bid');
  77. foreach ($list as &$v) {
  78. $v['bid_count'] = $mark_bid->where(['mark_id' => $v['id']])->count('id');
  79. }
  80. $this->success('精选推荐列表', $list);
  81. }
  82. //招标详情
  83. public function markinfo()
  84. {
  85. $id = input('id', 0, 'intval');
  86. if (!$id) {
  87. $this->error('参数缺失');
  88. }
  89. $info = Db::name('mark')->find($id);
  90. if (!$info) {
  91. $this->error('数据不存在');
  92. }
  93. $info = info_domain_image($info, ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  94. $info['createtime'] = date('Y-m-d H:i:s', $info['createtime']);
  95. $info['remaintime'] = $info['endtime'] - time() > 0 ? $info['endtime'] - time() : 0; //投标剩余时间
  96. $info['again_bid'] = process_time($info['again_bid']); //再次投标间隔时间处理
  97. $this->success('招标详情', $info);
  98. }
  99. //投标
  100. public function markbid()
  101. {
  102. $id = input('id', 0, 'intval'); //招标id
  103. $price = input('price', '', 'trim'); //报价/斤
  104. $number = input('number', 0, 'intval'); //购买数量
  105. $pig_pulling_time = input('pig_pulling_time', '', 'strtotime'); //预计拉猪时间
  106. if (!$id) {
  107. $this->error('参数缺失');
  108. }
  109. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $price) || $price <= 0) {
  110. $this->error('请输入正确报价');
  111. }
  112. if ($number <= 0) {
  113. $this->error('请输入购买数量');
  114. }
  115. if ($pig_pulling_time < time()) {
  116. $this->error('请选择正确拉猪时间');
  117. }
  118. if ($this->auth->is_auth != 2) {
  119. $this->error('请先完成实名认证');
  120. }
  121. $info = Db::name('mark')->find($id);
  122. if (!$info) {
  123. $this->error('招标信息不存在');
  124. }
  125. if ($info['status'] != 1) {
  126. $this->error('招标已经结束');
  127. }
  128. if ($info['endtime'] < time()) {
  129. $this->error('招标已经结束');
  130. }
  131. //查询是否投过标
  132. $bid_info = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->order('createtime', 'desc')->find();
  133. if ($bid_info) {
  134. if ($price <= $bid_info['price']) {
  135. $this->error('价格不能低于上次报价');
  136. }
  137. if ($info['again_bid'] > 0) {
  138. if (time() - $bid_info['updatetime'] < $info['again_bid']) {
  139. $this->error('您刚投标过,请稍等一会');
  140. }
  141. }
  142. }
  143. $data['user_id'] = $this->auth->id;
  144. $data['mark_id'] = $id;
  145. $data['order_sn'] = date('YmdHis', time()) . rand(10000000, 99999999);
  146. $data['price'] = $price;
  147. $data['number'] = $number;
  148. $data['pig_pulling_time'] = $pig_pulling_time;
  149. $data['province'] = $info['province'];
  150. $data['city'] = $info['city'];
  151. $data['area'] = $info['area'];
  152. $data['createtime'] = time();
  153. $data['updatetime'] = time();
  154. //开启事务
  155. Db::startTrans();
  156. //添加投标记录
  157. $rs = Db::name('mark_bid_record')->insertGetId($data);
  158. if (!$rs) {
  159. Db::rollback();
  160. $this->error('投标失败');
  161. }
  162. if ($bid_info) {
  163. //已经投标过, 更新实时投标数据
  164. $_data['order_sn'] = $data['order_sn'];
  165. $_data['price'] = $price;
  166. $_data['number'] = $number;
  167. $_data['pig_pulling_time'] = $pig_pulling_time;
  168. $_data['updatetime'] = time();
  169. $result = Db::name('mark_bid')->where(['id' => $bid_info['id'], 'user_id' => $this->auth->id, 'price' => $bid_info['price']])->setField($_data);
  170. } else {
  171. $result = Db::name('mark_bid')->insertGetId($data);
  172. }
  173. if (!$result) {
  174. Db::rollback();
  175. $this->error('投标失败');
  176. }
  177. $rt = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $id])->count('id');
  178. if ($rt != 1) {
  179. Db::rollback();
  180. $this->error('投标失败');
  181. }
  182. Db::commit();
  183. $this->success('投标成功');
  184. }
  185. //猪只类型
  186. public function pigbreedtype()
  187. {
  188. $list = Db::name('pig_breed_type')->field('id, name')->order('weigh', 'desc')->select();
  189. $this->success('猪只类型', $list);
  190. }
  191. //立即投标筛选列表
  192. public function marklist()
  193. {
  194. $pig_breed_type = input('pig_breed_type', '', 'trim'); //猪只类型
  195. $province = input('province', '', 'trim'); //省
  196. $city = input('city', '', 'trim'); //市
  197. $area = input('area', '', 'trim'); //区
  198. if (!$pig_breed_type) {
  199. $this->error('请选择猪只类型');
  200. }
  201. if (!$province && !$city && !$area) {
  202. $this->error('请选择地区');
  203. }
  204. $where['pig_breed_type'] = $pig_breed_type;
  205. $where['endtime'] = ['gt', time()];
  206. $where['status'] = 1;
  207. if ($province) {
  208. $where['province'] = $province;
  209. }
  210. if ($city) {
  211. $where['city'] = $city;
  212. }
  213. if ($area) {
  214. $where['area'] = $area;
  215. }
  216. $list = Db::name('mark')->field('id, area, pig_type, heft, number, price')
  217. ->where($where)->order('createtime', 'desc')->select();
  218. $this->success('立即投标筛选列表', $list);
  219. }
  220. //立即投标页面备注
  221. public function bidremark()
  222. {
  223. $info = Db::name('platform_info')->field('content')->where(['type' => 3])->find();
  224. $this->success('立即投标页面备注', $info);
  225. }
  226. //投标管理列表
  227. public function bidlist()
  228. {
  229. $type = input('type', 1, 'intval'); //类型 1全部 2竞标中 3=中标 4=未中标
  230. $time = input('time', '', 'strtotime'); //时间
  231. $province = input('province', '', 'trim'); //省
  232. $city = input('city', '', 'trim'); //市
  233. $area = input('area', '', 'trim'); //区
  234. $where['user_id'] = $this->auth->id;
  235. if ($type > 1) {
  236. $where['status'] = $type - 2; //状态:0=竞标中,1=中标,2=未中标
  237. }
  238. if (!$time) {
  239. $time = strtotime(date('Y-m-d 0:0:0', time()));
  240. }
  241. $where['createtime'] = ['between', [$time, $time + 86400]];
  242. if ($province) {
  243. $where['province'] = $province;
  244. }
  245. if ($city) {
  246. $where['city'] = $city;
  247. }
  248. if ($area) {
  249. $where['area'] = $area;
  250. }
  251. $list = Db::name('mark_bid')->where($where)
  252. ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
  253. $mark = Db::name('mark');
  254. $mark_bid = Db::name('mark_bid');
  255. foreach ($list as &$v) {
  256. $v['pig_pulling_time'] = date('Y-m-d H:i:s', $v['pig_pulling_time']);
  257. //排名
  258. $v['ranking'] = $mark_bid->where(['mark_id' => $v['mark_id'], 'price' => ['egt', $v['price']]])->count('id');
  259. $v['mark'] = $mark->find($v['mark_id']);
  260. $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  261. $v['mark']['endtime'] = date('Y-m-d H:i:s', $v['mark']['endtime']);
  262. }
  263. $this->success('投标管理列表', $list);
  264. }
  265. //投标记录
  266. public function bidrecord()
  267. {
  268. $id = input('id', 0, 'intval'); //招标id
  269. if (!$id) {
  270. $this->error('参数缺失');
  271. }
  272. $info = Db::name('mark')->find($id);
  273. if (!$info) {
  274. $this->error('招标信息不存在');
  275. }
  276. $list = Db::name('mark_bid')->field('id, price, number, createtime')
  277. ->where(['user_id' => $this->auth->id, 'mark_id' => $id])
  278. ->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
  279. foreach ($list as &$v) {
  280. $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
  281. }
  282. $this->success('投标记录', $list);
  283. }
  284. //投标详情
  285. public function bidinfo()
  286. {
  287. $id = input('id', 0, 'intval'); //投标记录id
  288. if (!$id) {
  289. $this->error('参数缺失');
  290. }
  291. $where['user_id'] = $this->auth->id;
  292. $where['id'] = $id;
  293. $info = Db::name('mark_bid')->where($where)->find();
  294. if (!$info) {
  295. $this->error('记录不存在');
  296. }
  297. $mark = Db::name('mark');
  298. $info['pig_pulling_time'] = date('Y-m-d H:i:s', $info['pig_pulling_time']);
  299. $info['mark'] = $mark->find($info['mark_id']);
  300. $info['mark'] = info_domain_image($info['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
  301. $info['mark']['endtime'] = date('Y-m-d H:i:s', $info['mark']['endtime']);
  302. $this->success('投标详情', $info);
  303. }
  304. }