admin/addon/cashier/storeapi/controller/Cashierordercreate.php

244 lines
9.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.cdcloudshop.com
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
* =========================================================
*/
namespace addon\cashier\storeapi\controller;
use addon\cashier\model\order\CashierOrderCreate as CashierOrderCreateModel;
use app\storeapi\controller\BaseStoreApi;
class Cashierordercreate extends BaseStoreApi
{
/**
* 商品计算
* @return false|string
*/
public function calculate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id,
'mobile' => $this->params[ 'mobile' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'goods',
'source' => $this->params[ 'source' ] ?? '',// is_buy 普通购买 cart 购物车 参与活动,
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->calculate($data);
return $this->response($res);
}
public function payment()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//[{"sku_id":1,"num":1,"card":1},{"card_id":2,"time":1}}},{"sku_id":2,"num":1}]
'order_id' => $order_id,
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'goods',
'source' => $this->params[ 'source' ] ?? '',// is_buy 普通购买 cart 购物车 参与活动,
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->orderPayment($data);
return $this->response($res);
}
/**
* 创建 收银单据
*/
public function create()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_id = $this->params[ 'order_id' ] ?? 0;
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//{{'sku_id':1, 'num':2, 'card_id':1}, {'money':20}}}
'order_id' => $order_id,
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'goods',
'source' => $this->params[ 'source' ] ?? '',// is_buy 普通购买 cart 购物车 参与活动,
'remark' => $this->params[ 'remark' ] ?? '',
'operator' => $this->user_info,//操作人员,
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->create($data);
return $this->response($res);
}
/**
* 会员卡订单
* @return false|string
*/
public function levelCreate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//{{'member_level_id':10, 'spec':'month'}}
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'remark' => $this->params[ 'remark' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'level',
'cashier_type' => 'cashier'
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->create($data);
return $this->response($res);
}
/**
* 充值订单
* @return false|string
*/
public function rechargeCreate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//[{'recharge_id':10}, {'money':20}]
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'remark' => $this->params[ 'remark' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'recharge',
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填充值参数'));
}
$res = $order_create_model->create($data);
return $this->response($res);
}
/**
* 卡项订单
* @return false|string
*/
public function cardCreate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],//{{'member_card_id':10}}
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->store_id ?? 0,
'remark' => $this->params[ 'remark' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'card',
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->create($data);
return $this->response($res);
}
/**
* 卡项订单计算
* @return false|string
*/
public function cardCalculate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create_model = new CashierOrderCreateModel();
$data = [
'site_id' => $this->site_id,//站点id
'sku_array' => !empty($this->params[ 'sku_array' ]) ? json_decode($this->params[ 'sku_array' ], true) : [],
'member_id' => $this->params[ 'member_id' ] ?? 0,//购买会员(可有可无)
'store_id' => $this->params[ 'store_id' ] ?? 0,
'mobile' => $this->params[ 'mobile' ] ?? '',
'order_from' => $this->params[ 'app_type' ],
'order_from_name' => $this->params[ 'app_type_name' ],
'type' => 'card',
'cashier_type' => 'cashier',
'create_time' => $this->params[ 'create_time' ] ?? 0,
];
if (empty($data[ 'sku_array' ])) {
return $this->response($this->error('', '缺少必填参数商品数据'));
}
$res = $order_create_model->calculate($data);
return $this->response($res);
}
}