AuctionProduct.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use crmeb\services\{ExpressService,
  6. JsonService,
  7. MiniProgramService,
  8. upload\Upload,
  9. WechatService,
  10. FormBuilder as Form,
  11. CacheService,
  12. UtilService as Util,
  13. JsonService as Json};
  14. use app\admin\model\system\{
  15. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  16. };
  17. use app\admin\model\auction\AuctionProduct as model;
  18. use think\facade\Db;
  19. use think\facade\Route as Url;
  20. /**
  21. * 竞拍管理
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class AuctionProduct extends AuthController
  26. {
  27. /**
  28. * 商品列表
  29. * @param $id
  30. * @return void
  31. */
  32. public function index($id)
  33. {
  34. $list = \app\admin\model\auction\Auction::select();
  35. $this->assign([
  36. 'auction'=> $list,
  37. 'id' => $id
  38. ]);
  39. return $this->fetch('auction/auction_product/index');
  40. }
  41. public function list($id)
  42. {
  43. $where = Util::getMore([
  44. ['is_show', ''],
  45. ['page', 1],
  46. ['limit', 20],
  47. ['store_name', '']
  48. ]);
  49. $data = model::list($where, $id);
  50. foreach ($data['data'] as $key => $val){
  51. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  52. }
  53. return Json::successlayui($data);
  54. }
  55. public function auction_list()
  56. {
  57. $list = model::select()->toArray();
  58. Json::successful($list);
  59. }
  60. /**
  61. * 显示创建资源表单页.
  62. *
  63. * @return \think\Response
  64. */
  65. public function create($id = 0)
  66. {
  67. $this->assign(['id' => $id]);
  68. return $this->fetch();
  69. }
  70. public function save($id)
  71. {
  72. $data = Util::postMore([
  73. 'name',
  74. 'is_show',
  75. 'image',
  76. 'price',
  77. 'info',
  78. 'sort',
  79. 'auction_id',
  80. 'hanging_price',
  81. 'slider_image',
  82. 'description',
  83. 'pl'
  84. ]);
  85. $data['slider_image'] = json_encode($data['slider_image']);
  86. $data['description'] = htmlspecialchars($data['description']);
  87. $model = new model();
  88. if($data['pl']){
  89. for ($x=0; $x<$data['pl']; $x++) {
  90. $res = $model->create($data);
  91. }
  92. }else{
  93. $res = $model->save($data);
  94. }
  95. if ($res){
  96. return Json::success('添加成功!');
  97. }else{
  98. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  99. }
  100. }
  101. /**
  102. * 删除
  103. * @param $id
  104. * @return void
  105. * @throws \Exception
  106. */
  107. public function delete($id)
  108. {
  109. if (!$id)return Json::fail('删除失败');
  110. $res = model::where('id', $id)->delete();
  111. if ($res){
  112. return Json::success('删除成功!');
  113. }else{
  114. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  115. }
  116. }
  117. public function set_status($id, $status)
  118. {
  119. if (empty($id))return Json::fail('修改失败');
  120. $res = model::update(['is_show' => $status, 'id' => $id]);
  121. if ($res){
  122. return Json::success('修改成功!');
  123. }else{
  124. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  125. }
  126. }
  127. public function edit($id, $auction_id)
  128. {
  129. if (!$id) Json::fail('数据不存在');
  130. $this->assign(['id' => $id, 'auction_id' => $auction_id]);
  131. return $this->fetch();
  132. }
  133. public function get_list($id)
  134. {
  135. if (!$id) Json::fail('数据不存在');
  136. $model = new model();
  137. $info = $model->find($id);
  138. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  139. $info['description'] = htmlspecialchars_decode($info['description']);
  140. $data['productInfo'] = $info;
  141. return JsonService::successful($data);
  142. }
  143. public function update($id)
  144. {
  145. $data = Util::postMore([
  146. 'id',
  147. 'name',
  148. 'image',
  149. 'price',
  150. 'deduct',
  151. 'rise',
  152. 'info',
  153. 'sort',
  154. 'auction_id',
  155. 'hanging_price',
  156. 'slider_image',
  157. 'description'
  158. ]);
  159. $data['slider_image'] = json_encode($data['slider_image']);
  160. $data['description'] = htmlspecialchars($data['description']);
  161. $res = model::update($data);
  162. if ($res){
  163. return Json::success('修改成功!');
  164. }else{
  165. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  166. }
  167. }
  168. // public function edit($id)
  169. // {
  170. // if (!$id) Json::fail('数据不存在');
  171. //
  172. //
  173. // $list = \app\admin\model\auction\Auction::get($id);
  174. // if (!$list) Json::fail('数据不存在');
  175. //
  176. // $f = array();
  177. // $f[] = Form::input('id', 'ID', $list->getData('id'))->disabled(1);
  178. // $f[] = Form::input('nickname', '名称', $list->getData('nickname'));
  179. // $f[] = Form::uploadImageOne('image', '图片','/index.php/admin/widget.images/upload',$list->getData('image'));
  180. // $f[] = Form::radio('is_promoter', '推广员',$list->getData('status'))->options([['value' => 1, 'label' => '启用'], ['value' => 0, 'label' => '禁用']]);
  181. // $f[] = Form::dateTime('time', '推广员',$list->getData('add_time'));
  182. //
  183. // $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $id)), 5);
  184. // $this->assign(compact('form'));
  185. // return $this->fetch('public/form-builder');
  186. // }
  187. }