123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\services\order\cashier;
- use app\dao\order\StoreHangOrderDao;
- use app\services\BaseServices;
- use app\services\order\StoreCartServices;
- use app\services\order\StoreOrderServices;
- use crmeb\traits\ServicesTrait;
- class StoreHangOrderServices extends BaseServices
- {
- use ServicesTrait;
-
- public function __construct(StoreHangOrderDao $dao)
- {
- $this->dao = $dao;
- }
-
- public function getHangOrder(int $storeId, int $staffId)
- {
-
- $service = app()->make(StoreCartServices::class);
- $data = $service->getHangOrder($storeId, $staffId)->limit(10)->order('add_time desc')->select()->toArray();
- foreach ($data as &$item) {
- $item['is_check'] = 0;
- }
- $uid = $data ? array_column($data, 'uid') : [];
-
- $orderService = app()->make(StoreOrderServices::class);
- $user = $orderService->getOrderHistoryList($storeId, $staffId, $uid, 20);
- foreach ($user as &$item) {
- $item['is_check'] = 1;
- }
- [$usec, $sec] = explode(" ", microtime());
- $msec = round($usec * 1000);
- $tourist = [[
- 'is_check' => 1,
- 'tourist_uid' => $msec,
- 'uid' => 0,
- 'nickname' => '',
- 'avatar' => '',
- 'staff_id' => $staffId,
- 'store_id' => $storeId,
- 'cart_id' => '',
- 'add_time' => time()
- ]];
- return array_merge($data, $tourist, $user);
- }
-
- public function getHangOrderList(int $storeId, int $staffId, string $search)
- {
- [$page, $limit] = $this->getPageValue();
-
- $service = app()->make(StoreCartServices::class);
- $data = $service->getHangOrder($storeId, $staffId, $search, $page, $limit)->order('add_time desc')->select()->toArray();
-
- $make = app()->make(CashierOrderServices::class);
- foreach ($data as &$item) {
- $item['id'] = $item['cart_id'];
- $item['_add_time'] = date('Y.m.d H:i:s', $item['add_time']);
- try {
- $computeOrder = $make->computeOrder($item['uid'], $storeId, explode(',', $item['cart_id']) ?: []);
- $item['price'] = $computeOrder['payPrice'];
- } catch (\Throwable $e) {
- $item['price'] = 0;
- }
- }
- $count = $service->getHangOrder($storeId, $staffId, $search)->count();
- return compact('data', 'count');
- }
-
- public function saveHang(int $uid, array $cartIds, string $price, int $storeId, int $staffId, string $touristUid = '')
- {
- $cartIds = implode(',', $cartIds);
- if ($uid && $this->dao->count(['uid' => $uid, 'store_id' => $storeId, 'staff_id' => $staffId])) {
- $this->dao->delete(['uid' => $uid, 'store_id' => $storeId, 'staff_id' => $staffId]);
- } else if ($touristUid && $this->dao->count(['tourist_uid' => $touristUid, 'store_id' => $storeId, 'staff_id' => $staffId])) {
- $this->dao->delete(['tourist_uid' => $touristUid, 'store_id' => $storeId, 'staff_id' => $staffId]);
- }
- return $this->dao->save([
- 'uid' => $uid,
- 'cart_ids' => $cartIds,
- 'store_id' => $storeId,
- 'staff_id' => $staffId,
- 'tourist_uid' => $touristUid,
- 'price' => $price
- ]);
- }
- }
|