AuctionProduct.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 edit($id)
  123. {
  124. if (!$id) Json::fail('数据不存在');
  125. $data = \app\admin\model\auction\Auction::select()->toArray();
  126. $this->assign(['id' => $id, 'list' => $data]);
  127. return $this->fetch();
  128. }
  129. public function get_list($id)
  130. {
  131. if (!$id) Json::fail('数据不存在');
  132. $model = new model();
  133. $info = $model->find($id);
  134. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  135. $info['description'] = htmlspecialchars_decode($info['description']);
  136. $data['productInfo'] = $info;
  137. return JsonService::successful($data);
  138. }
  139. public function update($id)
  140. {
  141. $data = Util::postMore([
  142. 'id',
  143. 'name',
  144. 'image',
  145. 'price',
  146. 'deduct',
  147. 'rise',
  148. 'info',
  149. 'sort',
  150. 'auction_id',
  151. 'hanging_price',
  152. 'slider_image',
  153. 'description',
  154. 'give',
  155. 'fictitious_price'
  156. ]);
  157. $data['slider_image'] = json_encode($data['slider_image']);
  158. $data['description'] = htmlspecialchars($data['description']);
  159. $res = model::update($data);
  160. if ($res){
  161. return Json::success('修改成功!');
  162. }else{
  163. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  164. }
  165. }
  166. /**
  167. * 修改商品所属人页面
  168. * @param $id
  169. * @return string
  170. * @throws \Exception
  171. */
  172. public function belonging($id)
  173. {
  174. $f = [];
  175. $f[] = Form::input('account', '输入用户账号或者ID' );
  176. $f[] = Form::hidden('id', $id );
  177. $form = Form::make_post_form('修改', $f, Url::buildUrl('belonging_save'));
  178. $this->assign(compact('form'));
  179. return $this->fetch('public/form-builder');
  180. }
  181. /**
  182. * 修改商品所属人
  183. * @param $account
  184. * @param $id
  185. * @return void
  186. * @throws \think\db\exception\DataNotFoundException
  187. * @throws \think\db\exception\DbException
  188. * @throws \think\db\exception\ModelNotFoundException
  189. */
  190. public function belonging_save($account, $id)
  191. {
  192. if (!$account) return Json::fail('不能为空');
  193. $user = User::where('account|uid', '=', $account)->find();
  194. if (!$user) return Json::fail('用户不存在');
  195. $product = \app\admin\model\auction\AuctionProduct::find($id);
  196. if ($product['is_admin'] != 1 and $product['is_show'] == 1){
  197. AuctionTime::where('product_id', $product['id'])->delete();// 删除上架信息
  198. }
  199. $product['is_show'] = 0;
  200. $product['uid'] = $user['uid'];
  201. $res = $product->save();
  202. if ($res) return Json::success('修改成功');
  203. return Json::fail('修改失败');
  204. }
  205. public function fz($id)
  206. {
  207. if (!$id) Json::fail('数据不存在');
  208. $data = \app\admin\model\auction\Auction::select()->toArray();
  209. $this->assign(['id' => $id, 'list' => $data]);
  210. return $this->fetch();
  211. }
  212. public function fzsp($id)
  213. {
  214. $data = Util::postMore([
  215. 'name',
  216. 'image',
  217. 'price',
  218. 'deduct',
  219. 'rise',
  220. 'info',
  221. 'sort',
  222. 'auction_id',
  223. 'hanging_price',
  224. 'slider_image',
  225. 'description',
  226. 'give',
  227. 'uid',
  228. 'fictitious_price'
  229. ]);
  230. $data['slider_image'] = json_encode($data['slider_image']);
  231. $data['description'] = htmlspecialchars($data['description']);
  232. $res = model::create($data);
  233. if ($res){
  234. return Json::success('修改成功!');
  235. }else{
  236. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  237. }
  238. }
  239. }