Index.php 13 KB

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