AuctionOrder.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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\AuctionOrder as model;
  20. use think\facade\Route as Url;
  21. /**
  22. * 竞拍管理
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class AuctionOrder 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. ['status', '']
  51. ]);
  52. $data = model::list($where);
  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. $data = \app\admin\model\auction\Auction::select()->toArray();
  71. $this->assign(['id' => $id, 'list' => $data]);
  72. return $this->fetch();
  73. }
  74. /**
  75. * 添加
  76. * @param $id
  77. * @return void
  78. */
  79. public function save($id)
  80. {
  81. $data = Util::postMore([
  82. 'name',
  83. 'is_show',
  84. 'image',
  85. 'price',
  86. 'deduct',
  87. 'rise',
  88. 'info',
  89. 'sort',
  90. 'auction_id'
  91. ]);
  92. $model = new model();
  93. $res = $model->save($data);
  94. if ($res){
  95. return Json::success('添加成功!');
  96. }else{
  97. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  98. }
  99. }
  100. /**
  101. * 删除
  102. * @param $id
  103. * @return void
  104. * @throws \Exception
  105. */
  106. public function delete($id)
  107. {
  108. if (!$id) Json::fail('删除失败');
  109. $res = model::where('id', $id)->delete();
  110. if ($res){
  111. return Json::success('删除成功!');
  112. }else{
  113. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  114. }
  115. }
  116. /**
  117. * 修改状态
  118. * @param $id
  119. * @param $status
  120. * @return void
  121. */
  122. public function set_status($id, $status)
  123. {
  124. if (empty($id)) Json::fail('修改失败');
  125. $res = model::update(['is_show' => $status, 'id' => $id]);
  126. if ($res){
  127. return Json::success('修改成功!');
  128. }else{
  129. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  130. }
  131. }
  132. /**
  133. * 编辑页面
  134. * @param $id
  135. * @return string
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\DbException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. */
  140. public function edit($id)
  141. {
  142. if (!$id) Json::fail('数据不存在');
  143. $data = \app\admin\model\auction\Auction::select()->toArray();
  144. $this->assign(['id' => $id, 'list' => $data]);
  145. return $this->fetch();
  146. }
  147. public function get_list($id)
  148. {
  149. if (!$id) Json::fail('数据不存在');
  150. $model = new model();
  151. $info = $model->find($id);
  152. return JsonService::successful($info);
  153. }
  154. /**
  155. * 修改
  156. * @param $id
  157. * @return void
  158. */
  159. public function update($id)
  160. {
  161. $data = Util::postMore([
  162. 'id',
  163. 'name',
  164. 'is_show',
  165. 'image',
  166. 'price',
  167. 'deduct',
  168. 'rise',
  169. 'info',
  170. 'sort',
  171. 'auction_id'
  172. ]);
  173. $res = model::update($data);
  174. if ($res){
  175. return Json::success('修改成功!');
  176. }else{
  177. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  178. }
  179. }
  180. /**
  181. * 通过
  182. * @param $id
  183. * @return void
  184. * @throws \think\db\exception\DataNotFoundException
  185. * @throws \think\db\exception\DbException
  186. * @throws \think\db\exception\ModelNotFoundException
  187. */
  188. public function qd($id)
  189. {
  190. if (!$id) return Json::fail('没有数据');
  191. $data = model::find($id);// 订单数据
  192. if($data['status'] < 3 and $data['status'] > 0){
  193. \app\admin\model\auction\AuctionProduct::beginTrans();
  194. $product = \app\admin\model\auction\AuctionProduct::find($data['product_id']);
  195. if (!$product) Json::fail('数据不存在');
  196. $uid = $product['uid']; // 所属人id
  197. $product['uid'] = $data['uid'];// 商品拥有人更新
  198. $res = $product->save();
  199. if ($res){
  200. if ($uid > 0){
  201. model::earn($uid,$data['price'] ,$product); // 卖家
  202. }
  203. model::return($id); // 买家
  204. $data['status'] = 3;
  205. $data->save();
  206. \app\admin\model\auction\AuctionProduct::commitTrans();
  207. // 计算总消费金额
  208. $prices=model::where('uid',$data['uid'])->where('status',3)->sum('price');//历史完成订单
  209. $sum=floatval($prices+$data['price']);
  210. //如果总金额大于等于三万
  211. if($sum>=30000){
  212. $user=User::where('uid',$data['uid'])->find();//获取用户信息
  213. if($user['f_integral']==3000){//如果积分依旧冻结
  214. //释放冻结积分
  215. $integral=floatval($user['integral']+3000);
  216. $res=User::where('uid',$data['uid'])->update(['f_integral' =>0,'integral'=>$integral]);
  217. //积分释放流水
  218. $res3=UserBill::income('冻结积分释放',$data['uid'], 'integral', 'release',3000, $id,$integral, '释放3000积分');
  219. if(!$res3){
  220. return self::setErrorInfo('操作失败');
  221. }
  222. }
  223. }
  224. return Json::successful('审核通过!');
  225. }else{
  226. \app\admin\model\auction\AuctionProduct::rollbackTrans();
  227. return Json::successful('审核失败!');
  228. }
  229. }
  230. return Json::fail('已通过订单');
  231. }
  232. }