| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace bizGhs\order\classes;
- use biz\merchant\classes\MerchantAssetClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\stat\classes\StatOrderCountClass;
- use common\components\orderSn;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizGhs\base\classes\BaseClass;
- class OrderClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\order\models\Order';
- //已完成
- const ORDER_STATUS_COMPLETE = 6;
- //已取消
- const ORDER_STATUS_CANCEL = 5;
- //待通知
- const ORDER_STATUS_UN_NOTICE = 4;
- //配送中
- const ORDER_STATUS_SENDING = 3;
- //待配送
- const ORDER_STATUS_UN_SEND = 2;
- //待付款,待确认
- const ORDER_STATUS_UN_PAY = 1;
- //未确认配送方式
- const SEND_TYPE_UNKNOWN = 1;
- //自取,免配送
- const SEND_TYPE_NO = 2;
- //自己送
- const SEND_TYPE_MYSELF = 3;
- //快递送,别人送
- const SEND_TYPE_OTHER = 4;
- //添加订单 shish 2019.12.5
- public static function addOrder($data)
- {
- $date = date("Y-m-d H:i:s");
- $merchantId = $data['merchantId'] ?? 0;
- $month = date("Ym");
- $data['orderSn'] = orderSn::getGhsOrderSn();
- $data['payStatus'] = 0;
- $data['createTime'] = $date;
- $data['addTime'] = time();
- //花材列表
- $product = $data['product'];
- OrderItemClass::batchAdd($product);
- //将花店每月的总订单数作为编号
- $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
- $data['sendNum'] = $riseNum;
- $data['num'] = 1;
- $data['smallNum'] = 1;
- $return = self::add($data);
- //全部订单+1,待付款订单+1
- $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
- $merchantAsset->unPayOrder += 1;
- $merchantAsset->totalOrder += 1;
- $merchantAsset->save();
- return $return;
- }
- //根据订单编号查询 shish 2021.19
- public static function getByOrderSn($orderSn)
- {
- return self::getByCondition(['orderSn' => $orderSn]);
- }
- //订单列表 shish 2021.1.19
- public static function getOrderList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- $data['list'] = self::groupOrder($data['list'], true);
- $data['allNum'] = 0;
- $data['unPayNum'] = 0;
- $data['unSendNum'] = 0;
- $data['sendingNum'] = 0;
- $data['finishNum'] = 0;
- return $data;
- }
- //整合订单员工和供货商等信息 shish 2021.1.19
- public static function groupOrder($list, $showButton = false, $showProgress = false, $showProdct = false)
- {
- if (empty($list)) {
- return $list;
- }
- $customIds = array_unique(array_filter(array_column($list, 'customId')));
- $customInfo = CustomClass::getCustomByIds($customIds);
- $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
- $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
- foreach ($list as $key => $val) {
- $adminId = $val['adminId'] ?? 0;
- $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
- $customId = $val['customId'] ?? 0;
- $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
- $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
- $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
- $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
- if ($showButton) {
- $list[$key]['buttonList'] = [
- ['type' => 'item', 'show' => 1, 'disable' => 1],
- ['type' => 'send', 'show' => 1, 'disable' => 0],
- ['type' => 'selfGet', 'show' => 1, 'disable' => 0],
- ];
- }
- if ($showProgress) {
- $list[$key]['progress'] = [
- ['name' => '创建', 'complete' => 1],
- ['name' => '待确认', 'complete' => 0],
- ['name' => '出库', 'complete' => 0],
- ];
- }
- if ($showProdct) {
- $list[$key]['product'] = [
- [
- 'cover' => 'https://img.huahb.com/uploads/12358/202101/13/0e713d46064ca89b1fb11095b710f244_small.jpeg',
- 'name' => '昆明B级红玫瑰卡罗拉', 'property' => 'B级', 'price' => '8.45', 'bigNum' => 2, 'smallNum' => 10
- ],
- ];
- }
- }
- return $list;
- }
- public static function valid($info, $shopId)
- {
- if (isset($info['shopId']) && $info['shopId'] == $shopId) {
- return true;
- }
- util::fail('没有权限操作的订单');
- }
- //获取订单详情 shish 2021.1.21
- public static function getOrderInfo($id)
- {
- $info = self::getById($id);
- $respond = self::groupOrder([$info], true, true, true);
- return current($respond);
- }
- }
|