AuctionProduct.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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->insertGetId($data);
  90. $datas = \app\models\auction\AuctionProduct::bs($res);// 获取挂售详情
  91. // 新增挂售时间段
  92. AuctionTime::create([
  93. 'uid' => $auction_gu['uid'],
  94. 'product_id' => $res,
  95. 'auction_id' => $data['auction_id'],
  96. 'add_time' => strtotime($datas['gs_time'])
  97. ]);
  98. if ($res){
  99. return Json::success('添加成功!');
  100. }else{
  101. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  102. }
  103. }
  104. /**
  105. * 删除
  106. * @param $id
  107. * @return void
  108. * @throws \Exception
  109. */
  110. public function delete($id)
  111. {
  112. if (!$id)return Json::fail('删除失败');
  113. $res = model::where('id', $id)->delete();
  114. if ($res){
  115. return Json::success('删除成功!');
  116. }else{
  117. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  118. }
  119. }
  120. public function set_status($id, $status)
  121. {
  122. if (empty($id))return Json::fail('修改失败');
  123. $res = model::update(['is_show' => $status, 'id' => $id]);
  124. if ($res){
  125. return Json::success('修改成功!');
  126. }else{
  127. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  128. }
  129. }
  130. public function set_frozen($id, $status)
  131. {
  132. if (empty($id))return Json::fail('修改失败');
  133. $res = model::update(['frozen' => $status, 'id' => $id]);
  134. if ($res){
  135. return Json::success('修改成功!');
  136. }else{
  137. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  138. }
  139. }
  140. public function edit($id)
  141. {
  142. if (!$id) Json::fail('数据不存在');
  143. $data = \app\admin\model\auction\Auction::select()->toArray();
  144. $this->assign(['id' => $id, 'list' => $data]);
  145. return $this->fetch();
  146. }
  147. public function get_list($id)
  148. {
  149. if (!$id) Json::fail('数据不存在');
  150. $model = new model();
  151. $info = $model->find($id);
  152. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  153. $info['description'] = htmlspecialchars_decode($info['description']);
  154. $data['productInfo'] = $info;
  155. return JsonService::successful($data);
  156. }
  157. public function update($id)
  158. {
  159. $data = Util::postMore([
  160. 'id',
  161. 'name',
  162. 'image',
  163. 'price',
  164. 'deduct',
  165. 'rise',
  166. 'info',
  167. 'sort',
  168. 'auction_id',
  169. 'hanging_price',
  170. 'slider_image',
  171. 'description',
  172. 'give',
  173. 'fictitious_price'
  174. ]);
  175. $data['slider_image'] = json_encode($data['slider_image']);
  176. $data['description'] = htmlspecialchars($data['description']);
  177. $res = model::update($data);
  178. if ($res){
  179. return Json::success('修改成功!');
  180. }else{
  181. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  182. }
  183. }
  184. /**
  185. * 修改商品所属人页面
  186. * @param $id
  187. * @return string
  188. * @throws \Exception
  189. */
  190. public function belonging($id)
  191. {
  192. $f = [];
  193. $f[] = Form::input('account', '输入用户账号或者ID' );
  194. $f[] = Form::hidden('id', $id );
  195. $form = Form::make_post_form('修改', $f, Url::buildUrl('belonging_save'));
  196. $this->assign(compact('form'));
  197. return $this->fetch('public/form-builder');
  198. }
  199. /**
  200. * 修改商品所属人
  201. * @param $account
  202. * @param $id
  203. * @return void
  204. * @throws \think\db\exception\DataNotFoundException
  205. * @throws \think\db\exception\DbException
  206. * @throws \think\db\exception\ModelNotFoundException
  207. */
  208. public function belonging_save($account, $id)
  209. {
  210. if (!$account) return Json::fail('不能为空');
  211. $user = User::where('account|uid', '=', $account)->find();
  212. if (!$user) return Json::fail('用户不存在');
  213. $product = \app\admin\model\auction\AuctionProduct::find($id);
  214. if ($product['is_admin'] != 1 and $product['is_show'] == 1){
  215. AuctionTime::where('product_id', $product['id'])->delete();// 删除上架信息
  216. }
  217. $product['is_show'] = 0;
  218. $product['uid'] = $user['uid'];
  219. $res = $product->save();
  220. if ($res) return Json::success('修改成功');
  221. return Json::fail('修改失败');
  222. }
  223. public function fz($id)
  224. {
  225. if (!$id) Json::fail('数据不存在');
  226. $data = \app\admin\model\auction\Auction::select()->toArray();
  227. $this->assign(['id' => $id, 'list' => $data]);
  228. return $this->fetch();
  229. }
  230. public function fzsp($id)
  231. {
  232. $data = Util::postMore([
  233. 'name',
  234. 'image',
  235. 'price',
  236. 'deduct',
  237. 'rise',
  238. 'info',
  239. 'sort',
  240. 'auction_id',
  241. 'hanging_price',
  242. 'slider_image',
  243. 'description',
  244. 'give',
  245. 'uid',
  246. 'fictitious_price'
  247. ]);
  248. $data['slider_image'] = json_encode($data['slider_image']);
  249. $data['description'] = htmlspecialchars($data['description']);
  250. $model = new model();
  251. $res = $model->insertGetId($data);
  252. $datas = \app\models\auction\AuctionProduct::bs($res);// 获取挂售详情
  253. // 新增挂售时间段
  254. AuctionTime::create([
  255. 'uid' => $data['uid'],
  256. 'product_id' => $res,
  257. 'auction_id' => $data['auction_id'],
  258. 'add_time' => strtotime($datas['gs_time'])
  259. ]);
  260. if ($res){
  261. return Json::success('修改成功!');
  262. }else{
  263. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  264. }
  265. }
  266. }