AuctionOrder.php 7.1 KB

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