AuctionOrder.php 7.6 KB

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