123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\models\auction;
- use app\admin\model\system\SystemConfig;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use http\Env\Request;
- use think\facade\Db;
- class AuctionProduct extends BaseModel
- {
- use ModelTrait;
- protected $pk = 'id';
- protected $name = 'auction_product';
- protected $autoWriteTimestamp = true;
-
- public static function user_product($data, $uid){
- $model = self::where('uid', $uid)->order('sort DESC,id DESC');
- $model->page($data['page'], $data['limit']);
- $list = $model->select()->toArray();
- return $list;
- }
- public static function random($id, $uid)
- {
- $auction = Auction::find($id);
- AuctionOrder::startTrans();
- $order = AuctionOrder::where([['auction_id', '=', $id], ['frequency', '=', $auction['frequency']]])->column('product_id');
- $product = self::where('auction_id', $auction['id'])->where('id', 'notIn', $order)->orderRaw('rand()')->limit(1)->find();
- if (empty($product)){
- $config = SystemConfig::where('config_tab_id', 24)->select();
- $data = [
- 'auction_id' => $auction['id']
- ];
- foreach ($config as $v)
- {
- if ($v['menu_name'] == 'product_name') $data['name'] = json_decode($v['value']);
- if ($v['menu_name'] == 'product_image') $data['image'] = json_decode($v['value']);
- if ($v['menu_name'] == 'product_slider_image') $data['slider_image'] = $v['value'];
- if ($v['menu_name'] == 'product_price') $data['price'] = json_decode($v['value']);
- if ($v['menu_name'] == 'product_hanging_price') $data['hanging_price'] = json_decode($v['value']);
- }
- $productSave = AuctionProduct::insertGetId($data);
- $product = self::find($productSave);
-
- $orderData = [
- 'uid' => $uid,
- 'collection_id' => $product['uid'],
- 'order_id' => getNewOrderId(),
- 'auction_id' => $id,
- 'product_id' => $product['id'],
- 'name' => $product['name'],
- 'image' => $product['image'],
- 'price' => $product['hanging_price'],
- 'actual_price' => $product['hanging_price'] - $product['price'],
- 'create_time' => time(),
- 'frequency' => $auction['frequency']
- ];
- $res = AuctionOrder::create($orderData);
- if ($res) {
- AuctionOrder::comimt();
- return $orderData;
- }else{
- AuctionOrder::rollbackTrans();
- return 'false';
- }
- }else{
-
- $orderData = [
- 'uid' => $uid,
- 'collection_id' => $product['uid'],
- 'order_id' => getNewOrderId(),
- 'auction_id' => $id,
- 'product_id' => $product['id'],
- 'name' => $product['name'],
- 'image' => $product['image'],
- 'price' => $product['hanging_price'],
- 'actual_price' => $product['hanging_price'] - $product['price'],
- 'create_time' => time(),
- 'frequency' => $auction['frequency']
- ];
- $res = AuctionOrder::create($orderData);
- if ($res) {
- AuctionOrder::commitTrans();
- return $orderData;
- }else{
- AuctionOrder::rollbackTrans();
- return 'false';
- }
- }
- }
- }
|