订单添加

parent 64fa34fc
...@@ -8,6 +8,7 @@ use App\Models\Inquiry; ...@@ -8,6 +8,7 @@ use App\Models\Inquiry;
use App\Models\InquiryItems; use App\Models\InquiryItems;
use App\Models\InquiryItemsModel; use App\Models\InquiryItemsModel;
use App\Models\InquiryModel; use App\Models\InquiryModel;
use App\Models\UserModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use App\Models\CartModel; use App\Models\CartModel;
...@@ -19,6 +20,9 @@ class OrderService ...@@ -19,6 +20,9 @@ class OrderService
public static function addOrder($data, $user_id) public static function addOrder($data, $user_id)
{ {
$vs = json_decode(\Arr::get($data, 'items', []),true); $vs = json_decode(\Arr::get($data, 'items', []),true);
//查询用户详情
$userInfo = UserModel::getUserInfo($user_id);
try{ try{
$con = DB::connection(); $con = DB::connection();
$redis = Redis::connection(); $redis = Redis::connection();
...@@ -28,7 +32,14 @@ class OrderService ...@@ -28,7 +32,14 @@ class OrderService
#订单主表 #订单主表
$mainData =[ $mainData =[
"order_sn"=>11, "order_sn"=>11,
""=>"", "sem_order"=>self::createOrderSn(),
"user_id"=>$user_id,
"company_name"=>$userInfo["company_name"],
"exchange_rate"=>getRate(),
"currency"=>2,
"order_remark"=>data_get($data,"order_remark"),
"create_time"=>time(),
"update_time"=>time(),
]; ];
$order_id = OrderModel::insertGetId($mainData); $order_id = OrderModel::insertGetId($mainData);
...@@ -94,7 +105,17 @@ class OrderService ...@@ -94,7 +105,17 @@ class OrderService
} }
} }
//刷新购物车并且返回列表 //生成订单单号
public static function createOrderSn($pre = "SE"){
$order_sn = $pre.date("Y-m-d").rand(1000,9999);
$check = OrderModel::getOrderInfo(["order_sn"=>$order_sn]);
if ($check){
self::createOrderSn();
}
return $order_sn;
}
//订单列表
public static function orderLists($user_id){ public static function orderLists($user_id){
//当前用户所有可用的购物车数据 //当前用户所有可用的购物车数据
......
...@@ -37,6 +37,12 @@ class OrderModel extends Model ...@@ -37,6 +37,12 @@ class OrderModel extends Model
self::status_complete => "Transaction Complete", self::status_complete => "Transaction Complete",
]; ];
//获取订单详情
public static function getOrderInfo($where)
{
$res = self::where($where)->first();
return ($res) ? $res->toArray() : [];
}
......
...@@ -53,4 +53,14 @@ class UserModel extends Authenticatable implements MustVerifyEmail ...@@ -53,4 +53,14 @@ class UserModel extends Authenticatable implements MustVerifyEmail
'password' => Hash::make($data['password']), 'password' => Hash::make($data['password']),
]); ]);
} }
//获取用户详情
public static function getUserInfo($user_id)
{
$map = [
"id" => $user_id
];
$res = self::where($map)->first();
return ($res) ? $res->toArray() : [];
}
} }
<?php <?php
use Illuminate\Support\Facades\Redis;
function test_helper() function test_helper()
{ {
return 'OK'; return 'OK';
...@@ -98,3 +100,12 @@ function getMaxBuyStock($stock,$multiple,$ladder_price){ ...@@ -98,3 +100,12 @@ function getMaxBuyStock($stock,$multiple,$ladder_price){
} }
return $max_buy_stock; return $max_buy_stock;
} }
/*
* 获取汇率,兑换人民币汇率
*/
public function getRate($k = "美元")
{
$redis = Redis::connection();
return $redis->hget('erp_rate', $k);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment