request->get();
$id = $get['id'] ?? 0;
$cg = PurchaseOrderClass::getById($id, true);
if (empty($cg)) {
util::fail('没有找到采购信息');
}
if ($cg->mainId != $this->mainId) {
util::fail('不是你的采购单哦');
}
if ($cg->status != 4) {
util::fail('已入库的订单才能打印');
}
$orderSn = $cg->orderSn ?? '';
$itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
$table = [];
$totalItemNum = 0;
$kind = 0;
if (!empty($itemList)) {
foreach ($itemList as $key => $val) {
$kind++;
$currentName = $val['name'] ?? '';
$preNum = $val['itemNum'] ?? 0;
$preNum = floatval($preNum);
$refundNum = $val['refundNum'] ?? 0;
$num = bcsub($preNum, $refundNum);
$totalItemNum = bcadd($totalItemNum, $num);
$unitPrice = $val['bigPrice'] ?? 0;
$unitPrice = floatval($unitPrice);
$orderNum = bcadd($key, 1);
$currentPrice = $val['totalPrice'] ?? 0;
$currentPrice = floatval($currentPrice);
$table[] = [
'orderNum' => $orderNum,
'name' => $currentName,
'num' => $preNum,
'unitPrice' => '¥' . $unitPrice,
'refundNum' => $refundNum,
'remark' => '',
'price' => '¥' . $currentPrice,
];
}
}
$shortOrderSn = substr($orderSn, -4);
$ghsName = $cg->ghsName ?? '';
$entryTime = $cg->entryTime ?? '';
$entryTime = substr($entryTime, 0, 16);
$addTime = $cg->addTime ?? '';
$addTime = substr($addTime, 0, 16);
$shopAdminName = $cg->shopAdminName ?? '';
$shopId = $cg->shopId ?? 0;
$shop = ShopClass::getById($shopId, true);
$telephone = $shop->telephone ?? '';
$shopName = $shop->shopName ?? '';
$sjId = $shop->sjId ?? 0;
$sj = SjClass::getById($sjId, true);
$sjName = $sj->name ?? '';
$sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
$prePrice = $cg->prePrice ?? 0;
$prePrice = floatval($prePrice);
$tkPrice = $cg->tkPrice ?? 0;
$tkPrice = floatval($tkPrice);
$realPrice = $cg->realPrice ?? 0;
$realPrice = floatval($realPrice);
$printData = [
'table' => $table,
'addTime' => $addTime,
'entryTime' => $entryTime,
'ghsName' => $ghsName,
'clearCode' => $shortOrderSn,
'staffName' => $shopAdminName,
'telephone' => $telephone,
'kind' => $kind,
'orderSn' => $orderSn,
'sjShopName' => $sjShopName . ' 采购单',
'prePrice' => '¥' . $prePrice,
'tkPrice' => '¥' . $tkPrice,
'realPrice' => '¥' . $realPrice,
'totalItemNum' => $totalItemNum,
'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
];
$template = '{"panels":[{"index":0,"name":1,"height":147.6,"width":210,"paperHeader":49.5,"paperFooter":387.63636363636357,"printElements":[{"options":{"left":17.5,"top":60,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"textAlign":"center","columns":[[{"width":275,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":275,"title":"价格","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}}],"paperNumberLeft":565.5,"paperNumberTop":396,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"vue-plugin-hiprint","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"row","layoutRowGap":0,"layoutColumnGap":0}}]}';
util::success(['template' => $template, 'printData' => $printData]);
}
//修改货位号 ssh 20240410
public function actionModifySeatSn()
{
$get = Yii::$app->request->get();
$id = $get['id'] ?? 0;
$seatSn = $get['seatSn'] ?? '';
$cg = PurchaseOrderClass::getById($id, true);
if (empty($cg)) {
util::fail('没有找到采购单');
}
if ($cg->mainId != $this->mainId) {
util::fail('没有权限');
}
$cg->seatSn = $seatSn;
$cg->save();
}
//获取零售端在进行中的订单 ssh 20231201
public function actionGetLsRunningOrderNum()
{
$lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
$lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
}
//打印小票 ssh 20230608
public function actionPrintBill()
{
$get = Yii::$app->request->get();
$id = $get['id'] ?? 0;
$order = $get['order'] ?? 1;
$cg = PurchaseOrderClass::getById($id, true);
if (empty($cg)) {
util::fail('没有找到采购单');
}
if ($cg->mainId != $this->mainId) {
util::fail('没有权限');
}
if (getenv('YII_ENV') == 'production') {
//小向的采购单要打印二张
if ($this->mainId == 23390) {
PurchaseOrderClass::printTicket($cg, false, $order);
}
}
PurchaseOrderClass::printTicket($cg, false, $order);
util::complete();
}
//打印全部 ssh 20220602
public function actionPrintAll()
{
$get = Yii::$app->request->get();
$orderSn = $get['orderSn'] ?? 0;
$type = $get['type'] ?? 0;
$itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
if (empty($itemList)) {
util::fail('没有商品');
}
$order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
$mainId = $order->mainId ?? 0;
$ext = $this->shopExt;
$printLabelSn = $ext->printLabelSn ?? '';
if (empty($printLabelSn)) {
util::fail('请设置标签打印机');
}
$p = new printUtil($printLabelSn);
foreach ($itemList as $key => $item) {
$name = $item->name ?? '';
$num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
if (empty($num)) {
util::fail('没有花材数量');
}
$ptItemId = $item->itemId ?? '';
$productId = $item->productId ?? 0;
$p->times = $num;
$smallUnit = $item->smallUnit ?? '';
$bigUnit = $item->bigUnit ?? '';
$ratio = $item->ratio ?? 0;
$unit = $ratio . $smallUnit . '/' . $bigUnit;
if (isset($item->ratioType) && $item->ratioType == 1) {
$unit = '若干' . $smallUnit . '/' . $bigUnit;
}
if (stringUtil::getWordNum($name) > 7) {
$content = '' . $name . '';
} else {
$content = '' . $name . '';
}
if ($key % 2 == 1) {
$content .= '.';
}
if ($type == 0) {
$content .= '' . $ptItemId . '';
if (in_array($mainId, [52, 1459])) {
$content .= '惠雅鲜花';
} else {
$content .= '' . $unit . '';
}
} else {
$content .= '' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '';
$content .= '扫码看价格';
}
$p->printLabelMsg($content);
}
util::complete();
}
//打印全部 ssh 20220
public function actionPrintItem()
{
$get = Yii::$app->request->get();
$id = $get['id'] ?? 0;
$type = $get['type'] ?? 0;
$item = PurchaseOrderItemClass::getById($id, true);
if (empty($item)) {
util::fail('没有找到花材');
}
$name = $item->name ?? '';
$num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
if (empty($num)) {
util::fail('没有花材数量');
}
$orderSn = $item->orderSn ?? '';
$order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
$mainId = $order->mainId ?? 0;
$ext = $this->shopExt;
$printLabelSn = $ext->printLabelSn ?? '';
if (empty($printLabelSn)) {
util::fail('请设置标签打印机');
}
$p = new printUtil($printLabelSn);
$productId = $item->productId ?? 0;
$product = ProductClass::getById($productId, true);
$smallUnit = $product->smallUnit ?? '';
$bigUnit = $product->bigUnit ?? '';
$ratio = $product->ratio ?? 20;
$ratioType = $product->ratioType ?? 0;
if ($ratioType == 1) {
$unit = '若干' . $smallUnit . '/' . $bigUnit;
} else {
$unit = $ratio . $smallUnit . '/' . $bigUnit;
}
$ptItemId = $item->itemId ?? '';
$p->times = $num;
if (stringUtil::getWordNum($name) > 7) {
$content = '' . $name . '';
} else {
$content = '' . $name . '';
}
if ($type == 0) {
$content .= '' . $ptItemId . '';
if (in_array($mainId, [52, 1459])) {
$content .= '惠雅鲜花';
} else {
$content .= '' . $unit . '';
}
} else {
$content .= '' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '';
$content .= '扫码看价格';
}
$p->printLabelMsg($content);
util::complete();
}
//取消入库单 ssh 20221211
public function actionCancel()
{
$get = Yii::$app->request->get();
$id = $get['id'] ?? 0;
$cg = PurchaseOrderClass::getLockById($id);
if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
util::fail('请确认是否您的采购单');
}
if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
util::fail('已取消过了');
}
if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
util::fail('已入库,无法取消');
}
PurchaseOrderClass::cancel($cg);
util::complete();
}
//确认入库 sssh 20221211
public function actionConfirmPutIn()
{
ini_set('memory_limit', '2045M');
set_time_limit(0);
$shopAdmin = $this->shopAdmin;
if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
util::fail('超管才能修改');
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
$get = Yii::$app->request->get();
$id = $get['id'] ?? 0;
$cg = PurchaseOrderClass::getLockById($id);
if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
util::fail('请确认是否您的采购单');
}
$staff = $this->shopAdmin;
$data = [];
$data['staffId'] = $staff->id ?? 0;
$data['staffName'] = $staff->name ?? '';
$data['adminId'] = $this->adminId ?? 0;
$return = PurchaseOrderClass::putIn($cg, $data);
$transaction->commit();
util::success($return);
} catch (\Exception $e) {
$transaction->rollBack();
noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
Yii::error("确认入库失败,原因:" . $e->getMessage());
util::fail('确认失败');
}
}
//新增采购订单
public function actionCreateOrder()
{
ini_set('memory_limit', '2045M');
set_time_limit(0);
$post = Yii::$app->request->post();
$post['sjId'] = $this->sjId;
$post['shopId'] = $this->shopId;
$post['adminId'] = $this->adminId;
$post['mainId'] = $this->mainId;
$staff = $this->shopAdmin;
//以下二个都需要保留
$post['staffId'] = $staff->id ?? 0;
$post['staffName'] = $staff->name ?? '';
$post['shopAdminId'] = $staff->id ?? 0;
$post['shopAdminName'] = $staff->name ?? '';
$shopAdmin = $this->shopAdmin;
if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
util::fail('超管才能修改');
}
if (getenv('YII_ENV') == 'production') {
//小向花卉采购控制
if ($this->mainId == 23390) {
if (!in_array($this->adminId, [24586, 24115, 24759])) {
util::fail('你不能采购哦');
}
}
} else {
if ($this->mainId == 644) {
// if (!in_array($this->adminId, [919])) {
// util::fail('你不能采购哈');
// }
}
}
$shop = $this->shop;
$carSale = $shop->carSale ?? 0;
if ($carSale == 1) {
util::fail('车销不能采购');
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
// [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
$ghsItemInfo = $post['itemInfo'] ?? '';
if (empty($ghsItemInfo)) {
util::fail('请选择花材');
}
$ghsItemInfo = json_decode($ghsItemInfo, true);
if (!is_array($ghsItemInfo)) {
util::fail('花材格式不正确');
}
//合并
$ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
//判断花材格式,是否属于当前门店
ProductClass::valid($ghsItemInfo, $this->mainId);
$cgStaffId = $post['cgStaffId'] ?? 0;
if (empty($cgStaffId)) {
$mainId = $this->mainId;
if (getenv('YII_ENV') == 'production') {
//花大苪、鹏诚康乃馨 采购入库必须选择采购人
if (in_array($mainId, [8164, 19606])) {
util::fail('请选择采购人');
}
} else {
if (in_array($mainId, [])) {
util::fail('请选择采购人');
}
}
}
//获取供货商信息
$ghsId = $post['ghsId'];
if (empty($ghsId)) {
util::fail("请选择供货商");
}
$ghsInfo = GhsClass::getGhsInfo($ghsId);
GhsClass::valid($ghsInfo, $this->shopId);
$post['ghsInfo'] = json_encode($ghsInfo);
$post['ghsName'] = $ghsInfo['name'] ?? '';
$post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
//判断花材里的信息
foreach ($ghsItemInfo as $v) {
$bigNum = $v['bigNum'] ?? 0;
$productId = $v['productId'] ?? 0;
$smallNum = $v['smallNum'] ?? 0;
if (!isset($v['itemPrice'])) {
util::fail('采购价格不能为空');
}
if (!$productId) {
util::fail('花材不存在');
}
if ($bigNum <= 0 && $smallNum <= 0) {
util::fail('花材数量不能为0');
}
}
$post['itemInfo'] = $ghsItemInfo;
//0稍后入库 1直接入库
$inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
$debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
$post['debt'] = $debtStatus;
$order = PurchaseOrderClass::addOrder($post);
//如果是附近供货商,则采购单标记为外采单
if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
$order->location = 1;
$order->save();
}
if (isset($order->needPrint) && $order->needPrint == 1) {
PurchaseOrderClass::printTicket($order);
}
$transaction->commit();
util::success($order);
} catch (\Exception $e) {
$transaction->rollBack();
noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
Yii::error("操作失败原因:" . $e->getMessage());
util::fail('操作失败');
}
}
//订单列表
public function actionList()
{
$where = [];
$get = Yii::$app->request->get();
$where['shopId'] = $this->shopId;
$orderStatus = $get['status'] ?? '';
if ($orderStatus) {
$where['status'] = $orderStatus;
}
$ghsId = $get['ghsId'] ?? 0;
if (!empty($ghsId)) {
$where['ghsId'] = $ghsId;
}
$location = $get['location'] ?? '';
if (is_numeric($location)) {
$where['location'] = $location;
}
$data = PurchaseOrderClass::getOrderList($where);
//状态统计,很慢,暂时隐藏
//$statData = PurchaseOrderClass::statNum($this->shopId);
$statData = [
'allNum' => 0,
'unPayNum' => 0,
'unSendNum' => 0,
'sendingNum' => 0,
'finishNum' => 0,
];
$data = array_merge($data, $statData);
util::success($data);
}
//订单详情
public function actionDetail()
{
$orderSn = Yii::$app->request->get('orderSn', '');
$orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
util::success($orderData);
}
//修改备注
public function actionUpdateRemark()
{
$remark = Yii::$app->request->post('remark', '');
$id = Yii::$app->request->post('id', '');
$cg = PurchaseOrderClass::getById($id, true);
if (empty($cg)) {
util::fail('没有找到订单');
}
if ($cg->shopId != $this->shopId) {
util::fail('没有权限修改');
}
$cg->remark = $remark;
$cg->save();
util::complete('修改成功');
}
}