AuctionOrder.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. ]);
  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 qd($id)
  188. {
  189. if (!$id) return Json::fail('没有数据');
  190. $data = model::find($id);// 订单数据
  191. if($data['status'] < 3 and $data['status'] > 0){
  192. \app\admin\model\auction\AuctionProduct::beginTrans();
  193. $product = \app\admin\model\auction\AuctionProduct::find($data['product_id']);
  194. if (!$product) Json::fail('数据不存在');
  195. $uid = $product['uid']; // 所属人id
  196. $product['uid'] = $data['uid'];// 商品拥有人更新
  197. $res = $product->save();
  198. if ($res){
  199. if ($uid > 0){
  200. model::earn($uid,$data['price'] ,$product); // 卖家
  201. }
  202. model::return($id); // 买家
  203. $data['status'] = 3;
  204. $data->save();
  205. \app\admin\model\auction\AuctionProduct::commitTrans();
  206. // 计算总消费金额
  207. $prices=model::where('uid',$data['uid'])->where('status',3)->sum('price');//历史完成订单
  208. $sum=floatval($prices+$data['price']);
  209. //如果总金额大于等于三万
  210. if($sum>=30000){
  211. $user=User::where('uid',$data['uid'])->find();//获取用户信息
  212. if($user['f_integral']==3000){//如果积分依旧冻结
  213. //释放冻结积分
  214. $integral=floatval($user['integral']+3000);
  215. $res=User::where('uid',$data['uid'])->update(['f_integral' =>0,'integral'=>$integral]);
  216. //积分释放流水
  217. $res3=UserBill::income('冻结积分释放',$data['uid'], 'integral', 'release',3000, $id,$integral, '释放3000积分');
  218. if(!$res3){
  219. return self::setErrorInfo('操作失败');
  220. }
  221. }
  222. }
  223. return Json::successful('审核通过!');
  224. }else{
  225. \app\admin\model\auction\AuctionProduct::rollbackTrans();
  226. return Json::successful('审核失败!');
  227. }
  228. }
  229. return Json::fail('无法通过');
  230. }
  231. }