laravel以完全相同的创建时间创建了两行

时间:2018-09-07 15:12:59

标签: laravel eloquent

我使用Laravel创建了一个应用程序,该应用程序具有一个order表,每个用户可以根据请求在该表中插入一行。我在该表中发现两行在同一时间具有完全相同的created_,并且它们是由同一用户创建的。他如何才能在一个请求中插入两行?有人可以给我有关该问题的提示吗?谢谢!

我有2个表,一个表是order,另一个表是mt_order,属于命令(原键是order_id)

代码如下:

    $orderData['consecutive_count'] = $count =  $user->getLatestConsecutiveCounts();
    $orderData['rate'] = $user->getRate($count);

    $orderData['lot'] = $orderData['base_lot'] * $orderData['rate'];//总手数
    $order = $user->orders()->create($orderData);

$group = $user->group;

    if($group->copy_type == 0)
    {
        if($type == 'buy')
        {
            $orderData['direct'] = 'sell';
        }
        else
        {
            $orderData['direct'] = 'buy';
        }
    }


    $mtorder = $order->mtorder()->create($orderData);
    $order->mt_order = $mtorder;

    return
    [
        'status' => true,
        'data' => $order,
    ];

我有一个orderCreated事件,但似乎它什么也不做,它没有监听器。

public $order;
    public function __construct(Order $order)
    {
        if($order->user->group->copy_type == 1)
        {
            $type = $order->direct;
        }
        else
        {
            $type = $order->direct == 'long' ? 'short' :'long';
        }

        $data = [
            'type' => 'exec', 
            'data' =>[
                'laravel_id' => $order->id,
                'MT_order_type' => $type, //多、空
                'MT_open_price' => $order->open_price,
                'MT_open_time' => $order->open_time,
                'MT_take_profit' => $order->take_profit,//(int)
                'MT_stop_loss' => $order->stop_loss,//int
            ],
        ];
        $this->order = $data;
    }

我用这样的ajax触发请求

$(".buy-sell a").on('click', function(){
        let url = $(this).data('url');
        bootbox.confirm({
          message:'want to make order?',
          buttons: {
              confirm: {
                  label: 'confirm',
                  className: 'btn-success'
              },
              cancel: {
                  label: 'cancel',
                  className: 'btn-danger'
              }
         },
         callback:function(result){
          if(result == true){
                $.ajax({
                    url:url,
                    type:'post',
                    success:function(data)
                    {
                        if(data.status)
                        {
                            let direct = data.data.direct == 1? '买入' :'卖出';
                            let str = '<ul class="list-inline" style="padding:10px"><li style="font-size:20px; color:#B7B7B7; width:100px">类型</li><li class="position-value">'+direct+'</li></ul> <ul class="list-inline" style="padding:10px"><li style="font-size:20px; color:#B7B7B7; width:100px">入场价格</li><li class="position-value" id="open_price">获取钟</li></ul><ul class="list-inline" style="padding:10px"><li style="font-size:20px; color:#B7B7B7; width:100px">入场时间</li><li class="position-value" id="open_time">获取中</li></ul>';

                            $("#current_position").empty().append(str);
                            $("#notes").remove();
                            view3.clear()
                            initData(0)
                        }
                        else
                        {
                            alert(data.message);
                        }
                    },
                    complete:function(xhr, text)
                    {
                        if(xhr.status == 429)
                        {
                            alert('request too times');
                        }
                    }
                });
         }

       }
    });
});

0 个答案:

没有答案