Auction.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\admin\model\auction\AuctionGu;
  6. use app\admin\model\auction\AuctionProduct as model;
  7. use app\admin\model\User;
  8. use crmeb\services\{ExpressService,
  9. JsonService,
  10. JsonService as Json,
  11. MiniProgramService,
  12. upload\Upload,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use app\admin\model\system\{
  18. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  19. };
  20. use think\facade\Route as Url;
  21. use think\facade\Validate;
  22. /**
  23. * 竞拍管理
  24. * Class StoreOrder
  25. * @package app\admin\controller\store
  26. */
  27. class Auction extends AuthController
  28. {
  29. public function index()
  30. {
  31. $list = AuctionGu::select();
  32. $this->assign('list', $list);
  33. return $this->fetch();
  34. }
  35. public function list()
  36. {
  37. $where = Util::getMore([
  38. ['status', ''],
  39. ['page', 1],
  40. ['limit', 20],
  41. ['auction'],
  42. ['auction_id']
  43. ]);
  44. $data = \app\admin\model\auction\Auction::list($where);
  45. return Json::successlayui($data);
  46. }
  47. /**
  48. * 显示创建资源表单页.
  49. *
  50. * @return \think\Response
  51. */
  52. public function create($id = 0)
  53. {
  54. $f = [];
  55. $f[] = Form::input('nickname', '场次名称')->col(12);
  56. $f[] = Form::input('anticipate', '预约价格')->col(12);
  57. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  58. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  59. $f[] = Form::select('auction_gu_id', '绑定场馆')->setOptions(function () {
  60. $model = new AuctionGu();
  61. $list = $model->select();
  62. $menus = [];
  63. foreach ($list as $menu) {
  64. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  65. }
  66. return $menus;
  67. })->filterable(1)->col(12);
  68. $f[] = Form::dateTimes('add_time', '预约开始时间');
  69. $f[] = Form::dateTimes('end_time', '预约结束时间');
  70. $f[] = Form::dateTimes('radd_time', '入场时间');
  71. $f[] = Form::dateTimes('rend_time', '结束时间');
  72. $f[] = Form::input('sort', '排序', '0');
  73. $f[] = Form::input('sort', '排序', '0');
  74. $f[] = Form::checkbox('site', '开场日期', [1,3,5])->options([
  75. ['value' => 1, 'label' => '周一'],
  76. ['value' => 2, 'label' => '周二'],
  77. ['value' => 3, 'label' => '周三'],
  78. ['value' => 4, 'label' => '周四'],
  79. ['value' => 5, 'label' => '周五'],
  80. ['value' => 6, 'label' => '周六'],
  81. ['value' => 7, 'label' => '周七'],
  82. ]);
  83. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  84. $this->assign(compact('form'));
  85. return $this->fetch('public/form-builder');
  86. // $data = [];
  87. // $model = new AuctionGu();
  88. // $auction = $model->select();
  89. // if ($id > 0) $data = \app\admin\model\auction\Auction::find($id)->toArray();
  90. //
  91. // $this->assign(['id' => $id, 'dataList' => $data, 'auction' => $auction]);
  92. // return $this->fetch();
  93. }
  94. public function save()
  95. {
  96. $mode = new \app\admin\model\auction\Auction();
  97. $data = Util::postMore([
  98. 'nickname',
  99. 'image',
  100. 'status',
  101. 'sort',
  102. 'add_time',
  103. 'end_time',
  104. 'radd_time',
  105. 'rend_time',
  106. 'info',
  107. 'anticipate',
  108. 'auction_gu_id',
  109. 'site'
  110. ]);
  111. $validate = Validate::rule('nickname', 'require')->rule([
  112. 'nickname' => 'require',
  113. 'image' => 'require',
  114. 'status' => 'require',
  115. 'anticipate' => 'require',
  116. 'add_time' => 'require',
  117. 'end_time' => 'require',
  118. 'radd_time' => 'require',
  119. 'rend_time' => 'require',
  120. 'auction_gu_id' => 'require',
  121. 'site' => 'require'
  122. ]);
  123. $validate->message([
  124. 'nickname.require' => '名称不能为空',
  125. 'image.require' => '图片不能为空',
  126. 'status.require' => '状态不能为空',
  127. 'anticipate.require' => '请填写预约价格',
  128. 'add_time.require' => '请选择预约开始时间价格',
  129. 'end_time.require' => '请选择预约结束时间价格',
  130. 'radd_time.require' => '请选择进场时间',
  131. 'rend_time.require' => '请选择结束时间',
  132. 'auction_gu_id.require' => '请选择绑定场馆',
  133. 'site.require' => '请选择开场日期',
  134. ]);
  135. $data['site'] = implode($data['site'], ',');
  136. if ($data['site'] == '1,3,5' or $data['site'] == '2,4,6') {
  137. if (!$validate->check($data)) {
  138. return Json::fail($validate->getError());
  139. }
  140. $res = $mode->save($data);
  141. if ($res){
  142. return Json::success('添加成功!');
  143. }else{
  144. return Json::fail('添加失败');
  145. }
  146. }else{
  147. return Json::fail('请选择正确的日期,1,3,5 或者 2,4,6');
  148. }
  149. }
  150. /**
  151. * 删除
  152. * @param $id
  153. * @return void
  154. * @throws \Exception
  155. */
  156. public function delete($id)
  157. {
  158. if (!$id) Json::fail('删除失败');
  159. $model = new \app\admin\model\auction\Auction();
  160. $res = $model->where('id', $id)->delete();
  161. if ($res){
  162. return Json::success('删除成功!');
  163. }else{
  164. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  165. }
  166. }
  167. public function set_status($id, $status)
  168. {
  169. if (empty($id))return Json::fail('修改失败');
  170. $res = \app\admin\model\auction\Auction::update(['status' => $status, 'id' => $id]);
  171. if ($res){
  172. return Json::success('修改成功!');
  173. }else{
  174. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  175. }
  176. }
  177. public function edit($id)
  178. {
  179. if (!$id) Json::fail('数据不存在');
  180. $data = \app\admin\model\auction\Auction::find($id);
  181. $f = [];
  182. $f[] = Form::input('nickname', '场次名称', $data->getData('nickname'))->col(12);
  183. $f[] = Form::input('anticipate', '预约价格', $data->getData('anticipate'))->col(12);
  184. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)',Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  185. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  186. $f[] = Form::select('auction_gu_id', '绑定场馆', (string)$data->getData('auction_gu_id'))->setOptions(function () {
  187. $model = new AuctionGu();
  188. $list = $model->select();
  189. $menus = [];
  190. foreach ($list as $menu) {
  191. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  192. }
  193. return $menus;
  194. })->filterable(1)->col(12);
  195. $f[] = Form::dateTimes('add_time', '预约开始时间', $data->getData('add_time'));
  196. $f[] = Form::dateTimes('end_time', '预约结束时间', $data->getData('end_time'));
  197. $f[] = Form::dateTimes('radd_time', '入场时间', $data->getData('radd_time'));
  198. $f[] = Form::dateTimes('rend_time', '结束时间', $data->getData('rend_time'));
  199. $f[] = Form::input('sort', '排序', '0', $data->getData('sort'));
  200. $f[] = Form::textarea('info', '介绍', $data->getData('info'))->col(12);
  201. $f[] = Form::checkbox('site', '开场日期', explode(',', $data->getData('site')))->options([
  202. ['value' => 1, 'label' => '周一'],
  203. ['value' => 2, 'label' => '周二'],
  204. ['value' => 3, 'label' => '周三'],
  205. ['value' => 4, 'label' => '周四'],
  206. ['value' => 5, 'label' => '周五'],
  207. ['value' => 6, 'label' => '周六'],
  208. ['value' => 7, 'label' => '周七'],
  209. ]);
  210. $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
  211. $this->assign(compact('form'));
  212. return $this->fetch('public/form-builder');
  213. }
  214. public function get_auction($id)
  215. {
  216. if (!$id) Json::fail('数据不存在');
  217. $model = new \app\admin\model\auction\Auction();
  218. $info = $model->find($id);
  219. $data['productInfo'] = $info;
  220. return JsonService::successful($data);
  221. }
  222. public function update()
  223. {
  224. $data = Util::postMore([
  225. 'id',
  226. 'nickname',
  227. 'image',
  228. 'status',
  229. 'sort',
  230. 'add_time',
  231. 'end_time',
  232. 'radd_time',
  233. 'rend_time',
  234. 'info',
  235. 'anticipate',
  236. 'auction_gu_id',
  237. 'site'
  238. ]);
  239. $validate = Validate::rule('nickname', 'require')->rule([
  240. 'nickname' => 'require',
  241. 'image' => 'require',
  242. 'status' => 'require',
  243. 'anticipate' => 'require',
  244. 'add_time' => 'require',
  245. 'end_time' => 'require',
  246. 'radd_time' => 'require',
  247. 'rend_time' => 'require',
  248. 'auction_gu_id' => 'require',
  249. 'site' => 'require'
  250. ]);
  251. $validate->message([
  252. 'nickname.require' => '名称不能为空',
  253. 'image.require' => '图片不能为空',
  254. 'status.require' => '状态不能为空',
  255. 'anticipate.require' => '请填写预约价格',
  256. 'add_time.require' => '请选择预约开始时间价格',
  257. 'end_time.require' => '请选择预约结束时间价格',
  258. 'radd_time.require' => '请选择进场时间',
  259. 'rend_time.require' => '请选择结束时间',
  260. 'auction_gu_id.require' => '请选择绑定场馆',
  261. 'site.require' => '请选择开场日期',
  262. ]);
  263. $data['site'] = implode($data['site'], ',');
  264. if ($data['site'] == '1,3,5' or $data['site'] == '2,4,6') {
  265. if (!$validate->check($data)) {
  266. return Json::fail($validate->getError());
  267. }
  268. $res = \app\admin\model\auction\Auction::update($data);
  269. if ($res){
  270. return Json::success('修改成功!');
  271. }else{
  272. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  273. }
  274. }else{
  275. return Json::fail('请选择正确的日期,1,3,5 或者 2,4,6');
  276. }
  277. }
  278. /**
  279. * 商品列表
  280. * @param $id
  281. * @return void
  282. */
  283. public function product($id)
  284. {
  285. $list = \app\admin\model\auction\Auction::select();
  286. $this->assign([
  287. 'auction'=> $list,
  288. 'id' => $id
  289. ]);
  290. return $this->fetch('');
  291. }
  292. /**
  293. * 商品
  294. * @param $id
  295. * @return void
  296. */
  297. public function product_list($id)
  298. {
  299. $where = Util::getMore([
  300. ['is_show', ''],
  301. ['page', 1],
  302. ['limit', 20],
  303. ['store_name', ''],
  304. ['auction_id'],
  305. ['is_show']
  306. ]);
  307. $data = model::list($where, $id);
  308. foreach ($data['data'] as $key => $val){
  309. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  310. }
  311. return Json::successlayui($data);
  312. }
  313. /**
  314. * 商品添加
  315. * @param $id
  316. * @return string
  317. * @throws \think\db\exception\DataNotFoundException
  318. * @throws \think\db\exception\DbException
  319. * @throws \think\db\exception\ModelNotFoundException
  320. */
  321. public function product_edit($id, $auction_id)
  322. {
  323. if (!$id) Json::fail('数据不存在');
  324. $this->assign(['id' => $id, 'auction_id' => $auction_id]);
  325. return $this->fetch();
  326. }
  327. /**
  328. * 显示创建资源表单页.
  329. *
  330. * @return \think\Response
  331. */
  332. public function product_create($id = 0)
  333. {
  334. $this->assign(['id' => $id]);
  335. return $this->fetch();
  336. }
  337. public function product_save($id)
  338. {
  339. $data = Util::postMore([
  340. 'name',
  341. 'is_show',
  342. 'image',
  343. 'price',
  344. 'deduct',
  345. 'rise',
  346. 'info',
  347. 'sort',
  348. 'auction_id',
  349. 'hanging_price',
  350. 'slider_image',
  351. 'description'
  352. ]);
  353. $data['slider_image'] = json_encode($data['slider_image']);
  354. $data['description'] = htmlspecialchars($data['description']);
  355. $auction = \app\admin\model\auction\Auction::where('id' ,$data['auction_id'])->find();
  356. $auction_gu = \app\admin\model\auction\AuctionGu::where('id' ,$auction['auction_gu_id'])->find();
  357. $data['uid'] = $auction_gu['uid'];
  358. $model = new model();
  359. $res = $model->save($data);
  360. if ($res){
  361. return Json::success('添加成功!');
  362. }else{
  363. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  364. }
  365. }
  366. /**
  367. * 商品修改
  368. * @param $id
  369. * @return void
  370. */
  371. public function product_update($id)
  372. {
  373. $data = Util::postMore([
  374. 'id',
  375. 'name',
  376. 'image',
  377. 'price',
  378. 'deduct',
  379. 'rise',
  380. 'info',
  381. 'sort',
  382. 'auction_id',
  383. 'hanging_price',
  384. 'slider_image',
  385. 'description'
  386. ]);
  387. $data['slider_image'] = json_encode($data['slider_image']);
  388. $data['description'] = htmlspecialchars($data['description']);
  389. $res = model::update($data);
  390. if ($res){
  391. return Json::success('修改成功!');
  392. }else{
  393. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  394. }
  395. }
  396. }