AuctionProduct.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\models\auction\AuctionTime;
  6. use app\models\user\User;
  7. use crmeb\services\{ExpressService,
  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\{
  17. SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
  18. };
  19. use app\admin\model\auction\AuctionProduct as model;
  20. use think\facade\Route as Url;
  21. /**
  22. * 竞拍管理
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class AuctionProduct extends AuthController
  27. {
  28. public function index()
  29. {
  30. $list = \app\admin\model\auction\Auction::select();
  31. $this->assign('auction', $list);
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['is_show', ''],
  38. ['page', 1],
  39. ['limit', 20],
  40. ['auction_id', ''],
  41. ['store_name', '']
  42. ]);
  43. $data = model::list($where);
  44. foreach ($data['data'] as $key => $val){
  45. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  46. }
  47. return Json::successlayui($data);
  48. }
  49. public function auction_list()
  50. {
  51. $list = model::select()->toArray();
  52. Json::successful($list);
  53. }
  54. /**
  55. * 显示创建资源表单页.
  56. *
  57. * @return \think\Response
  58. */
  59. public function create($id = 0)
  60. {
  61. $data = \app\admin\model\auction\Auction::select()->toArray();
  62. $this->assign(['id' => $id, 'list' => $data]);
  63. return $this->fetch();
  64. }
  65. public function save($id)
  66. {
  67. $data = Util::postMore([
  68. 'name',
  69. 'is_show',
  70. 'image',
  71. 'price',
  72. 'deduct',
  73. 'rise',
  74. 'info',
  75. 'sort',
  76. 'auction_id',
  77. 'hanging_price',
  78. 'slider_image',
  79. 'description',
  80. 'give',
  81. 'fictitious_price'
  82. ]);
  83. $data['slider_image'] = json_encode($data['slider_image']);
  84. $data['description'] = htmlspecialchars($data['description']);
  85. $auction = \app\admin\model\auction\Auction::where('id' ,$data['auction_id'])->find();
  86. $auction_gu = \app\admin\model\auction\AuctionGu::where('id' ,$auction['auction_gu_id'])->find();
  87. $data['uid'] = $auction_gu['uid'];
  88. $model = new model();
  89. $res = $model->save($data);
  90. if ($res){
  91. return Json::success('添加成功!');
  92. }else{
  93. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  94. }
  95. }
  96. /**
  97. * 删除
  98. * @param $id
  99. * @return void
  100. * @throws \Exception
  101. */
  102. public function delete($id)
  103. {
  104. if (!$id)return Json::fail('删除失败');
  105. $res = model::where('id', $id)->delete();
  106. if ($res){
  107. return Json::success('删除成功!');
  108. }else{
  109. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  110. }
  111. }
  112. public function set_status($id, $status)
  113. {
  114. if (empty($id))return Json::fail('修改失败');
  115. $res = model::update(['is_show' => $status, 'id' => $id]);
  116. if ($res){
  117. return Json::success('修改成功!');
  118. }else{
  119. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  120. }
  121. }
  122. public function set_frozen($id, $status)
  123. {
  124. if (empty($id))return Json::fail('修改失败');
  125. $res = model::update(['frozen' => $status, 'id' => $id]);
  126. if ($res){
  127. return Json::success('修改成功!');
  128. }else{
  129. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  130. }
  131. }
  132. public function edit($id)
  133. {
  134. if (!$id) Json::fail('数据不存在');
  135. $data = \app\admin\model\auction\Auction::select()->toArray();
  136. $this->assign(['id' => $id, 'list' => $data]);
  137. return $this->fetch();
  138. }
  139. public function get_list($id)
  140. {
  141. if (!$id) Json::fail('数据不存在');
  142. $model = new model();
  143. $info = $model->find($id);
  144. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  145. $info['description'] = htmlspecialchars_decode($info['description']);
  146. $data['productInfo'] = $info;
  147. return JsonService::successful($data);
  148. }
  149. public function update($id)
  150. {
  151. $data = Util::postMore([
  152. 'id',
  153. 'name',
  154. 'image',
  155. 'price',
  156. 'deduct',
  157. 'rise',
  158. 'info',
  159. 'sort',
  160. 'auction_id',
  161. 'hanging_price',
  162. 'slider_image',
  163. 'description',
  164. 'give',
  165. 'fictitious_price'
  166. ]);
  167. $data['slider_image'] = json_encode($data['slider_image']);
  168. $data['description'] = htmlspecialchars($data['description']);
  169. $res = model::update($data);
  170. if ($res){
  171. return Json::success('修改成功!');
  172. }else{
  173. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  174. }
  175. }
  176. /**
  177. * 修改商品所属人页面
  178. * @param $id
  179. * @return string
  180. * @throws \Exception
  181. */
  182. public function belonging($id)
  183. {
  184. $f = [];
  185. $f[] = Form::input('account', '输入用户账号或者ID' );
  186. $f[] = Form::hidden('id', $id );
  187. $form = Form::make_post_form('修改', $f, Url::buildUrl('belonging_save'));
  188. $this->assign(compact('form'));
  189. return $this->fetch('public/form-builder');
  190. }
  191. /**
  192. * 修改商品所属人
  193. * @param $account
  194. * @param $id
  195. * @return void
  196. * @throws \think\db\exception\DataNotFoundException
  197. * @throws \think\db\exception\DbException
  198. * @throws \think\db\exception\ModelNotFoundException
  199. */
  200. public function belonging_save($account, $id)
  201. {
  202. if (!$account) return Json::fail('不能为空');
  203. $user = User::where('account|uid', '=', $account)->find();
  204. if (!$user) return Json::fail('用户不存在');
  205. $product = \app\admin\model\auction\AuctionProduct::find($id);
  206. if ($product['is_admin'] != 1 and $product['is_show'] == 1){
  207. AuctionTime::where('product_id', $product['id'])->delete();// 删除上架信息
  208. }
  209. $product['is_show'] = 0;
  210. $product['uid'] = $user['uid'];
  211. $res = $product->save();
  212. if ($res) return Json::success('修改成功');
  213. return Json::fail('修改失败');
  214. }
  215. public function fz($id)
  216. {
  217. if (!$id) Json::fail('数据不存在');
  218. $data = \app\admin\model\auction\Auction::select()->toArray();
  219. $this->assign(['id' => $id, 'list' => $data]);
  220. return $this->fetch();
  221. }
  222. public function fzsp($id)
  223. {
  224. $data = Util::postMore([
  225. 'name',
  226. 'image',
  227. 'price',
  228. 'deduct',
  229. 'rise',
  230. 'info',
  231. 'sort',
  232. 'auction_id',
  233. 'hanging_price',
  234. 'slider_image',
  235. 'description',
  236. 'give',
  237. 'uid',
  238. 'fictitious_price'
  239. ]);
  240. $data['slider_image'] = json_encode($data['slider_image']);
  241. $data['description'] = htmlspecialchars($data['description']);
  242. $res = model::create($data);
  243. if ($res){
  244. return Json::success('修改成功!');
  245. }else{
  246. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  247. }
  248. }
  249. }