request->get();
$orderSn = $get['orderSn'] ?? 0;
$itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
if (empty($itemList)) {
util::fail('没有商品');
}
$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 ?? '';
$p->times = $num;
$smallUnit = $item->smallUnit ?? '';
$bigUnit = $item->bigUnit ?? '';
$ratio = $item->ratio ?? 0;
$unit = $ratio . $smallUnit . '/' . $bigUnit;
$content = '' . $name . '';
$content .= '' . $ptItemId . '';
if ($key % 2 == 1) {
$content .= '.';
}
$content .= '' . $unit . '';
$p->printLabelMsg($content);
}
util::complete();
}
//打印全部 ssh 20220
public function actionPrintItem()
{
$get = Yii::$app->request->get();
$id = $get['id'] ?? 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('没有花材数量');
}
$ext = $this->shopExt;
$printLabelSn = $ext->printLabelSn ?? '';
if (empty($printLabelSn)) {
util::fail('请设置标签打印机');
}
$p = new printUtil($printLabelSn);
$smallUnit = $item->smallUnit ?? '';
$bigUnit = $item->bigUnit ?? '';
$unit = $smallUnit . '/' . $bigUnit;
$ptItemId = $item->itemId ?? '';
$p->times = $num;
$content = '' . $name . '';
$content .= '' . $ptItemId . '';
$content .= '' . $unit . '';
$p->printLabelMsg($content);
util::complete();
}
//新增采购订单
public function actionCreateOrder()
{
$post = Yii::$app->request->post();
$post['sjId'] = $this->sjId;
$post['shopId'] = $this->shopId;
$post['adminId'] = $this->adminId;
$post['mainId'] = $this->mainId;
$shopAdmin = $this->shopAdmin;
if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
util::fail('超管才能修改');
}
// [{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);
//获取供应商信息
$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'] ?? '';
//判断花材里的信息
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;
$post['debt'] = PurchaseOrderClass::DEBT_YES;
$order = PurchaseOrderClass::addOrder($post);
util::success($order);
util::fail();
}
//订单列表
public function actionList()
{
$get = Yii::$app->request->get();
$orderStatus = $get['status'] ?? '';
if ($orderStatus) {
$where['status'] = $orderStatus;
}
$ghsId = $get['ghsId'] ?? 0;
if (!empty($ghsId)) {
$where['ghsId'] = $ghsId;
}
$where['sjId'] = $this->sjId;
$where['shopId'] = $this->shopId;
$data = PurchaseOrderClass::getOrderList($where);
//状态统计
$statData = PurchaseOrderClass::statNum($this->shopId);
$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('修改成功');
}
}