From cf4d708d57a8e8bd6fd2c822d4ce946664dcd1af Mon Sep 17 00:00:00 2001 From: denghy Date: Tue, 26 Feb 2019 21:36:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/FetchController.php | 7 +- .../Http/Controllers/OrderController.php | 14 ++ .../Repositories/ProductRepository.php | 8 ++ app/Domains/Virtual/Services/OrderService.php | 27 +++- .../Virtual/Services/PackageService.php | 2 +- .../Virtual/Services/ProductService.php | 28 ++++ app/Models/Virtual/Order.php | 28 ++++ frontend/package.json | 1 + frontend/src/assets/css/common.less | 1 - frontend/src/main.js | 3 +- .../src/views/virtual/flow_pools/detail.vue | 2 +- .../src/views/virtual/flow_pools/flows.vue | 32 +++-- frontend/src/views/virtual/orders/edit.vue | 129 ++++++++++++------ frontend/src/views/virtual/orders/index.vue | 57 ++++++-- frontend/src/views/virtual/orders/js/edit.js | 101 ++++++++++++-- frontend/src/views/virtual/orders/js/index.js | 2 + 16 files changed, 347 insertions(+), 95 deletions(-) diff --git a/app/Domains/Virtual/Http/Controllers/FetchController.php b/app/Domains/Virtual/Http/Controllers/FetchController.php index 961eb9f6..e74b06cf 100644 --- a/app/Domains/Virtual/Http/Controllers/FetchController.php +++ b/app/Domains/Virtual/Http/Controllers/FetchController.php @@ -36,7 +36,7 @@ class FetchController extends Controller public function packages(PackageRepository $packageRepository) { $type = $this->request->ids('type'); - return res($this->search($packageRepository->whereIn('type', $type)), '', 201); + return res($this->search($packageRepository->whereIn('type', $type), ['name', 'carrier_operator']), '', 201); } /** @@ -53,7 +53,10 @@ class FetchController extends Controller $search = $this->request->get('search'); $limit = $this->request->get('limit', 0); - $results = $repository->select([$primaryKey, $field, 'status'])->get(); + $field = array_wrap($field); + $field = array_merge([$primaryKey, 'status'], $field); + + $results = $repository->select($field)->get(); if ($search) { $results = $results->filter(function ($item) use ($search, $field) { diff --git a/app/Domains/Virtual/Http/Controllers/OrderController.php b/app/Domains/Virtual/Http/Controllers/OrderController.php index 37bf471a..226f4caf 100644 --- a/app/Domains/Virtual/Http/Controllers/OrderController.php +++ b/app/Domains/Virtual/Http/Controllers/OrderController.php @@ -107,6 +107,20 @@ class OrderController extends Controller return res($order, '订单详情', 201); } + /** + * 下单 + */ + public function create() + { + $attributes = $this->request->all(); + $attributes['source'] = 1; + + $res = $this->orderService->store($attributes); + + return res($res, '下单成功'); + } + + /** * 编辑. * diff --git a/app/Domains/Virtual/Repositories/ProductRepository.php b/app/Domains/Virtual/Repositories/ProductRepository.php index c2e72057..af035dd4 100644 --- a/app/Domains/Virtual/Repositories/ProductRepository.php +++ b/app/Domains/Virtual/Repositories/ProductRepository.php @@ -67,6 +67,14 @@ class ProductRepository extends Repository $query->where('company_id', $conditions['company_id']); } + if (isset($conditions['package_id'])) { + $query->where('package_id', $conditions['package_id']); + } + + if (isset($conditions['price'])) { + $query->where('price', $conditions['price']); + } + if (isset($conditions['status'])) { $query->where('status', $conditions['status']); } diff --git a/app/Domains/Virtual/Services/OrderService.php b/app/Domains/Virtual/Services/OrderService.php index 6a09b49c..2354149d 100644 --- a/app/Domains/Virtual/Services/OrderService.php +++ b/app/Domains/Virtual/Services/OrderService.php @@ -96,7 +96,21 @@ class OrderService extends Service { $attributes['sn'] = $attributes['sn'] ?: $this->generateSn(); + if ($attributes['company_id'] && $attributes['package_id'] && isset($attributes['unit_price'])) { + $attributes['unit_price'] = intval($attributes['unit_price'] * 100); + $product = ProductService::getProduct($attributes['company_id'], $attributes['package_id'], $attributes['unit_price']); + } elseif ($attributes['product_id']) { + $product = app(ProductRepository::class)->find($attributes['product_id']); + } + + if (!$product) { + throw new NotExistException('请选择套餐'); + } + + $attributes['product_id'] = $product->id; + $rule = [ + 'type' => ['required', 'in:0,1,2,3'], 'company_id' => ['exists:virtual_companies,id'], 'product_id' => [], 'counts' => [], @@ -123,18 +137,17 @@ class OrderService extends Service $rule['product_id'][] = 'required'; $rule['counts'][] = 'required'; $rule['pay_channel'][] = 'required'; - $rule['contacts'][] = 'required'; - $rule['mobile'][] = 'required'; - $rule['address'][] = 'required'; + + if (!$attributes['source']) { + $rule['contacts'][] = 'required'; + $rule['mobile'][] = 'required'; + $rule['address'][] = 'required'; + } } Validator::validate($attributes, $rule, $message); if (!$attributes['id']) { - if (!$product = app(ProductRepository::class)->withConditions(['id' => $attributes['product_id']])->first()) { - throw new NotExistException('套餐不存在或已删除'); - } - if ($product->company_id != $attributes['company_id']) { throw new NotAllowedException('非法操作'); } diff --git a/app/Domains/Virtual/Services/PackageService.php b/app/Domains/Virtual/Services/PackageService.php index c4ecfb77..04c91e11 100644 --- a/app/Domains/Virtual/Services/PackageService.php +++ b/app/Domains/Virtual/Services/PackageService.php @@ -151,7 +151,7 @@ class PackageService extends Service public static function load($id) { if (!self::$packages) { - self::$packages = app(PackageRepository::class)->select(['id', 'name', 'carrier_operator', 'flows', 'service_months', 'status'])->withTrashed()->get()->keyBy('id'); + self::$packages = app(PackageRepository::class)->select(['id', 'sn', 'name', 'carrier_operator', 'flows', 'service_months', 'status'])->withTrashed()->get()->keyBy('id'); } return self::$packages[$id]; diff --git a/app/Domains/Virtual/Services/ProductService.php b/app/Domains/Virtual/Services/ProductService.php index 65393bc5..251296f2 100644 --- a/app/Domains/Virtual/Services/ProductService.php +++ b/app/Domains/Virtual/Services/ProductService.php @@ -151,4 +151,32 @@ class ProductService extends Service { return strtoupper($packageSn . '_' . $companyId . '_' . $price); } + + /** + * 获取定价 + * + * @param string $sn + * @return void + */ + public static function getProduct($companyId, $packageId, $price) + { + $package = PackageService::load($packageId); + + $product = app(ProductRepository::class)->withConditions([ + 'company_id' => $companyId, + 'package_id' => $packageId, + 'price' => $price, + ])->first(); + + if (!$product) { + $product = app(ProductService::class)->store([ + 'name' => $package['name'] . ' ' . $price, + 'company_id' => $companyId, + 'package_id' => $package['id'], + 'price' => $price/100, + ]); + } + + return $product; + } } diff --git a/app/Models/Virtual/Order.php b/app/Models/Virtual/Order.php index e9a43738..2e71bb14 100644 --- a/app/Models/Virtual/Order.php +++ b/app/Models/Virtual/Order.php @@ -90,6 +90,34 @@ class Order extends Model 'extends' => 'array', ]; + protected $fillable = [ + 'id', + 'sn', + 'source', + 'type', + 'company_id', + 'package_id', + 'product_id', + 'transaction_no', + 'pay_channel', + 'unit_price', + 'counts', + 'total_price', + 'custom_price', + 'order_at', + 'area', + 'address', + 'contacts', + 'mobile', + 'logistics_company', + 'logistics_no', + 'order_status', + 'transaction_status', + 'logistics_remark', + 'remark', + 'extends', + ]; + public function company() { return $this->belongsTo(Company::class, 'company_id', 'id'); diff --git a/frontend/package.json b/frontend/package.json index 45eb0b04..e97d0dae 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,6 +14,7 @@ "blueimp-md5": "^2.10.0", "file-saver": "^1.3.8", "iview": "^3.0.1", + "iview-area": "^1.6.0", "jquery": "^3.3.1", "js-cookie": "^2.2.0", "moment": "^2.22.2", diff --git a/frontend/src/assets/css/common.less b/frontend/src/assets/css/common.less index a71e966c..001f08c9 100644 --- a/frontend/src/assets/css/common.less +++ b/frontend/src/assets/css/common.less @@ -796,7 +796,6 @@ table { page-break-after: left; margin-left: 120px; word-break: break-all; - line-height: 32px; } } diff --git a/frontend/src/main.js b/frontend/src/main.js index 578f9b3b..24d1f413 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -2,9 +2,9 @@ import 'iview/dist/styles/iview.css'; import 'css/common.less'; import 'css/layout.less'; import '@riophae/vue-treeselect/dist/vue-treeselect.css'; - import Vue from 'vue'; import iView from 'iview'; +import iviewArea from 'iview-area'; import Cookies from 'js-cookie'; import Treeselect from '@riophae/vue-treeselect'; import { service, serviceForm } from 'service/service'; @@ -29,6 +29,7 @@ Vue.prototype.moment = moment; Vue.config.productionTip = false; Vue.use(iView); +Vue.use(iviewArea); Vue.mixin(mixins); Vue.mixin(complete); Vue.use(base); diff --git a/frontend/src/views/virtual/flow_pools/detail.vue b/frontend/src/views/virtual/flow_pools/detail.vue index 163dd186..7a92cfd3 100644 --- a/frontend/src/views/virtual/flow_pools/detail.vue +++ b/frontend/src/views/virtual/flow_pools/detail.vue @@ -8,7 +8,7 @@ > -
+
基础信息 diff --git a/frontend/src/views/virtual/flow_pools/flows.vue b/frontend/src/views/virtual/flow_pools/flows.vue index 0780c0a4..44971424 100644 --- a/frontend/src/views/virtual/flow_pools/flows.vue +++ b/frontend/src/views/virtual/flow_pools/flows.vue @@ -13,7 +13,7 @@
  • 流量池名称:
    -
    {{data.pool_name}}
    +
    {{data.pool_name}}
  • @@ -21,21 +21,19 @@ *设置年月:
-

- -

+
  • 月计费总卡数:
    -
    {{data.total}}
    +
    {{data.total}}
  • @@ -43,9 +41,7 @@ *总使用流量:
  • -

    - (M) -

    + (M)
    @@ -66,7 +62,7 @@ - + {{!index ? obj.product_name : ' '}} {{!index ? obj.total : ' '}} @@ -119,7 +115,13 @@
    - +
    diff --git a/frontend/src/views/virtual/orders/edit.vue b/frontend/src/views/virtual/orders/edit.vue index 927769fd..59b5889b 100644 --- a/frontend/src/views/virtual/orders/edit.vue +++ b/frontend/src/views/virtual/orders/edit.vue @@ -1,5 +1,12 @@ diff --git a/frontend/src/views/virtual/orders/index.vue b/frontend/src/views/virtual/orders/index.vue index ceac82a8..1ea1651d 100644 --- a/frontend/src/views/virtual/orders/index.vue +++ b/frontend/src/views/virtual/orders/index.vue @@ -10,9 +10,9 @@
  • - +
    + +
    @@ -30,19 +30,43 @@
  • - - + +
  • - - + +
  • - +
  • @@ -90,10 +114,23 @@
    - +
    - + diff --git a/frontend/src/views/virtual/orders/js/edit.js b/frontend/src/views/virtual/orders/js/edit.js index 2742ea13..736ce5e9 100644 --- a/frontend/src/views/virtual/orders/js/edit.js +++ b/frontend/src/views/virtual/orders/js/edit.js @@ -1,4 +1,7 @@ import * as API from 'api/virtual/orders'; +import { + isPhone +} from 'validate'; export default { props: { @@ -6,11 +9,13 @@ export default { type: Boolean, default: false }, + type: { + type: Number, + default: 0 + }, data: { type: Object, - default() { - return null; - } + default: {} } }, data() { @@ -18,17 +23,21 @@ export default { my_show: false, isUpdate: false, loading: false, + companies: [], + completePackagesFilter: [], params: { - name: '', - contacts: '', - mobile: '', - address: '', + company_id: '', + carrier_operator: '', + package_id: '', + unit_price: 0, + pay_channel: '', + counts: 0, + order_at: '', remark: '', - extends: { - bank_account: '', - wechat_account: '', - alipay_account: '' - } + area: [], + address: '', + contacts: '', + mobile: '' } }; }, @@ -36,6 +45,18 @@ export default { show(bool) { this.my_show = bool; if (bool) { + this.initCompleteCompanies().then(companies => { + this.companies = companies.filter(item => { + return item.status === 0; + }); + }); + + this.initCompletePackages(this.type).then(packages => { + this.completePackagesFilter = packages.filter(function(item) { + return item.status === 0; + }); + }); + if (this.data) { for (let k in this.data) { if (k in this.params) { @@ -48,16 +69,43 @@ export default { }, methods: { ok() { - if (!this.params.name) { - this.$Message.info('请填写企业名称'); + this.params.type = this.type; + + if (!this.params.company_id) { + this.$Message.info('请选择企业'); return; } - if (!(/[\s\S]{2,32}/.test(this.params.contacts))) { + if (!this.params.package_id) { + this.$Message.info('请选择套餐'); + return; + } + + if (!this.params.pay_channel) { + this.$Message.info('请选择支付方式'); + return; + } + + if (!this.params.counts) { + this.$Message.info('请输入订单卡量'); + return; + } + + if (!this.params.order_at) { + this.$Message.info('请选择订单时间'); + return; + } + + if (this.params.contacts && !(/[\s\S]{2,32}/.test(this.params.contacts))) { this.$Message.info('联系人长度在2-32之间'); return; } + if (this.params.mobile && !isPhone(this.params.mobile)) { + this.$Message.info('手机号填写不正确'); + return; + } + if (this.data) { // 编辑 API.update(this.params, this.data.id).then(res => { @@ -97,6 +145,29 @@ export default { } this.my_show = false; + }, + handleChange(type) { + if (type === 1) { + this.params.package_id = ''; + this.initCompletePackages(this.type).then(packages => { + this.completePackagesFilter = packages.filter(item => { + return item.status === 0 && item.carrier_operator === this.params.carrier_operator; + }); + }); + } + + if (type === 2) { + let selectPackage = this.completePackagesFilter.find(item => { + return item.id === this.params.package_id; + }); + + if (selectPackage) { + this.params.carrier_operator = selectPackage.carrier_operator; + } + } + + console.log(type); + console.log(selectPackage); } } }; diff --git a/frontend/src/views/virtual/orders/js/index.js b/frontend/src/views/virtual/orders/js/index.js index f42984a5..2cf8b105 100644 --- a/frontend/src/views/virtual/orders/js/index.js +++ b/frontend/src/views/virtual/orders/js/index.js @@ -17,6 +17,7 @@ export default { carrier_operator: '', time: [] }, + type: 0, list_data: null, editObj: { show: false, @@ -506,6 +507,7 @@ export default { * @return {[type]} [description] */ index(page = 1) { + this.type = Number(this.$route.params.type); this.params.type = Number(this.$route.params.type); let data = this.searchDataHandle({}, { page }, this.params); this.isShowLoading(true);