Completed
Pull Request — 4.0 (#3626)
by chihiro
06:07
created

OrderRepository::getQueryBuilderBySearchData()   F

Complexity

Conditions 42
Paths > 20000

Size

Total Lines 167

Duplication

Lines 108
Ratio 64.67 %

Code Coverage

Tests 78
CRAP Score 42.642

Importance

Changes 0
Metric Value
cc 42
nc 884736
nop 1
dl 108
loc 167
rs 0
c 0
b 0
f 0
ccs 78
cts 84
cp 0.9286
crap 42.642

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Repository;
15
16
use Doctrine\ORM\NoResultException;
17
use Doctrine\ORM\QueryBuilder;
18
use Eccube\Doctrine\Query\Queries;
19
use Eccube\Entity\Customer;
20
use Eccube\Entity\Master\OrderStatus;
21
use Eccube\Entity\Order;
22
use Eccube\Entity\Shipping;
23
use Eccube\Util\StringUtil;
24
use Symfony\Bridge\Doctrine\RegistryInterface;
25
26
/**
27
 * OrderRepository
28
 *
29
 * This class was generated by the Doctrine ORM. Add your own custom
30
 * repository methods below.
31
 */
32
class OrderRepository extends AbstractRepository
33
{
34
    /**
35
     * @var Queries
36
     */
37
    protected $queries;
38
39
    /**
40
     * OrderRepository constructor.
41
     *
42
     * @param RegistryInterface $registry
43
     * @param Queries $queries
44 832
     */
45
    public function __construct(RegistryInterface $registry, Queries $queries)
46 832
    {
47 832
        parent::__construct($registry, Order::class);
48
        $this->queries = $queries;
49
    }
50
51
    /**
52
     * @param int $orderId
53
     * @param OrderStatus $Status
54 19
     */
55
    public function changeStatus($orderId, \Eccube\Entity\Master\OrderStatus $Status)
56
    {
57 19
        $Order = $this
58 19
            ->find($orderId)
59
            ->setOrderStatus($Status)
60
        ;
61 19
62 19
        switch ($Status->getId()) {
63 3
            case '6': // 入金済へ
64 3
                $Order->setPaymentDate(new \DateTime());
65
                break;
66
        }
67 19
68 19
        $em = $this->getEntityManager();
69 19
        $em->persist($Order);
70
        $em->flush();
71
    }
72
73
    /**
74
     * @param array $searchData
75
     *
76
     * @return QueryBuilder
77 17
     */
78
    public function getQueryBuilderBySearchData($searchData)
79 17
    {
80
        $qb = $this->createQueryBuilder('o');
81 17
82
        $joinedCustomer = false;
83
84 17
        // order_id_start
85 View Code Duplication
        if (isset($searchData['order_id_start']) && StringUtil::isNotBlank($searchData['order_id_start'])) {
86 1
            $qb
87 1
                ->andWhere('o.id >= :order_id_start')
88
                ->setParameter('order_id_start', $searchData['order_id_start']);
89
        }
90
91 17
        // order_id_end
92 View Code Duplication
        if (isset($searchData['order_id_end']) && StringUtil::isNotBlank($searchData['order_id_end'])) {
93 1
            $qb
94 1
                ->andWhere('o.id <= :order_id_end')
95
                ->setParameter('order_id_end', $searchData['order_id_end']);
96
        }
97
98 17
        // status
99
        if (!empty($searchData['status']) && $searchData['status']) {
100 1
            $qb
101 1
                ->andWhere('o.OrderStatus = :status')
102
                ->setParameter('status', $searchData['status']);
103
        }
104
105 17
        // name
106 View Code Duplication
        if (isset($searchData['name']) && StringUtil::isNotBlank($searchData['name'])) {
107 1
            $qb
108 1
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
109
                ->setParameter('name', '%'.$searchData['name'].'%');
110
        }
111
112 17
        // kana
113 View Code Duplication
        if (isset($searchData['kana']) && StringUtil::isNotBlank($searchData['kana'])) {
114 1
            $qb
115 1
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
116
                ->setParameter('kana', '%'.$searchData['kana'].'%');
117
        }
118
119 17
        // email
120 View Code Duplication
        if (isset($searchData['email']) && StringUtil::isNotBlank($searchData['email'])) {
121 1
            $qb
122 1
                ->andWhere('o.email = :email')
123
                ->setParameter('email', $searchData['email']);
124
        }
125
126 17
        // tel
127 View Code Duplication
        if (isset($searchData['phone_number']) && StringUtil::isNotBlank($searchData['phone_number'])) {
128 1
            $qb
129 1
                ->andWhere('o.phone_number = :phone_number')
130
                ->setParameter('phone_number', $searchData['phone_number']);
131
        }
132
133 17
        // birth
134 1 View Code Duplication
        if (!empty($searchData['birth_start']) && $searchData['birth_start']) {
135 1
            if (!$joinedCustomer) {
136 1
                $qb->leftJoin('o.Customer', 'c');
137
                $joinedCustomer = true;
138
            }
139 1
140
            $date = $searchData['birth_start'];
141 1
            $qb
142 1
                ->andWhere('c.birth >= :birth_start')
143
                ->setParameter('birth_start', $date);
144 17
        }
145 1 View Code Duplication
        if (!empty($searchData['birth_end']) && $searchData['birth_end']) {
146 1
            if (!$joinedCustomer) {
147 1
                $qb->leftJoin('o.Customer', 'c');
148
                $joinedCustomer = true;
149
            }
150 1
151
            $date = clone $searchData['birth_end'];
152 1
            $date = $date
153
                ->modify('+1 days');
154 1
            $qb
155 1
                ->andWhere('c.birth < :birth_end')
156
                ->setParameter('birth_end', $date);
157
        }
158
159 17
        // sex
160 1
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
161 1
            if (!$joinedCustomer) {
162 1
                $qb->leftJoin('o.Customer', 'c');
163
                $joinedCustomer = true;
0 ignored issues
show
Unused Code introduced by
$joinedCustomer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
164
            }
165 1
166 1
            $sexs = [];
167 1
            foreach ($searchData['sex'] as $sex) {
168
                $sexs[] = $sex->getId();
169
            }
170
171 1
            $qb
172 1
                ->andWhere($qb->expr()->in('c.Sex', ':sexs'))
173
                ->setParameter('sexs', $sexs);
174
        }
175
176 17
        // payment
177 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
178
            $payments = [];
179
            foreach ($searchData['payment'] as $payment) {
180
                $payments[] = $payment->getId();
181
            }
182
            $qb
183
                ->leftJoin('o.Payment', 'p')
184
                ->andWhere($qb->expr()->in('p.id', ':payments'))
185
                ->setParameter('payments', $payments);
186
        }
187
188 17
        // oreder_date
189 1 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
190
            $date = $searchData['order_date_start'];
191 1
            $qb
192 1
                ->andWhere('o.create_date >= :order_date_start')
193
                ->setParameter('order_date_start', $date);
194 17
        }
195 1 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
196
            $date = clone $searchData['order_date_end'];
197 1
            $date = $date
198
                ->modify('+1 days');
199 1
            $qb
200 1
                ->andWhere('o.create_date < :order_date_end')
201
                ->setParameter('order_date_end', $date);
202
        }
203
204 17
        // create_date
205 1 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
206
            $date = $searchData['update_date_start'];
207 1
            $qb
208 1
                ->andWhere('o.update_date >= :update_date_start')
209
                ->setParameter('update_date_start', $date);
210 17
        }
211 1 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
212
            $date = clone $searchData['update_date_end'];
213 1
            $date = $date
214
                ->modify('+1 days');
215 1
            $qb
216 1
                ->andWhere('o.update_date < :update_date_end')
217
                ->setParameter('update_date_end', $date);
218
        }
219
220 17
        // payment_total
221 View Code Duplication
        if (isset($searchData['payment_total_start']) && StringUtil::isNotBlank($searchData['payment_total_start'])) {
222 1
            $qb
223 1
                ->andWhere('o.payment_total >= :payment_total_start')
224
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
225 17
        }
226 View Code Duplication
        if (isset($searchData['payment_total_end']) && StringUtil::isNotBlank($searchData['payment_total_end'])) {
227 1
            $qb
228 1
                ->andWhere('o.payment_total <= :payment_total_end')
229
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
230
        }
231
232 17
        // buy_product_name
233 View Code Duplication
        if (isset($searchData['buy_product_name']) && StringUtil::isNotBlank($searchData['buy_product_name'])) {
234 1
            $qb
235 1
                ->leftJoin('o.OrderItems', 'oi')
236 1
                ->andWhere('oi.product_name LIKE :buy_product_name')
237
                ->setParameter('buy_product_name', '%'.$searchData['buy_product_name'].'%');
238
        }
239
240 17
        // Order By
241
        $qb->addOrderBy('o.update_date', 'DESC');
242 17
243
        return $this->queries->customize(QueryKey::ORDER_SEARCH, $qb, $searchData);
244
    }
245
246
    /**
247
     * @param  array        $searchData
248
     *
249
     * @return QueryBuilder
250 34
     */
251
    public function getQueryBuilderBySearchDataForAdmin($searchData)
252 34
    {
253 34
        $qb = $this->createQueryBuilder('o')
254 34
            ->select('o, s')
255
            ->innerJoin('o.Shippings', 's');
256
257 34
        // order_id_start
258 View Code Duplication
        if (isset($searchData['order_id']) && StringUtil::isNotBlank($searchData['order_id'])) {
259
            $qb
260
                ->andWhere('o.id = :order_id')
261
                ->setParameter('order_id', $searchData['order_id']);
262
        }
263
264 34
        // order_no
265 View Code Duplication
        if (isset($searchData['order_no']) && StringUtil::isNotBlank($searchData['order_no'])) {
266 2
            $qb
267 2
                ->andWhere('o.order_no = :order_no')
268
                ->setParameter('order_no', $searchData['order_no']);
269
        }
270
271 34
        // order_id_start
272 View Code Duplication
        if (isset($searchData['order_id_start']) && StringUtil::isNotBlank($searchData['order_id_start'])) {
273 1
            $qb
274 1
                ->andWhere('o.id >= :order_id_start')
275
                ->setParameter('order_id_start', $searchData['order_id_start']);
276
        }
277 34
        // multi
278 5 View Code Duplication
        if (isset($searchData['multi']) && StringUtil::isNotBlank($searchData['multi'])) {
279
            $multi = preg_match('/^\d{0,10}$/', $searchData['multi']) ? $searchData['multi'] : null;
280 5
            $qb
281
                ->andWhere('o.id = :multi OR o.name01 LIKE :likemulti OR o.name02 LIKE :likemulti OR '.
282 5
                            'o.kana01 LIKE :likemulti OR o.kana02 LIKE :likemulti OR o.company_name LIKE :likemulti OR '.
283 5
                            'o.order_no LIKE :likemulti')
284 5
                ->setParameter('multi', $multi)
285
                ->setParameter('likemulti', '%'.$searchData['multi'].'%');
286
        }
287
288 34
        // order_id_end
289 View Code Duplication
        if (isset($searchData['order_id_end']) && StringUtil::isNotBlank($searchData['order_id_end'])) {
290 1
            $qb
291 1
                ->andWhere('o.id <= :order_id_end')
292
                ->setParameter('order_id_end', $searchData['order_id_end']);
293
        }
294
295 34
        // status
296 34
        $filterStatus = false;
297 View Code Duplication
        if (!empty($searchData['status']) && count($searchData['status'])) {
298 1
            $qb
299 1
                ->andWhere($qb->expr()->in('o.OrderStatus', ':status'))
300 1
                ->setParameter('status', $searchData['status']);
301
            $filterStatus = true;
302
        }
303 34
304
        if (!$filterStatus) {
305 33
            // 購入処理中は検索対象から除外
306 33
            $OrderStatuses = $this->getEntityManager()
307 33
                ->getRepository('Eccube\Entity\Master\OrderStatus')
308 33
                ->findNotContainsBy(['id' => OrderStatus::PROCESSING]);
309 33
            $qb->andWhere($qb->expr()->in('o.OrderStatus', ':status'))
310
                ->setParameter('status', $OrderStatuses);
311
        }
312
313 34
        // company_name
314 View Code Duplication
        if (isset($searchData['company_name']) && StringUtil::isNotBlank($searchData['company_name'])) {
315 1
            $qb
316 1
                ->andWhere('o.company_name LIKE :company_name')
317
                ->setParameter('company_name', '%'.$searchData['company_name'].'%');
318
        }
319
320 34
        // name
321 View Code Duplication
        if (isset($searchData['name']) && StringUtil::isNotBlank($searchData['name'])) {
322 1
            $qb
323 1
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
324
                ->setParameter('name', '%'.$searchData['name'].'%');
325
        }
326
327 34
        // kana
328 View Code Duplication
        if (isset($searchData['kana']) && StringUtil::isNotBlank($searchData['kana'])) {
329 1
            $qb
330 1
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
331
                ->setParameter('kana', '%'.$searchData['kana'].'%');
332
        }
333
334 34
        // email
335 View Code Duplication
        if (isset($searchData['email']) && StringUtil::isNotBlank($searchData['email'])) {
336 3
            $qb
337 3
                ->andWhere('o.email like :email')
338
                ->setParameter('email', '%'.$searchData['email'].'%');
339
        }
340
341 34
        // tel
342 1 View Code Duplication
        if (isset($searchData['phone_number']) && StringUtil::isNotBlank($searchData['phone_number'])) {
343
            $tel = preg_replace('/[^0-9]/ ', '', $searchData['phone_number']);
344 1
            $qb
345 1
                ->andWhere('o.phone_number LIKE :phone_number')
346
                ->setParameter('phone_number', '%'.$tel.'%');
347
        }
348
349 34
        // sex
350
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
351 1
            $qb
352 1
                ->andWhere($qb->expr()->in('o.Sex', ':sex'))
353
                ->setParameter('sex', $searchData['sex']->toArray());
354
        }
355
356 34
        // payment
357 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
358
            $payments = [];
359
            foreach ($searchData['payment'] as $payment) {
360
                $payments[] = $payment->getId();
361
            }
362
            $qb
363
                ->leftJoin('o.Payment', 'p')
364
                ->andWhere($qb->expr()->in('p.id', ':payments'))
365
                ->setParameter('payments', $payments);
366
        }
367
368 34
        // oreder_date
369 1 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
370
            $date = $searchData['order_date_start'];
371 1
            $qb
372 1
                ->andWhere('o.order_date >= :order_date_start')
373
                ->setParameter('order_date_start', $date);
374 34
        }
375 1 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
376
            $date = clone $searchData['order_date_end'];
377 1
            $date = $date
378
                ->modify('+1 days');
379 1
            $qb
380 1
                ->andWhere('o.order_date < :order_date_end')
381
                ->setParameter('order_date_end', $date);
382
        }
383
384 34
        // payment_date
385 1 View Code Duplication
        if (!empty($searchData['payment_date_start']) && $searchData['payment_date_start']) {
386
            $date = $searchData['payment_date_start'];
387 1
            $qb
388 1
                ->andWhere('o.payment_date >= :payment_date_start')
389
                ->setParameter('payment_date_start', $date);
390 34
        }
391 1 View Code Duplication
        if (!empty($searchData['payment_date_end']) && $searchData['payment_date_end']) {
392
            $date = clone $searchData['payment_date_end'];
393 1
            $date = $date
394
                ->modify('+1 days');
395 1
            $qb
396 1
                ->andWhere('o.payment_date < :payment_date_end')
397
                ->setParameter('payment_date_end', $date);
398
        }
399
400 34
        // update_date
401 1 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
402
            $date = $searchData['update_date_start'];
403 1
            $qb
404 1
                ->andWhere('o.update_date >= :update_date_start')
405
                ->setParameter('update_date_start', $date);
406 34
        }
407 1 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
408
            $date = clone $searchData['update_date_end'];
409 1
            $date = $date
410
                ->modify('+1 days');
411 1
            $qb
412 1
                ->andWhere('o.update_date < :update_date_end')
413
                ->setParameter('update_date_end', $date);
414
        }
415
416 34
        // payment_total
417 View Code Duplication
        if (isset($searchData['payment_total_start']) && StringUtil::isNotBlank($searchData['payment_total_start'])) {
418 1
            $qb
419 1
                ->andWhere('o.payment_total >= :payment_total_start')
420
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
421 34
        }
422 View Code Duplication
        if (isset($searchData['payment_total_end']) && StringUtil::isNotBlank($searchData['payment_total_end'])) {
423 1
            $qb
424 1
                ->andWhere('o.payment_total <= :payment_total_end')
425
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
426
        }
427
428 34
        // buy_product_name
429 View Code Duplication
        if (isset($searchData['buy_product_name']) && StringUtil::isNotBlank($searchData['buy_product_name'])) {
430 1
            $qb
431 1
                ->leftJoin('o.OrderItems', 'oi')
432 1
                ->andWhere('oi.product_name LIKE :buy_product_name')
433
                ->setParameter('buy_product_name', '%'.$searchData['buy_product_name'].'%');
434
        }
435
436 34
        // 発送メール送信/未送信.
437
        if (isset($searchData['shipping_mail']) && $count = count($searchData['shipping_mail'])) {
438
            // 送信済/未送信両方にチェックされている場合は検索条件に追加しない
439
            if ($count < 2) {
440
                $checked = current($searchData['shipping_mail']);
441
                if ($checked == Shipping::SHIPPING_MAIL_UNSENT) {
442 34
                    // 未送信
443
                    $qb
444 1
                        ->andWhere('s.mail_send_date IS NULL');
445 1
                } elseif ($checked == Shipping::SHIPPING_MAIL_SENT) {
446
                    // 送信
447
                    $qb
448
                        ->andWhere('s.mail_send_date IS NOT NULL');
449 34
                }
450
            }
451
        }
452
453
        // 送り状番号.
454
        if (!empty($searchData['tracking_number'])) {
455 34
            $qb
456
                ->andWhere('s.tracking_number = :tracking_number')
457
                ->setParameter('tracking_number', $searchData['tracking_number']);
458
        }
459
460
        // お届け予定日(Shipping.delivery_date)
461 View Code Duplication
        if (!empty($searchData['shipping_delivery_date_start']) && $searchData['shipping_delivery_date_start']) {
462
            $date = $searchData['shipping_delivery_date_start'];
463
            $qb
464
                ->andWhere('s.shipping_delivery_date >= :shipping_delivery_date_start')
465 34
                ->setParameter('shipping_delivery_date_start', $date);
466 34
        }
467 View Code Duplication
        if (!empty($searchData['shipping_delivery_date_end']) && $searchData['shipping_delivery_date_end']) {
468 34
            $date = clone $searchData['shipping_delivery_date_end'];
469
            $date = $date
470
                ->modify('+1 days');
471
            $qb
472
                ->andWhere('s.shipping_delivery_date < :shipping_delivery_date_end')
473
                ->setParameter('shipping_delivery_date_end', $date);
474
        }
475
476 2
        // Order By
477
        $qb->orderBy('o.update_date', 'DESC');
478 2
        $qb->addorderBy('o.id', 'DESC');
479 2
480 2
        return $this->queries->customize(QueryKey::ORDER_SEARCH_ADMIN, $qb, $searchData);
481
    }
482
483 2
    /**
484
     * @param  \Eccube\Entity\Customer $Customer
485 2
     *
486
     * @return QueryBuilder
487
     */
488 View Code Duplication
    public function getQueryBuilderByCustomer(\Eccube\Entity\Customer $Customer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
489
    {
490
        $qb = $this->createQueryBuilder('o')
491
            ->where('o.Customer = :Customer')
492
            ->setParameter('Customer', $Customer);
493
494
        // Order By
495
        $qb->addOrderBy('o.id', 'DESC');
496 1
497
        return $this->queries->customize(QueryKey::ORDER_SEARCH_BY_CUSTOMER, $qb, ['customer' => $Customer]);
498 1
    }
499 1
500 1
    /**
501 1
     * ステータスごとの受注件数を取得する.
502 1
     *
503 1
     * @param integer $OrderStatusOrId
504 1
     *
505 1
     * @return int
506 1
     *
507
     * @throws \Doctrine\ORM\NoResultException
508 1
     * @throws \Doctrine\ORM\NonUniqueResultException
509
     */
510
    public function countByOrderStatus($OrderStatusOrId)
511
    {
512
        return (int) $this->createQueryBuilder('o')
513
            ->select('COALESCE(COUNT(o.id), 0)')
514
            ->where('o.OrderStatus = :OrderStatus')
515
            ->setParameter('OrderStatus', $OrderStatusOrId)
516
            ->getQuery()
517
            ->getSingleScalarResult();
518 2
    }
519
520 2
    /**
521
     * 会員の購入金額, 購入回数, 初回購入日, 最終購入費を更新する
522 2
     *
523 2
     * @param Customer $Customer
524 2
     * @param array $OrderStatuses
525 2
     */
526 2
    public function updateOrderSummary(Customer $Customer, array $OrderStatuses = [OrderStatus::NEW, OrderStatus::PAID, OrderStatus::DELIVERED, OrderStatus::IN_PROGRESS])
527 2
    {
528 2
        try {
529
            $result = $this->createQueryBuilder('o')
530 2
                ->select('COUNT(o.id) AS buy_times, SUM(o.total) AS buy_total, MIN(o.id) AS first_order_id, MAX(o.id) AS last_order_id')
531 1
                ->where('o.Customer = :Customer')
532
                ->andWhere('o.OrderStatus in (:OrderStatuses)')
533
                ->setParameter('Customer', $Customer)
534 1
                ->setParameter('OrderStatuses', $OrderStatuses)
535
                ->groupBy('o.Customer')
536
                ->getQuery()
537
                ->getSingleResult();
538
        } catch (NoResultException $e) {
539
            // 受注データが存在しなければ初期化
540
            $Customer->setFirstBuyDate(null);
541
            $Customer->setLastBuyDate(null);
542
            $Customer->setBuyTimes(0);
543
            $Customer->setBuyTotal(0);
544
545
            return;
546
        }
547 10
548
        $FirstOrder = $this->find(['id' => $result['first_order_id']]);
549 10
        $LastOrder = $this->find(['id' => $result['last_order_id']]);
550 10
551 10
        $Customer->setBuyTimes($result['buy_times']);
552 10
        $Customer->setBuyTotal($result['buy_total']);
553 10
        $Customer->setFirstBuyDate($FirstOrder->getOrderDate());
554 10
        $Customer->setLastBuyDate($LastOrder->getOrderDate());
555
    }
556
}
557