withConditions

This commit is contained in:
邓皓元 2018-12-25 17:34:52 +08:00
parent 68332d33d9
commit 31342f57a7
4 changed files with 36 additions and 16 deletions

View File

@ -33,6 +33,8 @@ class OrderController extends Controller
{
$conditions = $this->request->all();
$conditions['company_id'] = $this->account->company_id;
$conditions['source'] = 0;
$conditions['type'] = 0;
$res = $this->orderService->paginate($conditions);
@ -113,6 +115,7 @@ class OrderController extends Controller
{
$attributes = $this->request->all();
$attributes['company_id'] = $this->account->company_id;
$attributes['source'] = 0;
$res = $this->orderService->store($attributes);

View File

@ -49,7 +49,7 @@ class LogSync extends Command
$query = DB::connection('vd_old')->table('logs')
->where('type', '<>', 10)
->where('create_time', '>', $timestamp)
->where('id', '>', $nextId)
->orderBy('id');
$total = $query->count();
@ -65,6 +65,8 @@ class LogSync extends Command
DB::beginTransaction();
foreach ($res as $key => $value) {
$value = (array)$value;
$package = $this->getPackage($value['content']);
$unit_price = floatval($value['sale_account']) * 100;
$custom_price = floatval($value['order_account']) * 100;
@ -93,18 +95,9 @@ class LogSync extends Command
'created_at' => date('Y-m-d H:i:s', $res['create_time']),
];
$relationData = [
'sim' => $value['sim'],
'order_id' => $order->id,
'company_id' => $order->company_id,
'package_id' => $order->package_id,
'counts' => 1,
'unit_price' => $order->unit_price
];
try {
if ($order = Order::where('sn', $data['sn'])->first()) {
$order->count = $order->count + 1;
$order->counts = $order->counts + 1;
$order->total_price = $order->total_price + $unit_price;
$order->custom_price = $order->custom_price + $custom_price;
$order->save();
@ -112,13 +105,26 @@ class LogSync extends Command
$order = Order::create($data);
}
$query = (new $orderClasses[$type])->query();
$relationData = [
'sim' => $value['sim'],
'order_id' => $order->id,
'company_id' => $order->company_id,
'package_id' => $order->package_id,
'counts' => 1,
];
if ($relation = $query->where('sim', $value['sim'])->where('order_id', $order->id)->first()) {
$relation->count = $relation->count + 1;
$relation->save();
$class = (new self::$orderClasses[$type])->query();
if ($type) {
if ($relation = $class->where('sim', $value['sim'])->where('order_id', $order->id)->first()) {
$relation->counts = $relation->counts + 1;
$relation->save();
} else {
$relation = $class->create($relationData);
}
} else {
$relation = $query->create($relationData);
unset($relationData['counts']);
$relation = $class->upsert($relationData, ['sim', 'order_id']);
}
} catch (\Exception $e) {
DB::rollback();

View File

@ -33,6 +33,8 @@ class OrderController extends Controller
{
$conditions = $this->request->all();
$conditions['limit'] = $this->request->get('limit', 20);
$conditions['source'] = 0;
$conditions['type'] = 0;
$orders = $this->orderService->paginate($conditions);

View File

@ -60,6 +60,15 @@ class OrderRepository extends Repository
$this->model = $this->model->whereIn('id', $conditions['id']);
}
if (isset($conditions['source'])) {
$this->model = $this->model->where('source', $conditions['source']);
}
if (isset($conditions['type'])) {
$this->model = $this->model->where('type', $conditions['type']);
}
if (isset($conditions['company_id'])) {
$this->model = $this->model->where('company_id', $conditions['company_id']);
}