AuctionOrder.php 7.8 KB

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