AuctionOrder.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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::alias('a')
  27. ->order('a.id', 'desc')
  28. ->field('a.*, u.account, u.nickname,p.name, p.image')
  29. ->leftJoin('user u', 'a.uid = u.uid')
  30. ->leftJoin('auction_product p', 'a.product_id = p.id');
  31. if (trim($where['store_name']) != '') $model->where('a.id|u.account|u.nickname|a.order_id', 'like', '%'.$where['store_name'].'%');
  32. if (trim($where['status']) != '') $model->where('a.status', $where['status']);
  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. }
  78. $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
  79. $user->save();
  80. UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, $user['anticipate'] ,'卖出扣除预约卷');
  81. $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
  82. }
  83. /**
  84. * 购买成功退预约卷
  85. * @param $id
  86. * @return void
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\DbException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. */
  91. public static function return($id)
  92. {
  93. $data = self::find($id);
  94. $userModel = new User();
  95. $productModel = new AuctionProduct();
  96. $auctionModel = new Auction();
  97. $bookingModel = new AuctionBooking();
  98. $user = $userModel->find($data['uid']);
  99. if ($user['is_new'] == 1){
  100. if ($user['spread_uid']) {
  101. $spread = $userModel->where('uid', $user['spread_uid'])->find();
  102. $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
  103. $spread->save();
  104. }
  105. $orderCount =AuctionOrder::where([['uid', '=', $user['uid']], ['status', '=', 3]])->count();
  106. if ($orderCount >= 5){
  107. $user['is_new'] = 0;
  108. }
  109. }
  110. $product = $productModel->where('id', $data['product_id'])->find();
  111. $auction = $auctionModel->where('id', $product['auction_id'])->find();
  112. $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->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();
  113. if ($booking['status'] > 0){
  114. $booking['status'] = 0;
  115. $booking->save();
  116. $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
  117. $user->save();
  118. UserBill::create([
  119. 'uid' => $user['uid'],
  120. 'pm' => 1,
  121. 'title' => '预约卷退还',
  122. 'category' => 'anticipate',
  123. 'type' => 'add_anticipate',
  124. 'mark' => '退还预约卷',
  125. 'add_time' => time(),
  126. 'number' => $auction['anticipate'],
  127. 'balance' => $user['anticipate']
  128. ]);
  129. }
  130. }
  131. }