Auction.php 17 KB

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