返回手机号
This commit is contained in:
parent
306d9987a4
commit
fca629fecb
@ -25,6 +25,8 @@ class Dicts extends Repository
|
||||
'bloc_channel' => ['运营商', '中间商'],
|
||||
'package_type' => ['基础套餐', '续费包', '加油包', '可选包', '附加包'],
|
||||
'tables' => ['real' => 'RD', 'virtual' => 'VD'],
|
||||
'order_status' => ['已下单', '已取消', '已出库', '已签收'],
|
||||
'transaction_status' => ['未收款', '已收款'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
|
@ -3,6 +3,7 @@ namespace App\Domains\Company\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exceptions\AuthException;
|
||||
use App\Domains\Sms\Services\SmsService;
|
||||
use App\Domains\Virtual\Services\CompanyAccountService;
|
||||
|
||||
@ -75,12 +76,12 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
if (empty($this->account->mobile)) {
|
||||
return err('用户未绑定手机号');
|
||||
throw new AuthException('用户未绑定手机号', AuthException::NOT_BOUND_MOBILE);
|
||||
}
|
||||
|
||||
$freqsecs = app(SmsService::class)->sendVcode($this->account->mobile, '密码找回');
|
||||
|
||||
return res(['freg' => $freqsecs], '发送成功');
|
||||
return res(['freg' => $freqsecs, 'mobile' => $this->account->mobile], '发送成功');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,13 +25,46 @@ class OrderController extends Controller
|
||||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
public function paginate()
|
||||
public function paginate(Dicts $dicts)
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
|
||||
|
||||
|
||||
$res = $this->orderService->paginate($conditions);
|
||||
|
||||
return res($res, '订单列表', 201);
|
||||
$carrierOperators = $dicts->get('carrier_operator');
|
||||
$payChannels = array_keys($dicts->get('pay_channel'));
|
||||
$orderStatues = $dicts->get('order_status');
|
||||
$transactionStatuses = $dicts->get('transaction_status');
|
||||
|
||||
|
||||
$list = $res->map(function ($item) use ($carrierOperators, $payChannels, $orderStatues, $transactionStatuses) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'sn' => $item->sn,
|
||||
'package_name' => $item->package->name,
|
||||
'pay_channel' => $payChannels[$item->pay_channel],
|
||||
'carrier_operator' => $carrierOperators[$item->package->carrier_operator],
|
||||
'unit_price' => $item->unit_price,
|
||||
'counts' => $item->counts,
|
||||
'total_price' => $item->total_price,
|
||||
'custom_price' => $item->custom_price,
|
||||
'order_status' => $orderStatues[$item->order_status],
|
||||
'transaction_status' => $transactionStatuses[$item->transaction_status],
|
||||
'order_at' => $item->order_at,
|
||||
];
|
||||
});
|
||||
|
||||
if (empty($list)) {
|
||||
return err('没有更多数据');
|
||||
}
|
||||
|
||||
$order_at = $list->last()->order_at;
|
||||
|
||||
$count = $this->orderService->count($conditions);
|
||||
|
||||
return res($list, '订单列表', 201);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,10 +72,11 @@ class OrderController extends Controller
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
$attributes = $this->request->all();
|
||||
$attributes['company_id'] = $this->account->company_id;
|
||||
|
||||
$res = $this->orderService->paginate($conditions);
|
||||
$res = $this->orderService->store($attributes);
|
||||
|
||||
return res($res, '订单列表', 201);
|
||||
return res($res, '下单成功');
|
||||
}
|
||||
}
|
||||
|
@ -26,5 +26,6 @@ $router->group(['prefix' => 'companies', 'as' => 'companies'], function ($router
|
||||
$router->get('/products', ['as' => 'products', 'uses' => 'BootstrapController@products']);
|
||||
|
||||
$router->get('/orders/paginate', ['as' => 'orders/paginate', 'uses' => 'OrderController@paginate']);
|
||||
$router->post('/orders/store', ['as' => 'orders/store', 'uses' => 'OrderController@store']);
|
||||
});
|
||||
});
|
||||
|
@ -47,4 +47,23 @@ class CommonService
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付方式编号
|
||||
*
|
||||
* @param string $payChannel
|
||||
* @return int
|
||||
*/
|
||||
public static function intPayChannel($payChannel)
|
||||
{
|
||||
$payChannels = array_values(app(Dicts::class)->get('pay_channel'));
|
||||
|
||||
foreach ($payChannels as $key => $value) {
|
||||
if (in_array($payChannel, $value)) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return 255;
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,13 @@ use App\Dicts;
|
||||
use App\Core\Service;
|
||||
use App\Models\Virtual\Order;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Exceptions\NotExistException;
|
||||
use App\Exceptions\NotAllowedException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\ProductRepository;
|
||||
|
||||
class OrderService extends Service
|
||||
{
|
||||
@ -39,7 +43,26 @@ class OrderService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储企业定价
|
||||
* 订单计数
|
||||
*
|
||||
* @param array $conditions
|
||||
* @return mixed
|
||||
*/
|
||||
public function count(array $conditions = [])
|
||||
{
|
||||
$select = [
|
||||
DB::raw('COUNT(*) as total_count'),
|
||||
DB::raw('SUM(custom_price) as total_price'),
|
||||
DB::raw('SUM(custom_price*transaction_status) as transacted_price'),
|
||||
];
|
||||
|
||||
$res = $this->orderRepository->select($select)->withConditions($conditions)->get();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下单
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return Order
|
||||
@ -50,6 +73,7 @@ class OrderService extends Service
|
||||
|
||||
$rule = [
|
||||
'company_id' => ['required', 'exists:virtual_companies,id'],
|
||||
'product_id' => ['required'],
|
||||
'counts' => ['required'],
|
||||
'pay_channel' => ['required', Rule::in(array_collapse(app(Dicts::class)->get('pay_channel')))],
|
||||
'contacts' => ['required', 'display_length:2,32'],
|
||||
@ -61,7 +85,10 @@ class OrderService extends Service
|
||||
$message = [
|
||||
'company_id.required' => '请输入企业ID',
|
||||
'company_id.exists' => '企业不存在或已删除',
|
||||
'counts' => '请输入订购数量',
|
||||
'product_id.required' => '请选择套餐',
|
||||
'counts.required' => '请输入订购数量',
|
||||
'pay_channel.required' => '请选择支付方式',
|
||||
'pay_channel.in' => '支付方式不合法',
|
||||
'contacts.required' => '联系人不能为空',
|
||||
'contacts.display_length' => '联系人名称长度不合法',
|
||||
'mobile.required' => '手机号不能为空',
|
||||
@ -72,16 +99,31 @@ class OrderService extends Service
|
||||
|
||||
Validator::validate($attributes, $rule, $message);
|
||||
|
||||
if (!$product = app(ProductRepository::class)->withConditions(['id' => $attributes['product_id']])->first()) {
|
||||
throw new NotExistException('套餐不存在或已删除');
|
||||
}
|
||||
|
||||
if ($product->company_id != $attributes['company_id']) {
|
||||
throw new NotAllowedException('非法操作');
|
||||
}
|
||||
|
||||
$attributes['unit_price'] = $product->base_price;
|
||||
$attributes['total_price'] = $attributes['unit_price'] * $attributes['counts'];
|
||||
$attributes['custom_price'] = $attributes['unit_price'] * $attributes['counts'];
|
||||
$attributes['order_at'] = date('Y-m-d H:i:s');
|
||||
$attributes['pay_channel'] = CommonService::intPayChannel($attributes['pay_channel']);
|
||||
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
|
||||
|
||||
if (!$attributes['id']) {
|
||||
$node = $this->productRepository->create($attributes);
|
||||
$node = $this->orderRepository->create($attributes);
|
||||
}
|
||||
|
||||
if ($attributes['id']) {
|
||||
if (!$node = $this->productRepository->find($attributes['id'])) {
|
||||
throw new NotExistException('地址不存在或已删除');
|
||||
if (!$node = $this->orderRepository->find($attributes['id'])) {
|
||||
throw new NotExistException('订单不存在或已删除');
|
||||
}
|
||||
|
||||
$this->productRepository->setModel($node)->update($attributes);
|
||||
$this->orderRepository->setModel($node)->update($attributes);
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Models\Virtual;
|
||||
|
||||
use App\Core\Model;
|
||||
use App\Models\Real\OrderCard;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
@ -10,6 +11,16 @@ class Order extends Model
|
||||
|
||||
public function cards()
|
||||
{
|
||||
return $this->hasMany(Card::class, 'order_id', 'id');
|
||||
return $this->hasMany(OrderCard::class, 'order_id', 'id');
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTO(Company::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo(Package::class, 'package_id', 'id');
|
||||
}
|
||||
}
|
||||
|
@ -77,33 +77,6 @@ class CreateBaseTables extends Migration
|
||||
|
||||
db_alter("{$prefix}_cards", "{$type}订单企业套餐卡关联表");
|
||||
|
||||
Schema::create("{$prefix}_orders", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('订单ID');
|
||||
$table->string('sn', 32)->comment('订单编号');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业ID");
|
||||
$table->string('transaction_no', 64)->comment('交易流水号');
|
||||
$table->tinyInteger('pay_channel')->unsigned()->default(0)->comment('支付方式(0:银行转账 1:账户余额 2:微信支付 3:支付宝 4:天猫续费)');
|
||||
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->integer('total_price')->unsigned()->default(0)->comment('总价');
|
||||
$table->timestamp('order_at')->nullable()->comment('下单时间');
|
||||
$table->string('address')->default('')->comment('收货地址');
|
||||
$table->string('contact')->default('')->comment('联系人');
|
||||
$table->string('mobile')->default('')->comment('电话');
|
||||
$table->text('logistics_remark')->nullable()->comment('物流备注');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['sn', 'deleted_at']);
|
||||
$table->index('type');
|
||||
$table->index('company_id');
|
||||
$table->index('order_at');
|
||||
});
|
||||
|
||||
db_alter("{$prefix}_orders", "{$type}订单");
|
||||
|
||||
Schema::create("{$prefix}_added_orders", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('订单ID');
|
||||
$table->string('sn', 32)->comment('订单编号');
|
||||
@ -128,6 +101,33 @@ class CreateBaseTables extends Migration
|
||||
db_alter("{$prefix}_orders", "{$type}增值包订单");
|
||||
}
|
||||
|
||||
Schema::create("real_orders", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('订单ID');
|
||||
$table->string('sn', 32)->comment('订单编号');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
|
||||
$table->string('transaction_no', 64)->comment('交易流水号');
|
||||
$table->tinyInteger('pay_channel')->unsigned()->default(0)->comment('支付方式(0:银行转账 1:账户余额 2:微信支付 3:支付宝 4:天猫续费)');
|
||||
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->integer('total_price')->unsigned()->default(0)->comment('总价');
|
||||
$table->timestamp('order_at')->nullable()->comment('下单时间');
|
||||
$table->string('address')->default('')->comment('收货地址');
|
||||
$table->string('contacts')->default('')->comment('联系人');
|
||||
$table->string('mobile')->default('')->comment('电话');
|
||||
$table->text('logistics_remark')->nullable()->comment('物流备注');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['sn', 'deleted_at']);
|
||||
$table->index('type');
|
||||
$table->index('company_id');
|
||||
$table->index('order_at');
|
||||
});
|
||||
|
||||
db_alter("real_orders", "RD订单");
|
||||
|
||||
Schema::create("blocs", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('集团ID');
|
||||
$table->string('sn', 32)->comment('集团编号');
|
||||
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddPackageIdProductIdToVirtualProducts extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table("virtual_orders", function (Blueprint $table) {
|
||||
$table->integer('package_id')->unsigned()->default(0)->after('company_id')->comment('套餐ID');
|
||||
$table->integer('product_id')->unsigned()->default(0)->after('package_id')->comment('定价ID');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table("virtual_orders", function (Blueprint $table) {
|
||||
$table->dropColumn('package_id');
|
||||
$table->dropColumn('product_id');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCustomPriceOrderStatusTransactionStatusToVirtualOrders extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table("virtual_orders", function (Blueprint $table) {
|
||||
$table->integer('custom_price')->unsigned()->default(0)->after('total_price')->comment('自定义总价');
|
||||
$table->tinyInteger('order_status')->unsigned()->default(0)->after('mobile')->comment('订单状态(0:已下单 1:已取消 2:已出库 3:已签收)');
|
||||
$table->tinyInteger('transaction_status')->unsigned()->default(0)->after('order_status')->comment('收款状态(0:未收款 1:已收款)');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$table->dropColumn('custom_price');
|
||||
$table->dropColumn('order_status');
|
||||
$table->dropColumn('transaction_status');
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateVirtualOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create("virtual_orders", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('订单ID');
|
||||
$table->string('sn', 32)->comment('订单编号');
|
||||
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐)');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
|
||||
$table->integer('package_id')->unsigned()->default(0)->after('company_id')->comment('套餐ID');
|
||||
$table->integer('product_id')->unsigned()->default(0)->after('package_id')->comment('定价ID');
|
||||
$table->string('transaction_no', 64)->default('')->comment('交易流水号');
|
||||
$table->tinyInteger('pay_channel')->unsigned()->default(0)->comment('支付方式(0:银行转账 1:账户余额 2:微信支付 3:支付宝 4:天猫续费)');
|
||||
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
|
||||
$table->integer('counts')->unsigned()->default(0)->comment('数量');
|
||||
$table->integer('total_price')->unsigned()->default(0)->comment('总价');
|
||||
$table->integer('custom_price')->unsigned()->default(0)->after('total_price')->comment('自定义总价');
|
||||
$table->timestamp('order_at')->nullable()->comment('下单时间');
|
||||
$table->string('area')->default('')->comment('区域');
|
||||
$table->string('address')->default('')->comment('收货地址');
|
||||
$table->string('contacts')->default('')->comment('联系人');
|
||||
$table->string('mobile')->default('')->comment('电话');
|
||||
$table->tinyInteger('order_status')->unsigned()->default(0)->after('mobile')->comment('订单状态(0:已下单 1:已取消 2:已出库 3:已签收)');
|
||||
$table->tinyInteger('transaction_status')->unsigned()->default(0)->after('order_status')->comment('收款状态(0:未收款 1:已收款)');
|
||||
$table->text('logistics_remark')->nullable()->comment('物流备注');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['sn', 'deleted_at']);
|
||||
$table->index('type');
|
||||
$table->index('company_id');
|
||||
$table->index('order_at');
|
||||
});
|
||||
|
||||
db_alter("virtual_orders", "VD订单");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('virtual_orders');
|
||||
}
|
||||
}
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -16,6 +16,7 @@ return array(
|
||||
'CreateFailedJobsTable' => $baseDir . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
|
||||
'CreateOrderTables' => $baseDir . '/database/migrations/2018_11_27_175146_create_order_tables.php',
|
||||
'CreatePackageTables' => $baseDir . '/database/migrations/2018_11_27_175152_create_package_tables.php',
|
||||
'CreateVirtualOrdersTable' => $baseDir . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php',
|
||||
'DatabaseSeeder' => $baseDir . '/database/seeds/DatabaseSeeder.php',
|
||||
'DivisionByZeroError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
|
||||
'Error' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/Error.php',
|
||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -705,6 +705,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
|
||||
'CreateOrderTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175146_create_order_tables.php',
|
||||
'CreatePackageTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175152_create_package_tables.php',
|
||||
'CreateVirtualOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php',
|
||||
'DatabaseSeeder' => __DIR__ . '/../..' . '/database/seeds/DatabaseSeeder.php',
|
||||
'DivisionByZeroError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
|
||||
'Error' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/Error.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user