AuctionOrder.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. $gu = \app\admin\model\auction\AuctionGu::select();
  32. $this->assign([
  33. 'year' => get_month(),
  34. 'auction'=> $list,
  35. 'gu' => $gu
  36. ]);
  37. return $this->fetch();
  38. }
  39. /**
  40. * 获取列表
  41. * @return void
  42. */
  43. public function list()
  44. {
  45. $where = Util::getMore([
  46. ['is_show', ''],
  47. ['page', 1],
  48. ['limit', 20],
  49. ['auction_id', ''],
  50. ['store_name', ''],
  51. ['data', ''],
  52. ['status', ''],
  53. ['gu_id', ''],
  54. ['product_name'],
  55. ['excel', 0]
  56. ]);
  57. $data = model::list($where);
  58. foreach ($data['data'] as $key => $val){
  59. if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
  60. }
  61. return Json::successlayui($data);
  62. }
  63. public function auction_list()
  64. {
  65. $list = model::select()->toArray();
  66. Json::successful($list);
  67. }
  68. /**
  69. * 显示创建资源表单页.
  70. *
  71. * @return \think\Response
  72. */
  73. public function create($id = 0)
  74. {
  75. $data = \app\admin\model\auction\Auction::select()->toArray();
  76. $this->assign(['id' => $id, 'list' => $data]);
  77. return $this->fetch();
  78. }
  79. /**
  80. * 添加
  81. * @param $id
  82. * @return void
  83. */
  84. public function save($id)
  85. {
  86. $data = Util::postMore([
  87. 'name',
  88. 'is_show',
  89. 'image',
  90. 'price',
  91. 'deduct',
  92. 'rise',
  93. 'info',
  94. 'sort',
  95. 'auction_id'
  96. ]);
  97. $model = new model();
  98. $res = $model->save($data);
  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) 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. /**
  122. * 修改状态
  123. * @param $id
  124. * @param $status
  125. * @return void
  126. */
  127. public function set_status($id, $status)
  128. {
  129. if (empty($id)) Json::fail('修改失败');
  130. $res = model::update(['is_show' => $status, 'id' => $id]);
  131. if ($res){
  132. return Json::success('修改成功!');
  133. }else{
  134. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  135. }
  136. }
  137. /**
  138. * 编辑页面
  139. * @param $id
  140. * @return string
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\DbException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. */
  145. public function edit($id)
  146. {
  147. if (!$id) Json::fail('数据不存在');
  148. $data = \app\admin\model\auction\Auction::select()->toArray();
  149. $this->assign(['id' => $id, 'list' => $data]);
  150. return $this->fetch();
  151. }
  152. public function get_list($id)
  153. {
  154. if (!$id) Json::fail('数据不存在');
  155. $model = new model();
  156. $info = $model->find($id);
  157. return JsonService::successful($info);
  158. }
  159. /**
  160. * 修改
  161. * @param $id
  162. * @return void
  163. */
  164. public function update($id)
  165. {
  166. $data = Util::postMore([
  167. 'id',
  168. 'name',
  169. 'is_show',
  170. 'image',
  171. 'price',
  172. 'deduct',
  173. 'rise',
  174. 'info',
  175. 'sort',
  176. 'auction_id'
  177. ]);
  178. $res = model::update($data);
  179. if ($res){
  180. return Json::success('修改成功!');
  181. }else{
  182. return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
  183. }
  184. }
  185. /**
  186. * 通过
  187. * @param $id
  188. * @return void
  189. * @throws \think\db\exception\DataNotFoundException
  190. * @throws \think\db\exception\DbException
  191. * @throws \think\db\exception\ModelNotFoundException
  192. */
  193. public function qd($id)
  194. {
  195. if (!$id) return Json::fail('没有数据');
  196. $data = model::find($id);// 订单数据
  197. if($data['status'] < 3 and $data['status'] > 0){
  198. \app\admin\model\auction\AuctionProduct::beginTrans();
  199. $product = \app\admin\model\auction\AuctionProduct::find($data['product_id']);
  200. if (!$product)return Json::fail('数据不存在');
  201. $uid = $product['uid']; // 所属人id
  202. $product['uid'] = $data['uid'];// 商品拥有人更新
  203. $product['add_time'] = time();
  204. $product['order'] = $data['order_id'];
  205. $res = $product->save();
  206. if ($res){
  207. if ($uid > 0){
  208. model::earn($uid,$data['price'] ,$product); // 卖家
  209. }
  210. model::return($id); // 买家
  211. $data['status'] = 3;
  212. $data->save();
  213. \app\admin\model\auction\AuctionProduct::commitTrans();
  214. // 计算总消费金额
  215. $prices=model::where('uid',$data['uid'])->where('status',3)->sum('price');//历史完成订单
  216. $sum=floatval($prices+$data['price']);
  217. //如果总金额大于等于三万
  218. if($sum>=30000){
  219. $user=User::where('uid',$data['uid'])->find();//获取用户信息
  220. if($user['f_integral']==3000){//如果积分依旧冻结
  221. //释放冻结积分
  222. $integral=floatval($user['integral']+3000);
  223. $res=User::where('uid',$data['uid'])->update(['f_integral' =>0,'integral'=>$integral]);
  224. //积分释放流水
  225. $res3=UserBill::income('冻结积分释放',$data['uid'], 'integral', 'release',3000, $id,$integral, '释放3000积分');
  226. if(!$res3){
  227. return self::setErrorInfo('操作失败');
  228. }
  229. }
  230. }
  231. return Json::successful('审核通过!');
  232. }else{
  233. \app\admin\model\auction\AuctionProduct::rollbackTrans();
  234. return Json::successful('审核失败!');
  235. }
  236. }
  237. return Json::fail('已通过订单');
  238. }
  239. }