AuctionGu.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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\User;
  6. use crmeb\services\{ExpressService,
  7. FormBuilder,
  8. JsonService,
  9. MiniProgramService,
  10. upload\Upload,
  11. WechatService,
  12. FormBuilder as Form,
  13. CacheService,
  14. UtilService as Util,
  15. JsonService as Json};
  16. use app\admin\model\system\{SystemAdmin,
  17. SystemAttachment as SystemAttachmentModel,
  18. SystemAttachmentCategory as Category};
  19. use think\Db;
  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 AuctionGu extends AuthController
  28. {
  29. public function index()
  30. {
  31. $this->assign('admin', $this->adminInfo);
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['status', ''],
  38. ['page', 1],
  39. ['limit', 20],
  40. ['auction'],
  41. ['uid'],
  42. ['null']
  43. ]);
  44. if ($this->adminInfo['roles'] == 8){
  45. if ($this->adminInfo['uid']){
  46. $where['uid'] = $this->adminInfo['uid'];
  47. }
  48. }
  49. $data = \app\admin\model\auction\AuctionGu::list($where);
  50. return Json::successlayui($data);
  51. }
  52. /**
  53. * 显示创建资源表单页.
  54. *
  55. * @return \think\Response
  56. */
  57. public function create($id = 0)
  58. {
  59. $f = [];
  60. $f[] = Form::input('name', '场馆名称')->col(12);
  61. $f[] = Form::input('max_hanging', '最大挂售额度')->col(12);
  62. $f[] = Form::frameImageOne('image', '主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  63. $f[] = Form::frameImages('slider_image', '轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')))->maxLength(3)->icon('images')->width('100%')->height('500px');
  64. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  65. $f[] = Form::select('uid', '绑定用户')->setOptions(function () {
  66. $model = new \app\models\user\User();
  67. $list = $model->select();
  68. $menus = [];
  69. foreach ($list as $menu) {
  70. $menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
  71. }
  72. return $menus;
  73. })->filterable(1)->col(12);
  74. $f[] = Form::input('sort', '排序', '0')->col(12);
  75. $f[] = Form::textarea('info', '介绍');
  76. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  77. $this->assign(compact('form'));
  78. return $this->fetch('public/form-builder');
  79. }
  80. public function save()
  81. {
  82. $mode = new \app\admin\model\auction\AuctionGu();
  83. $data = Util::postMore([
  84. 'name',
  85. 'image',
  86. 'sort',
  87. 'info',
  88. 'uid',
  89. 'slider_image',
  90. 'max_hanging'
  91. ]);
  92. $validate = Validate::rule('name', 'require')->rule([
  93. 'name' => 'require',
  94. 'image' => 'require',
  95. 'uid' => 'require',
  96. 'slider_image' => 'require',
  97. 'max_hanging' => 'require'
  98. ]);
  99. $validate->message([
  100. 'name.require' => '名称不能为空',
  101. 'image.require' => '图片不能为空',
  102. 'uid.require' => '请绑定用户',
  103. 'slider_image.require' => '轮播图不能为空',
  104. 'max_hanging.require' => '挂售额度不能为空',
  105. ]);
  106. $data['slider_image'] = json_encode($data['slider_image']);
  107. if (!$validate->check($data)) {
  108. return Json::fail($validate->getError());
  109. }
  110. $user = \app\models\user\User::where('uid', $data['uid'])->find();
  111. if ($user['spread_uid']){
  112. $user['spread_uid'] = 0; // 更新用户上级
  113. $user->save();
  114. }
  115. $res = $mode->save($data);
  116. if ($res){
  117. return Json::success('添加成功!');
  118. }else{
  119. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  120. }
  121. }
  122. /**
  123. * 删除
  124. * @param $id
  125. * @return void
  126. * @throws \Exception
  127. */
  128. public function delete($id)
  129. {
  130. if (!$id) Json::fail('删除失败');
  131. $model = new \app\admin\model\auction\AuctionGu();
  132. $res = $model->where('id', $id)->delete();
  133. if ($res){
  134. return Json::success('删除成功!');
  135. }else{
  136. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  137. }
  138. }
  139. public function set_status($id, $status)
  140. {
  141. if (empty($id))return Json::fail('修改失败');
  142. $res = \app\admin\model\auction\AuctionGu::update(['status' => $status, 'id' => $id]);
  143. if ($res){
  144. return Json::success('修改成功!');
  145. }else{
  146. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  147. }
  148. }
  149. public function edit($id)
  150. {
  151. if (!$id) Json::fail('数据不存在');
  152. $data = \app\admin\model\auction\AuctionGu::find($id);
  153. $f = [];
  154. $f[] = Form::input('name', '场馆名称',$data->getData('name'))->col(12);
  155. if ($this->adminInfo['roles'] == 8){
  156. $f[] = Form::hidden('max_hanging', $data->getData('max_hanging'))->col(12);
  157. }else{
  158. $f[] = Form::input('max_hanging', '最大挂售额度',$data->getData('max_hanging'))->col(12);
  159. }
  160. $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  161. $f[] = Form::frameImages('slider_image', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')), json_decode($data->getData('slider_image'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
  162. $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  163. $f[] = Form::select('uid', '绑定用户',(string)$data->getData('uid'))->setOptions(function () {
  164. $model = new \app\models\user\User();
  165. $list = $model->select();
  166. $menus = [];
  167. foreach ($list as $menu) {
  168. $menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
  169. }
  170. return $menus;
  171. })->filterable(1)->col(12);
  172. $f[] = Form::input('sort', '排序' ,$data->getData('sort'))->col(12);
  173. $f[] = Form::textarea('info', '介绍',$data->getData('info'));
  174. $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
  175. $this->assign(compact('form'));
  176. return $this->fetch('public/form-builder');
  177. }
  178. public function get_auction($id)
  179. {
  180. if (!$id) Json::fail('数据不存在');
  181. $info = \app\admin\model\auction\AuctionGu::find($id)->toArray();
  182. $data['productInfo'] = $info;
  183. return JsonService::successful($data);
  184. }
  185. public function update()
  186. {
  187. $data = Util::postMore([
  188. 'id',
  189. 'name',
  190. 'image',
  191. 'sort',
  192. 'info',
  193. 'uid',
  194. 'status',
  195. 'slider_image',
  196. 'max_hanging'
  197. ]);
  198. $validate = Validate::rule('name', 'require')->rule([
  199. 'name' => 'require',
  200. 'image' => 'require',
  201. 'uid' => 'require',
  202. 'slider_image' => 'require',
  203. 'max_hanging' => 'require'
  204. ]);
  205. $validate->message([
  206. 'name.require' => '名称不能为空',
  207. 'image.require' => '图片不能为空',
  208. 'uid.require' => '请绑定用户',
  209. 'slider_image.require' => '轮播图不能为空',
  210. 'max_hanging.require' => '挂售额度不能为空',
  211. ]);
  212. if (!$validate->check($data)) {
  213. return Json::fail($validate->getError());
  214. }
  215. $data['slider_image'] = json_encode($data['slider_image']);
  216. $user = \app\models\user\User::where('uid', $data['uid'])->find();
  217. if ($user['spread_uid']){
  218. $user['spread_uid'] = 0; // 更新用户上级
  219. $user->save();
  220. }
  221. $res = \app\admin\model\auction\AuctionGu::update($data);
  222. if ($res){
  223. return Json::success('修改成功!');
  224. }else{
  225. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  226. }
  227. }
  228. // public function edit($id)
  229. // {
  230. // if (!$id) Json::fail('数据不存在');
  231. //
  232. //
  233. // $list = \app\admin\model\auction\Auction::get($id);
  234. // if (!$list) Json::fail('数据不存在');
  235. //
  236. // $f = array();
  237. // $f[] = Form::input('id', 'ID', $list->getData('id'))->disabled(1);
  238. // $f[] = Form::input('nickname', '名称', $list->getData('nickname'));
  239. // $f[] = Form::uploadImageOne('image', '图片','/index.php/admin/widget.images/upload',$list->getData('image'));
  240. // $f[] = Form::radio('is_promoter', '推广员',$list->getData('status'))->options([['value' => 1, 'label' => '启用'], ['value' => 0, 'label' => '禁用']]);
  241. // $f[] = Form::dateTime('time', '推广员',$list->getData('add_time'));
  242. //
  243. // $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $id)), 5);
  244. // $this->assign(compact('form'));
  245. // return $this->fetch('public/form-builder');
  246. // }
  247. }