AuctionOrder.php 7.2 KB

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