|
|
@@ -10,10 +10,12 @@ |
|
|
|
namespace addons\unishop\controller; |
|
|
|
|
|
|
|
use addons\unishop\extend\Hashids; |
|
|
|
use addons\unishop\extend\Snowflake; |
|
|
|
use addons\unishop\model\Area; |
|
|
|
use addons\unishop\model\Config; |
|
|
|
use addons\unishop\model\Evaluate; |
|
|
|
use addons\unishop\model\Product; |
|
|
|
use app\admin\model\OrderLog; |
|
|
|
use app\admin\model\unishop\Coupon as CouponModel; |
|
|
|
use addons\unishop\model\DeliveryRule as DeliveryRuleModel; |
|
|
|
use addons\unishop\model\OrderRefund; |
|
|
@@ -38,7 +40,7 @@ class Order extends Base |
|
|
|
*/ |
|
|
|
protected $frequently = ['getorders']; |
|
|
|
|
|
|
|
protected $noNeedLogin = ['count']; |
|
|
|
protected $noNeedLogin = ['count','create','submit','submitbar']; |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建订单 |
|
|
@@ -48,7 +50,8 @@ class Order extends Base |
|
|
|
$productId = $this->request->post('id', 0); |
|
|
|
|
|
|
|
try { |
|
|
|
$user_id = $this->auth->id; |
|
|
|
// $user_id = $this->auth->id; |
|
|
|
$user_id = 1; |
|
|
|
|
|
|
|
// 单个商品 |
|
|
|
if ($productId) { |
|
|
@@ -128,11 +131,45 @@ class Order extends Base |
|
|
|
public function submit() |
|
|
|
{ |
|
|
|
$data = $this->request->post(); |
|
|
|
$order = new \addons\unishop\model\Order(); |
|
|
|
$out_trade_no = date('Ymd',time()).uniqid()."1"; |
|
|
|
$snowflake = new Snowflake(); |
|
|
|
$id = $snowflake->id(); |
|
|
|
$productId = \addons\unishop\extend\Hashids::decodeHex($data["product_id"]); |
|
|
|
$products = Db::name('unishop_product') |
|
|
|
->where(['id' =>$productId , 'switch' => Product::SWITCH_ON]) |
|
|
|
->find(); |
|
|
|
|
|
|
|
$specs = explode(',', $data['spec']); |
|
|
|
foreach ($specs as &$spec) { |
|
|
|
$spec = str_replace('|', ',', $spec); |
|
|
|
} |
|
|
|
$productInfo = (new \addons\unishop\extend\Product())->getBaseData($products, $specs[0] ? $specs[0] : ''); |
|
|
|
$price = $productInfo["sales_price"]*$data["number"]; |
|
|
|
$order->save([ |
|
|
|
'id' => $id, |
|
|
|
// 'user_id' => $userId, |
|
|
|
'out_trade_no' => $out_trade_no, |
|
|
|
'order_price' => $price, |
|
|
|
'total_price' => $price, |
|
|
|
'ip' => $_SERVER['REMOTE_ADDR'] ?? '', |
|
|
|
'remark' => $data['remark'] ?? '', |
|
|
|
'status' => $order::STATUS_NORMAL, |
|
|
|
'product_id'=>$productId, |
|
|
|
'name'=>$data["name"], |
|
|
|
'mobile'=>$data["mobile"], |
|
|
|
'address'=>$data["address"], |
|
|
|
"spec"=>$data["spec"], |
|
|
|
"number"=>$data["number"], |
|
|
|
]); |
|
|
|
$this->success('', []); |
|
|
|
return ; |
|
|
|
|
|
|
|
try { |
|
|
|
$validate = Loader::validate('\\addons\\unishop\\validate\\Order'); |
|
|
|
if (!$validate->check($data, [], 'submit')) { |
|
|
|
throw new Exception($validate->getError()); |
|
|
|
} |
|
|
|
// $validate = Loader::validate('\\addons\\unishop\\validate\\Order'); |
|
|
|
// if (!$validate->check($data, [], 'submit')) { |
|
|
|
// throw new Exception($validate->getError()); |
|
|
|
// } |
|
|
|
|
|
|
|
Db::startTrans(); |
|
|
|
|
|
|
@@ -146,7 +183,7 @@ class Order extends Base |
|
|
|
} |
|
|
|
|
|
|
|
$orderModel = new \addons\unishop\model\Order(); |
|
|
|
$result = $orderModel->createOrder($this->auth->id, $data); |
|
|
|
$result = $orderModel->createOrder(1, $data); |
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
|
|
|
@@ -625,4 +662,13 @@ class Order extends Base |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function submitbar(){ |
|
|
|
$data=json_encode($_POST); |
|
|
|
$now=date("Y-m-d H:i:s"); |
|
|
|
$order_log= new OrderLog(); |
|
|
|
$order_log->data=$data; |
|
|
|
$order_log->time=$now; |
|
|
|
$order_log->save(); |
|
|
|
} |
|
|
|
|
|
|
|
} |