|
@@ -91,21 +91,24 @@ class Order extends Base
|
|
|
*/
|
|
|
public function create()
|
|
|
{
|
|
|
- $productId = $this->request->post('id', 0);
|
|
|
+ $productId = input('id', 0);
|
|
|
|
|
|
try {
|
|
|
$user_id = $this->auth->id;
|
|
|
|
|
|
// 单个商品
|
|
|
- if ($productId) {
|
|
|
+ /*if ($productId) {*/
|
|
|
+ $number = input('number',1,'intval');
|
|
|
+ $number = intval($number);
|
|
|
$productId = \addons\unishop\extend\Hashids::decodeHex($productId);
|
|
|
$product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
|
|
|
/** 产品基础数据 **/
|
|
|
- $spec = $this->request->post('spec', '');
|
|
|
- $productData[0] = $product->getDataOnCreateOrder($spec);
|
|
|
- } else {
|
|
|
+ $spec = input('spec', '');
|
|
|
+
|
|
|
+ $productData[0] = $product->getDataOnCreateOrder($spec,$number);
|
|
|
+ /* } else {
|
|
|
// 多个商品
|
|
|
- $cart = $this->request->post('cart');
|
|
|
+ $cart = input('cart');
|
|
|
$carts = (new \addons\unishop\model\Cart)
|
|
|
->whereIn('id', $cart)
|
|
|
->with(['product'])
|
|
@@ -116,25 +119,25 @@ class Order extends Base
|
|
|
$productData[] = $cart->product->getDataOnCreateOrder($cart->spec ? $cart->spec : '', $cart->number);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
if (empty($productData) || !$productData) {
|
|
|
$this->error(__('Product not exist'));
|
|
|
}
|
|
|
|
|
|
/** 默认地址 **/
|
|
|
- $address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
|
|
|
+ /*$address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
|
|
|
if ($address) {
|
|
|
$area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
|
|
|
$address = $address->toArray();
|
|
|
$address['province']['name'] = $area[$address['province_id']];
|
|
|
$address['city']['name'] = $area[$address['city_id']];
|
|
|
$address['area']['name'] = $area[$address['area_id']];
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
/** 可用优惠券 **/
|
|
|
- $coupon = CouponModel::all(function ($query) {
|
|
|
+ /*$coupon = CouponModel::all(function ($query) {
|
|
|
$time = time();
|
|
|
$query
|
|
|
->where(['switch' => CouponModel::SWITCH_ON])
|
|
@@ -143,24 +146,41 @@ class Order extends Base
|
|
|
});
|
|
|
if ($coupon) {
|
|
|
$coupon = collection($coupon)->toArray();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
/** 运费数据 **/
|
|
|
- $cityId = $address['city_id'] ? $address['city_id'] : 0;
|
|
|
- $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
|
|
|
+// $cityId = $address['city_id'] ? $address['city_id'] : 0;
|
|
|
+// $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
|
|
|
|
|
|
+ $order_price = '0';
|
|
|
foreach ($productData as &$product) {
|
|
|
$product['image'] = Config::getImagesFullUrl($product['image']);
|
|
|
$product['sales_price'] = round($product['sales_price'], 2);
|
|
|
$product['market_price'] = round($product['market_price'], 2);
|
|
|
+
|
|
|
+ $order_price = bcadd($order_price,$product['total_price'],2);
|
|
|
}
|
|
|
|
|
|
+ $coupon = Db::name('unishop_coupon_user')->alias('cu')
|
|
|
+ ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime'])
|
|
|
+ ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
|
|
|
+ ->where('cu.user_id',$this->auth->id)
|
|
|
+ ->where('cu.status',0)
|
|
|
+ ->where('c.deletetime',NULL)
|
|
|
+ ->where('c.switch',1)
|
|
|
+ ->where('c.starttime','<',time())
|
|
|
+ ->where('c.endtime','>',time())
|
|
|
+ ->where('c.least','>=',$order_price)
|
|
|
+ ->select();
|
|
|
+
|
|
|
$this->success('', [
|
|
|
'product' => $productData,
|
|
|
- 'address' => $address,
|
|
|
+// 'address' => $address,
|
|
|
'coupon' => $coupon,
|
|
|
- 'delivery' => $delivery['list']
|
|
|
+// 'delivery' => $delivery['list']
|
|
|
+ 'order_price' => $order_price,
|
|
|
+ 'total_price' => $order_price
|
|
|
]);
|
|
|
|
|
|
} catch (Exception $e) {
|
|
@@ -190,7 +210,7 @@ class Order extends Base
|
|
|
*/
|
|
|
public function submit()
|
|
|
{
|
|
|
- $data = $this->request->post();
|
|
|
+ $data = input();
|
|
|
try {
|
|
|
$validate = Loader::validate('\\addons\\unishop\\validate\\Order');
|
|
|
if (!$validate->check($data, [], 'submit')) {
|
|
@@ -426,12 +446,12 @@ class Order extends Base
|
|
|
*/
|
|
|
public function comment()
|
|
|
{
|
|
|
- $rate = $this->request->post('rate', 5);
|
|
|
- $anonymous = $this->request->post('anonymous', 0);
|
|
|
- $comment = $this->request->post('comment');
|
|
|
- $order_id = $this->request->post('order_id', 0);
|
|
|
+ $rate = input('rate', 5);
|
|
|
+ $anonymous = input('anonymous', 0);
|
|
|
+ $comment = input('comment');
|
|
|
+ $order_id = input('order_id', 0);
|
|
|
$order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
|
|
|
- $product_id = $this->request->post('product_id');
|
|
|
+ $product_id = input('product_id');
|
|
|
$product_id = \addons\unishop\extend\Hashids::decodeHex($product_id);
|
|
|
|
|
|
$orderProductModel = new \addons\unishop\model\OrderProduct();
|