AuctionOrder.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\admin\model\auction;
  8. use app\admin\model\user\User;
  9. use app\admin\model\user\UserBill;
  10. use crmeb\services\product\Product;
  11. use crmeb\traits\ModelTrait;
  12. use crmeb\basic\BaseModel;
  13. /**
  14. * 预约 Model
  15. * Class WechatNews
  16. * @package app\admin\model\wechat
  17. */
  18. class AuctionOrder extends BaseModel
  19. {
  20. use ModelTrait;
  21. protected $pk = 'id';
  22. protected $name = 'auction_order';
  23. protected $autoWriteTimestamp = true;
  24. public static function list($where)
  25. {
  26. $model = self::where('a.delete_time', 0)
  27. ->alias('a')
  28. ->order('a.id', 'desc')
  29. ->field('a.*, u.account, u.nickname,p.name, p.image')
  30. ->leftJoin('user u', 'a.uid = u.uid')
  31. ->leftJoin('auction_product p', 'a.product_id = p.id');
  32. if (trim($where['store_name']) != '') $model->where('a.id|u.account|u.nickname|a.order_id', 'like', '%'.$where['store_name'].'%');
  33. if (trim($where['auction_id']) != '') $model->where('a.auction_id', $where['auction_id']);
  34. if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
  35. if ($where['page'] && $where['limit']){
  36. $model->page($where['page'], $where['limit']);
  37. }else{
  38. $model->page(20, 1);
  39. }
  40. $data['count'] = $model->count();
  41. $list = $model->select();
  42. $data['data'] = $list;
  43. return $data;
  44. }
  45. /**
  46. * 卖家操作
  47. * @param $id //商品所属人
  48. * @param $price //卖出价格
  49. * @param $product //商品详情
  50. * @return void
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public static function earn($id, $price,$product)
  56. {
  57. $userModel = new User();
  58. $billModel = new UserBill();
  59. $productModel = new AuctionProduct();
  60. $user = $userModel->find($id);
  61. if ($user['spread_uid'] > 0){
  62. $s_price = ($price - $product['price']) * 0.1; // 卖出价格减去购买价格的百分之十 为上级直推奖励
  63. $spread = $userModel->find($user['spread_uid']);
  64. $spread['integral'] = $spread['integral'] + $s_price; //积分增加
  65. $spread->save();
  66. $billModel->save([
  67. 'uid' => $spread['uid'],
  68. 'pm' => 1,
  69. 'title' => '积分增加',
  70. 'category' => 'integral',
  71. 'type' => 'gain',
  72. 'mark' => '直推积分',
  73. 'add_time' => time(),
  74. 'number' => $s_price,
  75. 'balance' => $spread['integral']
  76. ]);
  77. $anticipate = $user['anticipate'];
  78. $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
  79. $user->save();
  80. UserBill::create([
  81. 'uid' => $user['uid'],
  82. 'pm' => 1,
  83. 'title' => '预约卷扣除',
  84. 'category' => 'anticipate',
  85. 'type' => 'reduce_anticipate',
  86. 'mark' => '卖出扣除预约卷',
  87. 'add_time' => time(),
  88. 'number' => $anticipate,
  89. 'balance' => $user['anticipate']
  90. ]);
  91. }
  92. $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
  93. }
  94. /**
  95. * 购买成功退预约卷
  96. * @param $id
  97. * @return void
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\DbException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. */
  102. public static function return($id)
  103. {
  104. $data = self::find($id);
  105. $userModel = new User();
  106. $productModel = new AuctionProduct();
  107. $auctionModel = new Auction();
  108. $bookingModel = new AuctionBooking();
  109. $user = $userModel->find($data['uid']);
  110. if ($user['is_new'] == 1){
  111. if ($user['spread_uid']) {
  112. $spread = $userModel->where('id', $user['spread_uid'])->find();
  113. $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
  114. }
  115. $orderCount =AuctionOrder::where([['uid', '=', $user['uid']], ['status', 3]])->count();
  116. if ($orderCount >= 5){
  117. $user['is_new'] = 0;
  118. }
  119. }
  120. $product = $productModel->where('id', $data['product_id'])->find();
  121. $auction = $auctionModel->where('id', $product['auction_id'])->find();
  122. $booking = $bookingModel->where('auction_id', $auction['id'])->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
  123. if ($booking['status'] > 0){
  124. $booking['status'] = 0;
  125. $booking->save();
  126. $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
  127. $user->save();
  128. UserBill::create([
  129. 'uid' => $user['uid'],
  130. 'pm' => 1,
  131. 'title' => '预约卷退还',
  132. 'category' => 'anticipate',
  133. 'type' => 'add_anticipate',
  134. 'mark' => '退还预约卷',
  135. 'add_time' => time(),
  136. 'number' => $auction['anticipate'],
  137. 'balance' => $user['anticipate']
  138. ]);
  139. }
  140. }
  141. }