AuctionProduct.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\models\user\User;
  6. use app\models\user\UserBill;
  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\Db;
  21. use think\facade\Route as Url;
  22. /**
  23. * 竞拍管理
  24. * Class StoreOrder
  25. * @package app\admin\controller\store
  26. */
  27. class AuctionProduct extends AuthController
  28. {
  29. /**
  30. * 商品列表
  31. * @param $id
  32. * @return void
  33. */
  34. public function index($id)
  35. {
  36. $list = \app\admin\model\auction\Auction::select();
  37. $this->assign([
  38. 'auction'=> $list,
  39. 'id' => $id
  40. ]);
  41. return $this->fetch('auction/auction_product/index');
  42. }
  43. public function list($id)
  44. {
  45. $where = Util::getMore([
  46. ['is_show', ''],
  47. ['page', 1],
  48. ['limit', 20],
  49. ['store_name', '']
  50. ]);
  51. $data = model::list($where, $id);
  52. foreach ($data['data'] as $key => $val){
  53. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  54. }
  55. return Json::successlayui($data);
  56. }
  57. public function auction_list()
  58. {
  59. $list = model::select()->toArray();
  60. Json::successful($list);
  61. }
  62. /**
  63. * 显示创建资源表单页.
  64. *
  65. * @return \think\Response
  66. */
  67. public function create($id = 0)
  68. {
  69. $this->assign(['id' => $id]);
  70. return $this->fetch();
  71. }
  72. public function save($id)
  73. {
  74. $data = Util::postMore([
  75. 'name',
  76. 'is_show',
  77. 'image',
  78. 'price',
  79. 'info',
  80. 'sort',
  81. 'auction_id',
  82. 'hanging_price',
  83. 'slider_image',
  84. 'description',
  85. 'pl'
  86. ]);
  87. $data['slider_image'] = json_encode($data['slider_image']);
  88. $data['description'] = htmlspecialchars($data['description']);
  89. $model = new model();
  90. if($data['pl']){
  91. for ($x=0; $x<$data['pl']; $x++) {
  92. $res = $model->create($data);
  93. }
  94. }else{
  95. $res = $model->save($data);
  96. }
  97. if ($res){
  98. return Json::success('添加成功!');
  99. }else{
  100. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  101. }
  102. }
  103. /**
  104. * 删除
  105. * @param $id
  106. * @return void
  107. * @throws \Exception
  108. */
  109. public function delete($id)
  110. {
  111. if (!$id)return Json::fail('删除失败');
  112. $res = model::where('id', $id)->delete();
  113. if ($res){
  114. return Json::success('删除成功!');
  115. }else{
  116. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  117. }
  118. }
  119. public function set_status($id, $status)
  120. {
  121. if (empty($id))return Json::fail('修改失败');
  122. $res = model::update(['is_show' => $status, 'id' => $id]);
  123. if ($res){
  124. return Json::success('修改成功!');
  125. }else{
  126. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  127. }
  128. }
  129. public function edit($id, $auction_id)
  130. {
  131. if (!$id) Json::fail('数据不存在');
  132. $this->assign(['id' => $id, 'auction_id' => $auction_id]);
  133. return $this->fetch();
  134. }
  135. public function get_list($id)
  136. {
  137. if (!$id) Json::fail('数据不存在');
  138. $model = new model();
  139. $info = $model->find($id);
  140. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  141. $info['description'] = htmlspecialchars_decode($info['description']);
  142. $data['productInfo'] = $info;
  143. return JsonService::successful($data);
  144. }
  145. public function update($id)
  146. {
  147. $data = Util::postMore([
  148. 'id',
  149. 'name',
  150. 'image',
  151. 'price',
  152. 'deduct',
  153. 'rise',
  154. 'info',
  155. 'sort',
  156. 'auction_id',
  157. 'hanging_price',
  158. 'slider_image',
  159. 'description'
  160. ]);
  161. $data['slider_image'] = json_encode($data['slider_image']);
  162. $data['description'] = htmlspecialchars($data['description']);
  163. $res = model::update($data);
  164. if ($res){
  165. return Json::success('修改成功!');
  166. }else{
  167. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  168. }
  169. }
  170. /**
  171. * 回收
  172. * @param $id
  173. * @return void
  174. * @throws \think\db\exception\DataNotFoundException
  175. * @throws \think\db\exception\DbException
  176. * @throws \think\db\exception\ModelNotFoundException
  177. */
  178. public function hs($id)
  179. {
  180. $userModel = new User();
  181. $productModel = new \app\admin\model\auction\AuctionProduct();
  182. $product = $productModel->find($id);
  183. if ($product['is_show'] < 1) return Json::fail('当前状态不能回收');
  184. if ($product['uid'] > 0){
  185. $user = $userModel->where('uid', $product['uid'])->find();
  186. if (!$product) return Json::fail('数据不存在');
  187. $product['is_show'] = 0;
  188. $product['uid'] = 0;
  189. $money = $product['hanging_price'] - $product['price'];
  190. $user['now_money'] += $money;
  191. UserBill::income('商品回收', $user['uid'], 'now_money', 'system_add', $money, $user['spread_uid'], $user['now_money'], '商品回收');
  192. $res = $user->save();
  193. $product->save();
  194. if ($res) return Json::success('成功!');
  195. return Json::fail('失败!');
  196. }
  197. return Json::fail('商品没有用户不能回收');
  198. }
  199. }