Auction.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\User;
  5. use app\models\auction\AuctionSection;
  6. use crmeb\services\{ExpressService,
  7. JsonService,
  8. JsonService as Json,
  9. MiniProgramService,
  10. upload\Upload,
  11. WechatService,
  12. FormBuilder as Form,
  13. CacheService,
  14. UtilService as Util};
  15. use app\admin\model\system\{
  16. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  17. };
  18. use think\facade\Route as Url;
  19. use think\facade\Validate;
  20. /**
  21. * 竞拍管理
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class Auction extends AuthController
  26. {
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. public function list()
  32. {
  33. $where = Util::getMore([
  34. ['status', ''],
  35. ['page', 1],
  36. ['limit', 20],
  37. ['auction']
  38. ]);
  39. $data = \app\admin\model\auction\Auction::list($where);
  40. return Json::successlayui($data);
  41. }
  42. /**
  43. * 显示创建资源表单页.
  44. *
  45. * @return \think\Response
  46. */
  47. public function create($id = 0)
  48. {
  49. $f = [];
  50. $f[] = Form::input('name', '场次名称')->col(12);
  51. $f[] = Form::input('advert', '预约广告值')->col(12);
  52. $f[] = Form::input('lowest', '额度门槛');
  53. $f[] = Form::input('minimum', '广告值门槛');
  54. $f[] = Form::input('dispatch', '派单百分比%', 100)->col(12);
  55. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  56. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  57. $f[] = Form::dateTimes('radd_time', '入场时间');
  58. $f[] = Form::dateTimes('rend_time', '结束时间');
  59. $f[] = Form::input('sort', '排序',0);
  60. $f[] = Form::textarea('info', '介绍');
  61. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  62. $this->assign(compact('form'));
  63. return $this->fetch('public/form-builder');
  64. }
  65. /**
  66. * 修改页面
  67. * @param $id
  68. * @return string
  69. * @throws \FormBuilder\exception\FormBuilderException
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function edit($id)
  75. {
  76. $data = \app\admin\model\auction\Auction::find($id);
  77. $f = [];
  78. $f[] = Form::input('name', '场次名称', $data->getData('name'))->col(12);
  79. $f[] = Form::input('advert', '预约广告值', $data->getData('advert'))->col(12);
  80. $f[] = Form::input('lowest', '额度门槛', $data->getData('lowest'));
  81. $f[] = Form::input('minimum', '广告值门槛', $data->getData('minimum'));
  82. $f[] = Form::input('dispatch', '派单百分比%', $data->getData('dispatch'));
  83. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  84. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  85. $f[] = Form::dateTimes('radd_time', '入场时间', $data->getData('radd_time'));
  86. $f[] = Form::dateTimes('rend_time', '结束时间', $data->getData('rend_time'));
  87. $f[] = Form::input('sort', '排序', $data->getData('sort'));
  88. $f[] = Form::textarea('info', '介绍', $data->getData('info'));
  89. $f[] = Form::hidden('id', $id);
  90. $form = Form::make_post_form('修改', $f, Url::buildUrl('save'));
  91. $this->assign(compact('form'));
  92. return $this->fetch('public/form-builder');
  93. }
  94. public function save()
  95. {
  96. $mode = new \app\admin\model\auction\Auction();
  97. $data = Util::postMore([
  98. 'id',
  99. 'name',
  100. 'image',
  101. 'status',
  102. 'sort',
  103. 'radd_time',
  104. 'rend_time',
  105. 'info',
  106. 'advert',
  107. 'lowest',
  108. 'minimum',
  109. 'dispatch'
  110. ]);
  111. $validate = Validate::rule('name', 'require')->rule([
  112. 'image' => 'require',
  113. 'status' => 'require',
  114. 'advert' => 'require',
  115. 'radd_time' => 'require',
  116. 'rend_time' => 'require',
  117. 'lowest' => 'require',
  118. 'minimum' => 'require',
  119. 'dispatch' => 'require',
  120. ]);
  121. $validate->message([
  122. 'name.require' => '名称不能为空',
  123. 'image.require' => '图片不能为空',
  124. 'status.require' => '状态不能为空',
  125. 'advert.require' => '请填写预约广告值',
  126. 'radd_time.require' => '请选择进场时间',
  127. 'rend_time.require' => '请选择结束时间',
  128. 'lowest.require' => '请填写额度门槛',
  129. 'minimum.require' => '请选择广告值门槛',
  130. 'dispatch.require' => '请填写派单量',
  131. ]);
  132. if (!$validate->check($data)) {
  133. return Json::fail($validate->getError());
  134. }
  135. if ($data['id']){
  136. $details = $mode->find($data['id']);
  137. unset($data['id']);
  138. $res = $details->save($data);
  139. }else{
  140. $res = $mode->save($data);
  141. }
  142. if ($res){
  143. return Json::success('成功!');
  144. }else{
  145. return Json::fail('失败');
  146. }
  147. }
  148. /**
  149. * 删除
  150. * @param $id
  151. * @return void
  152. * @throws \Exception
  153. */
  154. public function delete($id)
  155. {
  156. if (!$id) Json::fail('删除失败');
  157. $model = new \app\admin\model\auction\Auction();
  158. $res = $model->where('id', $id)->delete();
  159. if ($res){
  160. return Json::success('删除成功!');
  161. }else{
  162. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  163. }
  164. }
  165. public function set_status($id, $status)
  166. {
  167. if (empty($id))return Json::fail('修改失败');
  168. $res = \app\admin\model\auction\Auction::update(['status' => $status, 'id' => $id]);
  169. if ($res){
  170. return Json::success('修改成功!');
  171. }else{
  172. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  173. }
  174. }
  175. /**
  176. * 区间
  177. * @param $id
  178. * @return string
  179. * @throws \Exception
  180. */
  181. public function auction_section($id)
  182. {
  183. $this->assign('id', $id);
  184. return $this->fetch();
  185. }
  186. /**
  187. * 区间列表
  188. * @param $id
  189. * @return void
  190. */
  191. public function section_list ($id)
  192. {
  193. $where = Util::getMore([
  194. ['status', ''],
  195. ['page', 1],
  196. ['limit', 20],
  197. ['auction']
  198. ]);
  199. $list['data'] = AuctionSection::where('auction_id', $id)->page($where['page'], $where['limit'])->select();
  200. $list['data'] = empty($list['data']) ? [] : $list['data']->toArray();
  201. $list['count'] = AuctionSection::where('auction_id', $id)->count();
  202. return Json::successlayui($list);
  203. }
  204. /**
  205. * 区间添加
  206. * @param $id
  207. * @return string
  208. * @throws \Exception
  209. */
  210. public function section_create($id)
  211. {
  212. $f = [];
  213. $f[] = Form::input('name', '场次名称');
  214. $f[] = Form::number('low', '最低价格');
  215. $f[] = Form::number('high', '最高价格');
  216. $f[] = Form::hidden('auction_id', $id);
  217. $form = Form::make_post_form('添加', $f, Url::buildUrl('section_save'));
  218. $this->assign(compact('form'));
  219. return $this->fetch('public/form-builder');
  220. }
  221. /**
  222. * 区间添加
  223. * @param $id
  224. * @return string
  225. * @throws \Exception
  226. */
  227. public function section_edit($id)
  228. {
  229. $data = AuctionSection::where('id', $id)->find();
  230. $f = [];
  231. $f[] = Form::input('name', '场次名称', $data->getData('name'));
  232. $f[] = Form::number('low', '最低价格', $data->getData('low'));
  233. $f[] = Form::number('high', '最高价格', $data->getData('high'));
  234. $f[] = Form::hidden('auction_id', $data->getData('auction_id'));
  235. $f[] = Form::hidden('id', $id);
  236. $form = Form::make_post_form('修改', $f, Url::buildUrl('section_save'));
  237. $this->assign(compact('form'));
  238. return $this->fetch('public/form-builder');
  239. }
  240. public function section_save()
  241. {
  242. $data = Util::postMore([
  243. ['name'],
  244. ['low'],
  245. ['high'],
  246. ['id'],
  247. ['auction_id']
  248. ]);
  249. if (empty($data['name'])) return Json::fail('名称不能为空');
  250. if (empty($data['low'])) return Json::fail('设置最低价格');
  251. if (empty($data['high'])) return Json::fail('设置最高价格');
  252. if ($data['id']){
  253. $id = $data['id'];
  254. unset( $data['id']);
  255. $res = AuctionSection::where('id', $id)->save($data);
  256. }else{
  257. $res = AuctionSection::insert($data);
  258. }
  259. if (!$res){
  260. return Json::fail('失败');
  261. }
  262. return Json::success('成功');
  263. }
  264. /**
  265. * 删除
  266. * @param $id
  267. * @return void
  268. * @throws \Exception
  269. */
  270. public function section_delete($id)
  271. {
  272. if (!$id) Json::fail('删除失败');
  273. $model = new AuctionSection();
  274. $res = $model->where('id', $id)->delete();
  275. if ($res){
  276. return Json::success('删除成功!');
  277. }else{
  278. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  279. }
  280. }
  281. }