AuctionProduct.php 7.2 KB

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