AuctionOrder.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 app\models\auction\AuctionProduct;
  11. use crmeb\services\product\Product;
  12. use crmeb\traits\ModelTrait;
  13. use crmeb\basic\BaseModel;
  14. /**
  15. * 预约 Model
  16. * Class WechatNews
  17. * @package app\admin\model\wechat
  18. */
  19. class AuctionOrder extends BaseModel
  20. {
  21. use ModelTrait;
  22. protected $pk = 'id';
  23. protected $name = 'auction_order';
  24. protected $autoWriteTimestamp = true;
  25. public static function list($where)
  26. {
  27. $model = self::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['status']) != '') $model->where('a.status', $where['status']);
  34. if (trim($where['auction_id']) != '') $model->where('a.auction_id', $where['auction_id']);
  35. if (trim($where['data']) != '') $model = self::getModelTime($where, $model, 'a.create_time');
  36. if ($where['page'] && $where['limit']){
  37. $model->page($where['page'], $where['limit']);
  38. }else{
  39. $model->page(20, 1);
  40. }
  41. $data['count'] = $model->count();
  42. $list = $model->select();
  43. $data['data'] = $list;
  44. return $data;
  45. }
  46. /**
  47. * 卖家操作
  48. * @param $id //商品所属人
  49. * @param $price //卖出价格
  50. * @param $product //商品详情
  51. * @return void
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public static function earn($id, $price,$product)
  57. {
  58. $userModel = new \app\models\user\User();
  59. $productModel = new AuctionProduct();
  60. $user = $userModel->find($id);
  61. if ($user['spread_uid'] > 0){
  62. $s_price = number_format(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
  63. $spread = $userModel->find($user['spread_uid']);
  64. $spread['integral'] = $spread['integral'] + $s_price; //积分增加
  65. $spread->save();
  66. \app\models\user\UserBill::income('直推奖励', $spread['uid'], 'anticipate', 'add_anticipate', $s_price, 0, $spread['integral'], '奖励趣豆');
  67. }
  68. // $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
  69. // $user->save();
  70. // UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, $user['anticipate'] ,'卖出扣除预约卷');
  71. $productModel->where('id', $product['id'])->save(['is_show' => 0]); //下架等待挂售
  72. }
  73. /**
  74. * 购买成功退预约卷
  75. * @param $id
  76. * @return void
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. */
  81. public static function return($id)
  82. {
  83. $data = self::find($id);
  84. $userModel = new User();
  85. $productModel = new AuctionProduct();
  86. $auctionModel = new Auction();
  87. $bookingModel = new AuctionBooking();
  88. $user = $userModel->find($data['uid']);
  89. if ($user['is_new'] == 1){
  90. if ($user['spread_uid']) {
  91. $spread = $userModel->where('uid', $user['spread_uid'])->find();
  92. $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
  93. $spread->save();
  94. }
  95. $orderCount =AuctionOrder::where([['uid', '=', $user['uid']], ['status', '=', 3]])->count();
  96. if ($orderCount >= 5){
  97. $user['is_new'] = 0;
  98. }
  99. }
  100. $product = $productModel->where('id', $data['product_id'])->find();
  101. $auction = $auctionModel->where('id', $product['auction_id'])->find();
  102. $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();
  103. if ($booking['status'] > 0){
  104. $booking['status'] = 0;
  105. $booking->save();
  106. $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
  107. $user->save();
  108. UserBill::create([
  109. 'uid' => $user['uid'],
  110. 'pm' => 1,
  111. 'title' => '预约卷退还',
  112. 'category' => 'anticipate',
  113. 'type' => 'add_anticipate',
  114. 'mark' => '退还预约卷',
  115. 'add_time' => time(),
  116. 'number' => $auction['anticipate'],
  117. 'balance' => $user['anticipate']
  118. ]);
  119. }
  120. }
  121. }