Auction.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\User;
  5. use crmeb\services\{ExpressService,
  6. JsonService,
  7. JsonService as Json,
  8. MiniProgramService,
  9. upload\Upload,
  10. WechatService,
  11. FormBuilder as Form,
  12. CacheService,
  13. UtilService as Util};
  14. use app\admin\model\system\{
  15. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  16. };
  17. use think\facade\Route as Url;
  18. use think\facade\Validate;
  19. /**
  20. * 竞拍管理
  21. * Class StoreOrder
  22. * @package app\admin\controller\store
  23. */
  24. class Auction extends AuthController
  25. {
  26. public function index()
  27. {
  28. return $this->fetch();
  29. }
  30. public function list()
  31. {
  32. $where = Util::getMore([
  33. ['status', ''],
  34. ['page', 1],
  35. ['limit', 20],
  36. ['auction']
  37. ]);
  38. $data = \app\admin\model\auction\Auction::list($where);
  39. return Json::successlayui($data);
  40. }
  41. /**
  42. * 显示创建资源表单页.
  43. *
  44. * @return \think\Response
  45. */
  46. public function create($id = 0)
  47. {
  48. $f = [];
  49. $f[] = Form::input('name', '场次名称')->col(12);
  50. $f[] = Form::input('advert', '预约广告值')->col(12);
  51. $f[] = Form::input('lowest', '额度门槛');
  52. $f[] = Form::input('minimum', '广告值门槛');
  53. $f[] = Form::input('dispatch', '派单百分比%', 100)->col(12);
  54. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  55. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  56. $f[] = Form::dateTimes('radd_time', '入场时间');
  57. $f[] = Form::dateTimes('rend_time', '结束时间');
  58. $f[] = Form::input('sort', '排序',0);
  59. $f[] = Form::textarea('info', '介绍');
  60. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  61. $this->assign(compact('form'));
  62. return $this->fetch('public/form-builder');
  63. }
  64. /**
  65. * 修改页面
  66. * @param $id
  67. * @return string
  68. * @throws \FormBuilder\exception\FormBuilderException
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function edit($id)
  74. {
  75. $data = \app\admin\model\auction\Auction::find($id);
  76. $f = [];
  77. $f[] = Form::input('name', '场次名称', $data->getData('name'))->col(12);
  78. $f[] = Form::input('advert', '预约广告值', $data->getData('advert'))->col(12);
  79. $f[] = Form::input('lowest', '额度门槛', $data->getData('lowest'));
  80. $f[] = Form::input('minimum', '广告值门槛', $data->getData('minimum'));
  81. $f[] = Form::input('dispatch', '派单百分比%', $data->getData('dispatch'));
  82. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  83. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  84. $f[] = Form::dateTimes('radd_time', '入场时间', $data->getData('radd_time'));
  85. $f[] = Form::dateTimes('rend_time', '结束时间', $data->getData('rend_time'));
  86. $f[] = Form::input('sort', '排序', $data->getData('sort'));
  87. $f[] = Form::textarea('info', '介绍', $data->getData('info'));
  88. $f[] = Form::hidden('id', $id);
  89. $form = Form::make_post_form('修改', $f, Url::buildUrl('save'));
  90. $this->assign(compact('form'));
  91. return $this->fetch('public/form-builder');
  92. }
  93. public function save()
  94. {
  95. $mode = new \app\admin\model\auction\Auction();
  96. $data = Util::postMore([
  97. 'id',
  98. 'name',
  99. 'image',
  100. 'status',
  101. 'sort',
  102. 'radd_time',
  103. 'rend_time',
  104. 'info',
  105. 'advert',
  106. 'lowest',
  107. 'minimum',
  108. 'dispatch'
  109. ]);
  110. $validate = Validate::rule('name', 'require')->rule([
  111. 'image' => 'require',
  112. 'status' => 'require',
  113. 'advert' => 'require',
  114. 'radd_time' => 'require',
  115. 'rend_time' => 'require',
  116. 'lowest' => 'require',
  117. 'minimum' => 'require',
  118. 'dispatch' => 'require',
  119. ]);
  120. $validate->message([
  121. 'name.require' => '名称不能为空',
  122. 'image.require' => '图片不能为空',
  123. 'status.require' => '状态不能为空',
  124. 'advert.require' => '请填写预约广告值',
  125. 'radd_time.require' => '请选择进场时间',
  126. 'rend_time.require' => '请选择结束时间',
  127. 'lowest.require' => '请填写额度门槛',
  128. 'minimum.require' => '请选择广告值门槛',
  129. 'dispatch.require' => '请填写派单量',
  130. ]);
  131. if (!$validate->check($data)) {
  132. return Json::fail($validate->getError());
  133. }
  134. if ($data['id']){
  135. $details = $mode->find($data['id']);
  136. unset($data['id']);
  137. $res = $details->save($data);
  138. }else{
  139. $res = $mode->save($data);
  140. }
  141. if ($res){
  142. return Json::success('成功!');
  143. }else{
  144. return Json::fail('失败');
  145. }
  146. }
  147. /**
  148. * 删除
  149. * @param $id
  150. * @return void
  151. * @throws \Exception
  152. */
  153. public function delete($id)
  154. {
  155. if (!$id) Json::fail('删除失败');
  156. $model = new \app\admin\model\auction\Auction();
  157. $res = $model->where('id', $id)->delete();
  158. if ($res){
  159. return Json::success('删除成功!');
  160. }else{
  161. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  162. }
  163. }
  164. public function set_status($id, $status)
  165. {
  166. if (empty($id))return Json::fail('修改失败');
  167. $res = \app\admin\model\auction\Auction::update(['status' => $status, 'id' => $id]);
  168. if ($res){
  169. return Json::success('修改成功!');
  170. }else{
  171. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  172. }
  173. }
  174. }