AuctionOrder.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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['auction_id']) != '') $model->where('a.auction_id', $where['auction_id']);
  33. if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
  34. if ($where['page'] && $where['limit']){
  35. $model->page($where['page'], $where['limit']);
  36. }else{
  37. $model->page(20, 1);
  38. }
  39. $data['count'] = $model->count();
  40. $list = $model->select();
  41. $data['data'] = $list;
  42. return $data;
  43. }
  44. /**
  45. * 卖家操作
  46. * @param $id //商品所属人
  47. * @param $price //卖出价格
  48. * @param $product //商品详情
  49. * @return void
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public static function earn($id, $price,$product)
  55. {
  56. $userModel = new User();
  57. $billModel = new UserBill();
  58. $productModel = new AuctionProduct();
  59. $user = $userModel->find($id);
  60. if ($user['spread_uid'] > 0){
  61. $s_price = ($price - $product['price']) * 0.1; // 卖出价格减去购买价格的百分之十 为上级直推奖励
  62. $spread = $userModel->find($user['spread_uid']);
  63. $spread['integral'] = $spread['integral'] + $s_price; //积分增加
  64. $spread->save();
  65. $billModel->save([
  66. 'uid' => $spread['uid'],
  67. 'pm' => 1,
  68. 'title' => '积分增加',
  69. 'category' => 'integral',
  70. 'type' => 'gain',
  71. 'mark' => '直推积分',
  72. 'add_time' => time(),
  73. 'number' => $s_price,
  74. 'balance' => $spread['integral']
  75. ]);
  76. $anticipate = $user['anticipate'];
  77. $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
  78. $user->save();
  79. UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, '卖出扣除预约卷');
  80. }
  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('id', $user['spread_uid'])->find();
  102. $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
  103. }
  104. $orderCount =AuctionOrder::where([['uid', '=', $user['uid']], ['status', 3]])->count();
  105. if ($orderCount >= 5){
  106. $user['is_new'] = 0;
  107. }
  108. }
  109. $product = $productModel->where('id', $data['product_id'])->find();
  110. $auction = $auctionModel->where('id', $product['auction_id'])->find();
  111. $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();
  112. if ($booking['status'] > 0){
  113. $booking['status'] = 0;
  114. $booking->save();
  115. $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
  116. $user->save();
  117. UserBill::create([
  118. 'uid' => $user['uid'],
  119. 'pm' => 1,
  120. 'title' => '预约卷退还',
  121. 'category' => 'anticipate',
  122. 'type' => 'add_anticipate',
  123. 'mark' => '退还预约卷',
  124. 'add_time' => time(),
  125. 'number' => $auction['anticipate'],
  126. 'balance' => $user['anticipate']
  127. ]);
  128. }
  129. }
  130. }