AuctionOrder.php 7.0 KB

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