AuctionProduct.php 6.2 KB

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