AuctionProduct.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. ['auction_id', ''],
  51. ]);
  52. $data = model::list($where, $id);
  53. foreach ($data['data'] as $key => $val){
  54. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  55. }
  56. return Json::successlayui($data);
  57. }
  58. public function auction_list()
  59. {
  60. $list = model::select()->toArray();
  61. Json::successful($list);
  62. }
  63. /**
  64. * 显示创建资源表单页.
  65. *
  66. * @return \think\Response
  67. */
  68. public function create($id = 0)
  69. {
  70. $this->assign(['id' => $id]);
  71. return $this->fetch();
  72. }
  73. public function save($id)
  74. {
  75. $data = Util::postMore([
  76. 'name',
  77. 'is_show',
  78. 'image',
  79. 'price',
  80. 'info',
  81. 'sort',
  82. 'auction_id',
  83. 'hanging_price',
  84. 'slider_image',
  85. 'description',
  86. 'pl'
  87. ]);
  88. $data['slider_image'] = json_encode($data['slider_image']);
  89. $data['description'] = htmlspecialchars($data['description']);
  90. $model = new model();
  91. if($data['pl']){
  92. for ($x=0; $x<$data['pl']; $x++) {
  93. $res = $model->create($data);
  94. }
  95. }else{
  96. $res = $model->save($data);
  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 edit($id, $auction_id)
  131. {
  132. if (!$id) Json::fail('数据不存在');
  133. $this->assign(['id' => $id, 'auction_id' => $auction_id]);
  134. return $this->fetch();
  135. }
  136. public function get_list($id)
  137. {
  138. if (!$id) Json::fail('数据不存在');
  139. $model = new model();
  140. $info = $model->find($id);
  141. $info['slider_image'] = is_string($info['slider_image']) ? json_decode($info['slider_image'], true) : [];
  142. $info['description'] = htmlspecialchars_decode($info['description']);
  143. $data['productInfo'] = $info;
  144. return JsonService::successful($data);
  145. }
  146. public function update($id)
  147. {
  148. $data = Util::postMore([
  149. 'id',
  150. 'name',
  151. 'image',
  152. 'price',
  153. 'deduct',
  154. 'rise',
  155. 'info',
  156. 'sort',
  157. 'auction_id',
  158. 'hanging_price',
  159. 'slider_image',
  160. 'description'
  161. ]);
  162. $data['slider_image'] = json_encode($data['slider_image']);
  163. $data['description'] = htmlspecialchars($data['description']);
  164. $res = model::update($data);
  165. if ($res){
  166. return Json::success('修改成功!');
  167. }else{
  168. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  169. }
  170. }
  171. /**
  172. * 回收
  173. * @param $id
  174. * @return void
  175. * @throws \think\db\exception\DataNotFoundException
  176. * @throws \think\db\exception\DbException
  177. * @throws \think\db\exception\ModelNotFoundException
  178. */
  179. public function hs($id)
  180. {
  181. $userModel = new User();
  182. $productModel = new \app\admin\model\auction\AuctionProduct();
  183. $product = $productModel->find($id);
  184. if ($product['is_show'] < 1) return Json::fail('当前状态不能回收');
  185. if ($product['uid'] > 0){
  186. $user = $userModel->where('uid', $product['uid'])->find();
  187. if (!$product) return Json::fail('数据不存在');
  188. $product['is_show'] = 0;
  189. $product['uid'] = 0;
  190. $money = $product['hanging_price'] - $product['price'];
  191. $user['now_money'] += $money;
  192. UserBill::income('商品回收', $user['uid'], 'now_money', 'system_add', $money, $user['spread_uid'], $user['now_money'], '商品回收');
  193. $res = $user->save();
  194. $product->save();
  195. if ($res) return Json::success('成功!');
  196. return Json::fail('失败!');
  197. }
  198. return Json::fail('商品没有用户不能回收');
  199. }
  200. }