AuctionBooking.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace app\admin\controller\auction;
  3. use app\admin\controller\AuthController;
  4. use app\admin\controller\Union;
  5. use app\admin\model\user\User;
  6. use app\admin\model\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\AuctionBooking as model;
  20. use think\facade\Route as Url;
  21. /**
  22. * 竞拍管理
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class AuctionBooking extends AuthController
  27. {
  28. public function index()
  29. {
  30. $list = \app\admin\model\auction\Auction::select();
  31. $this->assign([
  32. 'year' => get_month(),
  33. 'auction'=> $list
  34. ]);
  35. return $this->fetch();
  36. }
  37. /**
  38. * 获取列表
  39. * @return void
  40. */
  41. public function list()
  42. {
  43. $where = Util::getMore([
  44. ['is_show', ''],
  45. ['page', 1],
  46. ['limit', 20],
  47. ['auction_id', ''],
  48. ['store_name', ''],
  49. ['data', '']
  50. ]);
  51. $data = model::list($where);
  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. $data = \app\admin\model\auction\Auction::select()->toArray();
  70. $this->assign(['id' => $id, 'list' => $data]);
  71. return $this->fetch();
  72. }
  73. /**
  74. * 添加
  75. * @param $id
  76. * @return void
  77. */
  78. public function save($id)
  79. {
  80. $data = Util::postMore([
  81. 'name',
  82. 'is_show',
  83. 'image',
  84. 'price',
  85. 'deduct',
  86. 'rise',
  87. 'info',
  88. 'sort',
  89. 'auction_id'
  90. ]);
  91. $model = new model();
  92. $res = $model->save($data);
  93. if ($res){
  94. return Json::success('添加成功!');
  95. }else{
  96. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  97. }
  98. }
  99. /**
  100. * 删除
  101. * @param $id
  102. * @return void
  103. * @throws \Exception
  104. */
  105. public function delete($id)
  106. {
  107. if (!$id) Json::fail('删除失败');
  108. $res = model::where('id', $id)->delete();
  109. if ($res){
  110. return Json::success('删除成功!');
  111. }else{
  112. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  113. }
  114. }
  115. /**
  116. * 修改状态
  117. * @param $id
  118. * @param $status
  119. * @return void
  120. */
  121. public function set_status($id, $status)
  122. {
  123. if (empty($id)) 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. /**
  132. * 编辑页面
  133. * @param $id
  134. * @return string
  135. * @throws \think\db\exception\DataNotFoundException
  136. * @throws \think\db\exception\DbException
  137. * @throws \think\db\exception\ModelNotFoundException
  138. */
  139. public function edit($id)
  140. {
  141. if (!$id) Json::fail('数据不存在');
  142. $data = \app\admin\model\auction\Auction::select()->toArray();
  143. $this->assign(['id' => $id, 'list' => $data]);
  144. return $this->fetch();
  145. }
  146. public function get_list($id)
  147. {
  148. if (!$id) Json::fail('数据不存在');
  149. $model = new model();
  150. $info = $model->find($id);
  151. return JsonService::successful($info);
  152. }
  153. /**
  154. * 修改
  155. * @param $id
  156. * @return void
  157. */
  158. public function update($id)
  159. {
  160. $data = Util::postMore([
  161. 'id',
  162. 'name',
  163. 'is_show',
  164. 'image',
  165. 'price',
  166. 'deduct',
  167. 'rise',
  168. 'info',
  169. 'sort',
  170. 'auction_id'
  171. ]);
  172. $res = model::update($data);
  173. if ($res){
  174. return Json::success('修改成功!');
  175. }else{
  176. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  177. }
  178. }
  179. /**
  180. * 退回广告值
  181. * @param $id
  182. * @return void
  183. * @throws \think\db\exception\DataNotFoundException
  184. * @throws \think\db\exception\DbException
  185. * @throws \think\db\exception\ModelNotFoundException
  186. */
  187. public function th($id)
  188. {
  189. if (!$id) Json::fail('没有数据');
  190. $data = model::find($id);
  191. if ($data['status'] < 1) Json::fail('已退回请勿重复提交');
  192. $userModel = new User();
  193. $user = $userModel->where('uid', $data['uid'])->find();
  194. if (!$user) Json::fail('没有数据');
  195. $user['anticipate'] = $user['anticipate']+ $data['anticipate'];
  196. $bill = UserBill::create([
  197. 'uid' => $user['uid'],
  198. 'pm' => 1,
  199. 'title' => '广告值退回',
  200. 'category' => 'anticipate',
  201. 'type' => 'add_anticipate',
  202. 'number' => $data['anticipate'],
  203. 'balance' => $user['anticipate'],
  204. 'mark' => '后台操作退回',
  205. 'add_time' => time(),
  206. ]);
  207. if ($bill){
  208. $res = $user->save();
  209. model::where('id', $id)->update(['status' => 0]);
  210. if ($res){
  211. Json::successful('退回成功');
  212. }else{
  213. Json::fail('退回失败');
  214. }
  215. }else{
  216. Json::fail('错误');
  217. }
  218. }
  219. }