AuctionProduct.php 6.1 KB

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