AuctionBooking.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. return Json::successlayui($data);
  53. }
  54. public function auction_list()
  55. {
  56. $list = model::select()->toArray();
  57. Json::successful($list);
  58. }
  59. /**
  60. * 显示创建资源表单页.
  61. *
  62. * @return \think\Response
  63. */
  64. public function create($id = 0)
  65. {
  66. $data = \app\admin\model\auction\Auction::select()->toArray();
  67. $this->assign(['id' => $id, 'list' => $data]);
  68. return $this->fetch();
  69. }
  70. /**
  71. * 添加
  72. * @param $id
  73. * @return void
  74. */
  75. public function save($id)
  76. {
  77. $data = Util::postMore([
  78. 'name',
  79. 'is_show',
  80. 'image',
  81. 'price',
  82. 'deduct',
  83. 'rise',
  84. 'info',
  85. 'sort',
  86. 'auction_id'
  87. ]);
  88. $model = new model();
  89. $res = $model->save($data);
  90. if ($res){
  91. return Json::success('添加成功!');
  92. }else{
  93. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  94. }
  95. }
  96. /**
  97. * 删除
  98. * @param $id
  99. * @return void
  100. * @throws \Exception
  101. */
  102. public function delete($id)
  103. {
  104. if (!$id) Json::fail('删除失败');
  105. $res = model::where('id', $id)->delete();
  106. if ($res){
  107. return Json::success('删除成功!');
  108. }else{
  109. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  110. }
  111. }
  112. /**
  113. * 修改状态
  114. * @param $id
  115. * @param $status
  116. * @return void
  117. */
  118. public function set_status($id, $status)
  119. {
  120. if (empty($id)) Json::fail('修改失败');
  121. $res = model::update(['is_show' => $status, 'id' => $id]);
  122. if ($res){
  123. return Json::success('修改成功!');
  124. }else{
  125. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  126. }
  127. }
  128. /**
  129. * 编辑页面
  130. * @param $id
  131. * @return string
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function edit($id)
  137. {
  138. if (!$id) Json::fail('数据不存在');
  139. $data = \app\admin\model\auction\Auction::select()->toArray();
  140. $this->assign(['id' => $id, 'list' => $data]);
  141. return $this->fetch();
  142. }
  143. public function get_list($id)
  144. {
  145. if (!$id) Json::fail('数据不存在');
  146. $model = new model();
  147. $info = $model->find($id);
  148. return JsonService::successful($info);
  149. }
  150. /**
  151. * 修改
  152. * @param $id
  153. * @return void
  154. */
  155. public function update($id)
  156. {
  157. $data = Util::postMore([
  158. 'id',
  159. 'name',
  160. 'is_show',
  161. 'image',
  162. 'price',
  163. 'deduct',
  164. 'rise',
  165. 'info',
  166. 'sort',
  167. 'auction_id'
  168. ]);
  169. $res = model::update($data);
  170. if ($res){
  171. return Json::success('修改成功!');
  172. }else{
  173. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  174. }
  175. }
  176. /**
  177. * 退回预约卷
  178. * @param $id
  179. * @return void
  180. * @throws \think\db\exception\DataNotFoundException
  181. * @throws \think\db\exception\DbException
  182. * @throws \think\db\exception\ModelNotFoundException
  183. */
  184. public function th($id)
  185. {
  186. if (!$id) Json::fail('没有数据');
  187. $data = model::find($id);
  188. if ($data['status'] < 1) Json::fail('已退回请勿重复提交');
  189. $userModel = new User();
  190. $user = $userModel->where('uid', $data['uid'])->find();
  191. if (!$user) Json::fail('没有数据');
  192. $user['anticipate'] = $user['anticipate']+ $data['anticipate'];
  193. $bill = UserBill::create([
  194. 'uid' => $user['uid'],
  195. 'pm' => 1,
  196. 'title' => '预约卷退回',
  197. 'category' => 'anticipate',
  198. 'type' => 'add_anticipate',
  199. 'number' => $data['anticipate'],
  200. 'balance' => $user['anticipate'],
  201. 'mark' => '后台操作退回',
  202. 'add_time' => time(),
  203. ]);
  204. if ($bill){
  205. $res = $user->save();
  206. model::where('id', $id)->update(['status' => 0]);
  207. if ($res){
  208. Json::successful('退回成功');
  209. }else{
  210. Json::fail('退回失败');
  211. }
  212. }else{
  213. Json::fail('错误');
  214. }
  215. }
  216. }