request->get('orderSn', '');
$info = PartClass::getByCondition(['orderSn' => $orderSn], true);
if ($info->mainId != $this->mainId) {
util::fail('没有权限');
}
$orderSn = $info->orderSn ?? '';
$orderInfo = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
$itemData = [];
if (!empty($orderInfo)) {
foreach ($orderInfo as $v) {
$shortCover = $v['cover'] ?? '';
$v['cover'] = imgUtil::groupImg($shortCover);
$itemData[] = $v;
}
}
util::success(['info' => $info, 'itemList' => $itemData]);
}
//列表
public function actionList()
{
$where = [];
$where['mainId'] = $this->mainId;
$list = PartClass::getPartList($where);
util::success($list);
}
//拆散花材 ssh 20230208
public function actionPartItem()
{
$post = Yii::$app->request->post();
$post['shopId'] = $this->shopId;
$post['sjId'] = $this->sjId;
$post['mainId'] = $this->mainId;
$post['shopAdminId'] = $this->shopAdminId;
$shopAdmin = $this->shopAdmin;
$adminName = $shopAdmin['name'] ?? '';
$post['shopAdminName'] = $adminName;
$productJson = $post['product'] ?? '';
if (empty($productJson)) {
util::fail('请选择花材');
}
$productList = json_decode($productJson, true);
if (empty($productList)) {
util::fail('请选择花材');
}
//有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
$hasUnitType = array_column($productList, 'unitType');
if (!empty($hasUnitType)) {
$newProductList = [];
foreach ($productList as $key => $val) {
$unitType = $val['unitType'] ?? 0;
$bigNum = 0;
$smallNum = 0;
$num = $val['num'] ?? 0;
$id = $val['productId'] ?? 0;
if ($unitType == dict::getDict('unitType', 'big')) {
$bigNum = $num;
} else {
$smallNum = $num;
util::fail('小单位不能拆散');
}
$newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
}
$productList = $newProductList;
}
foreach ($productList as $v) {
$bigNum = $v['bigNum'] ?? 0;
$smallNum = $v['smallNum'] ?? 0;
if ($bigNum <= 0) {
util::fail('数量不能为0');
}
if ($smallNum > 0) {
util::fail('仅支持整扎的拆散');
}
$property = $v['property'] ?? 1;
if ($property == 0) {
util::fail('暂不支持成品的拆散');
}
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
ProductClass::valid($productList, $this->mainId);
$post['product'] = $productList;
$post['ptStyle'] = dict::getDict('ptStyle', 'hd');
$return = PartClass::addOrder($post);
$transaction->commit();
util::success($return);
} catch (\Exception $e) {
$transaction->rollBack();
Yii::info("拆散失败原因:" . $e->getMessage());
util::fail('拆散保存失败');
}
}
//打印拆散订单
public function actionPrintOrder()
{
$get = Yii::$app->request->get();
$orderSn = $get['orderSn'] ?? '';
if (empty($orderSn)) {
util::fail('参数错误');
}
$info = PartClass::getByCondition(['orderSn' => $orderSn], true);
if (empty($info)) {
util::fail('没有找到拆散单');
}
if ($info->mainId != $this->mainId) {
util::fail('没有权限');
}
$itemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
if (empty($itemList)) {
util::fail('没有花材需要打印');
}
$shopId = $this->shopId;
$ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
$printSn = $ext->printSn ?? '';
$printKey = $ext->printKey ?? '';
if (empty($printSn) || empty($printKey)) {
util::success(['hasNoPrint' => 1]);
}
$shop = $this->shop;
$sj = $this->sj;
$sjName = $sj->name ?? '';
$shopName = $shop->shopName ?? '';
$currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
$kindNum = 0;
$totalNum = 0;
$content = "{$currentName}
";
$content .= "拆散单
";
$content .= '商品 数量
';
$content .= '--------------------------------
';
foreach ($itemList as $current) {
$name = $current['name'] ?? '';
$num = $current['itemNum'] ?? 0;
$content .= '' . $name . ' ' . floatval($num) . '扎' . "
";
$content .= '--------------------------------
';
$kindNum = bcadd($kindNum, 1);
$totalNum = bcadd($totalNum, $current['itemNum']);
}
if (!empty($info->remark)) {
$content .= '备注:' . $info->remark . '
';
}
$content .= '
';
$content .= '********************************
';
$content .= "共{$kindNum}种,{$totalNum}扎";
$content .= "";
$content .= '********************************
';
$content .= '
';
$content .= "订单编号:{$orderSn}
";
$content .= '拆散人员:' . ($info->shopAdminName ?? '') . '
';
$p = new printUtil($printSn);
$p->printMsg($content, $shop, $orderSn);
util::complete('打印成功');
}
}