AuctionOrder.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\models\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. /**
  25. * 用户订单
  26. * @param $data
  27. * @param $uid
  28. * @return \think\Collection
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public static function userOrder($data,$uid)
  34. {
  35. if ($data['type'] == 1){
  36. $list = self::where([['uid', '=', $uid], ['status', '=', 1]])->select()->toArray(); //待上传订单
  37. }else if($data['type'] == 2){
  38. $list = self::where([['uid', '=', $uid], ['status', '=', 2]])->select()->toArray(); //待审核订单
  39. }else if($data['type'] == 3) {
  40. $list = self::where([['uid', '=', $uid], ['status', '=', 3]])->select()->toArray(); //完成订单
  41. }else{
  42. $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->select()->toArray(); //过期订单
  43. }
  44. return $list;
  45. }
  46. /**
  47. * 卖家订单
  48. * @param $data
  49. * @param $uid
  50. * @return \think\Collection
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public static function seller_list($data,$uid)
  56. {
  57. if ($data['type'] == 1){
  58. $list = self::where([['collection_id', '=', $uid], ['status', '=', 1]])->select()->toArray(); //待上传订单
  59. }else if($data['type'] == 2){
  60. $list = self::where([['collection_id', '=', $uid], ['status', '=', 2]])->select()->toArray(); //待审核订单
  61. }else if($data['type'] == 3) {
  62. $list = self::where([['collection_id', '=', $uid], ['status', '=', 3]])->select()->toArray(); //完成订单
  63. }else{
  64. $list = self::where([['collection_id', '=', $uid], ['status', '<', 1]])->select()->toArray(); //过期订单
  65. }
  66. return $list;
  67. }
  68. /**
  69. * 卖家操作
  70. * @param $id //商品所属人
  71. * @param $price //卖出价格
  72. * @param $product //商品详情
  73. * @return void
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public static function earn($id, $price,$product)
  79. {
  80. $userModel = new \app\models\user\User();
  81. $productModel = new AuctionProduct();
  82. $user = $userModel->find($id);
  83. if ($user['spread_uid'] > 0){
  84. $s_price = number_format(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
  85. $spread = $userModel->find($user['spread_uid']);
  86. $spread['integral'] = $spread['integral'] + $s_price; //积分增加
  87. $spread->save();
  88. \app\models\user\UserBill::create([
  89. 'uid' => $spread['uid'],
  90. 'link_id' => $id,
  91. 'pm' => 1,
  92. 'title' => '积分增加',
  93. 'category' => 'integral',
  94. 'type' => 'gain',
  95. 'mark' => '卖出商品直推'.$s_price.'积分',
  96. 'add_time' => time(),
  97. 'number' => $s_price,
  98. 'balance' => $spread['integral']
  99. ]);
  100. $user['anticipate'] = $user['anticipate']-number_format($price*($product['deduct']/100),2); // 扣除当前卖出价格百分比的预约卷
  101. $user->save();
  102. \app\models\user\UserBill::create([
  103. 'uid' => $user['uid'],
  104. 'pm' => 0,
  105. 'title' => '预约卷扣除',
  106. 'category' => 'anticipate',
  107. 'type' => 'reduce_anticipate',
  108. 'mark' => '卖出商品扣除'.number_format($price*($product['deduct']/100), 2).'预约卷',
  109. 'add_time' => time(),
  110. 'number' => number_format($price*($product['deduct']/100),2),
  111. 'balance' => $user['anticipate']
  112. ]);
  113. }
  114. $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
  115. }
  116. /**
  117. * 购买成功退预约卷
  118. * @param $id
  119. * @return void
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\DbException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. */
  124. public static function return($id)
  125. {
  126. $data = self::find($id);
  127. $userModel = new User();
  128. $productModel = new AuctionProduct();
  129. $auctionModel = new Auction();
  130. $bookingModel = new AuctionBooking();
  131. $user = $userModel->find($data['uid']);
  132. if ($user['is_new'] == 1){
  133. if ($user['spread_uid']) {
  134. $spread = $userModel->where('id', $user['spread_uid'])->find();
  135. $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
  136. }
  137. $orderCount = AuctionOrder::where([['uid', '=', $user['uid']], ['status', 3]])->count();
  138. if ($orderCount >= 5){
  139. $user['is_new'] = 0;
  140. }
  141. }
  142. $product = $productModel->where('id', $data['product_id'])->find();
  143. $auction = $auctionModel->where('id', $product['auction_id'])->find();
  144. $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();
  145. if ($booking['status'] > 0){
  146. $booking['status'] = 0;
  147. $booking->save();
  148. $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
  149. $user->save();
  150. \app\models\user\UserBill::create([
  151. 'uid' => $user['uid'],
  152. 'pm' => 1,
  153. 'title' => '预约卷退还',
  154. 'category' => 'anticipate',
  155. 'type' => 'add_anticipate',
  156. 'mark' => '退还预约场馆'.number_format($auction['anticipate'],2).'预约卷',
  157. 'add_time' => time(),
  158. 'number' => number_format($auction['anticipate'],2),
  159. 'balance' => $user['anticipate']
  160. ]);
  161. }
  162. }
  163. }