getSellData_v1($start_time, $now_time, $store_id, $cashier_id); //出售商品统计数据 $result['goodsList'] = $res['goodsList']; $result['sumSellPrice'] = $res['sumSellPrice']; unset($res['goodsList']); $result['getSellData'] = $res; // $t_2 = mSecTime(); // $result['sql_time_getSellData'] = ($t_2 - $t_1) / 1000; // $t_1 = mSecTime(); $result['payList'] = $SellDataApi->getPayData_v1($start_time, $now_time, $store_id, $cashier_id); //支付方式总额统计数据 // $t_2 = mSecTime(); // $result['sql_time_getPayData'] = ($t_2 - $t_1) / 1000; $result['record_time'] = date('Y-m-d H:i:s', $start_time) . '~' . date('Y-m-d H:i:s', $now_time); //赊账数据统计 if (in_array('Credit', C('MODULE_ALLOW_LIST'))) { $CreditRecord = new \Credit\Business\CreditRecord(); $param['start_time'] = $start_time; $param['end_time'] = $now_time; $param['cashier_id'] = $cashier_id; $res = $CreditRecord->getCashierRecord($param); $result['credit_data'] = $res['data']; } //钱箱数据 $cash_box = $record['cash_box']; $result['cash_box'] = round($result['payList']['cash_amount'] + $result['payList']['recharge_cash_amount'] + $cash_box, 2); $result['status'] = 1; $result['msg'] = '统计数据获取成功'; $time2 = mSecTime(); $result['mini_time'] = ($time2 - $time1) / 1000; $this->ajaxReturn($result); } /** * 收银员下班 */ public function submitWork() { $WorkRecordModel = new WorkRecordModel(); $SellDataController = new SellDataController(); $record = self::$record; //上班记录 $start_time = $record['start_time']; //开始上班时间 $now_time = time(); //当前时间 $store_id = self::$store_id; $cashier_id = self::$cashier_id; $payList = $SellDataController->getPayData_v1($start_time, $now_time, $store_id, $cashier_id); $item = [ 'rmbpay' => $payList['cash_amount'], //现金支付总额 'wxpay' => $payList['weChat_amount'], //微信支付总额 'alipay' => $payList['ali_amount'], //支付宝支付总额 'vipcardpay' => $payList['vip_amount'], //会员卡支付总额 'other_pay' => $payList['other_amount'], //其他支付总额 'end_time' => $now_time, //交班时间 'recharge_cash' => $payList['recharge_cash_amount'], //会员现金充值 'recharge_wx' => $payList['recharge_weChat_amount'], //会员微信充值 'recharge_zfb' => $payList['recharge_ali_amount'], //会员支付宝充值 'jobnum' => self::$cashier['jobnum'], 'mec_money' => $payList['MoralEducationCoin'],//德育币金额 'recharge' => round($payList['recharge_cash_amount'] + $payList['recharge_weChat_amount'] + $payList['recharge_ali_amount'], 2), 'other_pay_json' => $payList['other_amount_array'] ? json_encode($payList['other_amount_array']) : '', ]; //赊账数据统计 if (in_array('Credit', C('MODULE_ALLOW_LIST'))) { $CreditRecord = new \Credit\Business\CreditRecord(); $param['start_time'] = $start_time; $param['end_time'] = $now_time; $param['cashier_id'] = $cashier_id; $creditInfo = $CreditRecord->getCashierRecord($param); $item['credit_arrea_money'] = $creditInfo['data']['arrearage_money']; $item['credit_repay_money'] = $creditInfo['data']['repayment_money']; } $update = $WorkRecordModel->updateOrder(['id' => $record['id']], $item); if ($update) { $result['status'] = 1; $result['msg'] = '交班成功'; } else { $result['status'] = 0; $result['msg'] = '交班失败'; } $this->ajaxReturn($result); } /** * wifi打印交班明细 */ public function printerRecordData_v1() { $cashier_name = self::$cashier['name']; //收银员名称 $store_name = self::$store['storetag']; //门店名称 $record = self::$record; //上班记录 $start_time = $record['start_time']; //开始上班时间 $now_time = time(); //当前时间 $SellDataController = new SellDataController(); $type = I('post.type') ? I('post.type') : 2; //是否打印明细 1打印 2不打印 默认不打印 $store_id = self::$store_id; $cashier_id = self::$cashier_id; $sellData = $SellDataController->getSellData_v1($start_time, $now_time, $store_id, $cashier_id); //出售商品统计数据 $goodsList = $sellData['goodsList']; $sumSellPrice = $sellData['sumSellPrice']; $payList = $SellDataController->getPayData_v1($start_time, $now_time, $store_id, $cashier_id); //支付方式总额统计数据 //钱箱数据 $cash_box = $record['cash_box']; $payList['cash_box'] = $payList['cash_amount'] + $payList['recharge_cash_amount'] + $cash_box; $record_time = date('Y-m-d H:i:s', $start_time) . '~' . date('Y-m-d H:i:s', $now_time); //交班时间 $store_id = self::$store_id; $Plug = new Plug(); $PlugData = $Plug->merPlugState([ 'merchant_id' => self::$cashier['merchantid'], 'identification_arr' => ['credit', 'moraleducationcoin'] ]); //插件权限 //赊账数据统计 if ($PlugData['credit']) { //判断门店是否开启赊账插件 $StoreConfig = new StoreConfigModel(); $is_credit = $StoreConfig->getFindField(['store_id' => $store_id], 'is_credit'); if ($is_credit == 1) { $CreditRecord = new \Credit\Business\CreditRecord(); $param['start_time'] = $start_time; $param['end_time'] = $now_time; $param['cashier_id'] = $cashier_id; $creditInfo = $CreditRecord->getCashierRecord($param); } } if ($PlugData['moraleducationcoin']) { //商户德育币插件设置是否禁用非德育币支付方式 $MerModel = new \MoralEducationCoin\Model\MoralEducationCoinMerModel(); $conf = $MerModel->getFind(['merchant_id' => self::$cashier['merchantid']], 'only_pay'); $only_mec_pay = $conf['only_pay'] != 1 ? 0 : 1; } else { $only_mec_pay = 0; } $PrinterModel = new RetailPrinterModel(); $map = [ 'storeid' => $store_id, 'status' => 2, ]; $printSet = $PrinterModel->getSelect($map); //根据传入的门店id,查询该门店是否配置打印机或已开启打印机 if (empty($printSet)) { $this->ajaxReturn(['status' => 0, 'msg' => '暂无可用WIFI打印机,请检查']); } /*飞蛾打印参数*/ $fContent[] = "交班凭条"; //title为自定义头部信息,如果没有显示门店名 $fContent[] = ""; $fContent[] = "交班人员:" . $cashier_name; $fContent[] = "交班时间:" . $record_time; $fContent[] = "交班门店:" . $store_name; if(!$only_mec_pay){ $fContent[] = "现金金额:" . $payList['cash_amount']; $fContent[] = "微信金额:" . $payList['weChat_amount']; $fContent[] = "支付宝金额:" . $payList['ali_amount']; } if(!$PlugData['moraleducationcoin']){ $fContent[] = "会员金额:" . $payList['vip_amount']; } if(!$only_mec_pay){ if (!$payList['other_amount_array']) { $fContent[] = "其他支付金额:" . $payList['other_amount']; } else { foreach ($payList['other_amount_array'] as $val) { $fContent[] = $val['name'] . ':' . $val['money']; } } } if(!$only_mec_pay){ $fContent[] = "会员充值(现金):" . $payList['recharge_cash_amount']; $fContent[] = "会员充值(微信):" . $payList['recharge_weChat_amount']; $fContent[] = "会员充值(支付宝):" . $payList['recharge_ali_amount']; $fContent[] = "会员充值赠送:" . $payList['recharge_give_amount']; $fContent[] = "钱箱金额:" . $payList['cash_box']; if ($is_credit == 1) { $fContent[] = "赊账金额:" . $creditInfo['data']['arrearage_money']; $fContent[] = "赊账还款金额:" . $creditInfo['data']['repayment_money']; } } /*易联云打印参数*/ $yContent = "
--交班凭条--
"; $yContent .= "" . "\n"; $yContent .= "交班人员:" . $cashier_name . "\n"; $yContent .= "交班时间:" . $record_time . "\n"; $yContent .= "交班门店:" . $store_name . "\n"; if(!$only_mec_pay) { $yContent .= "现金金额:" . $payList['cash_amount'] . "\n"; $yContent .= "微信金额:" . $payList['weChat_amount'] . "\n"; $yContent .= "支付宝金额:" . $payList['ali_amount'] . "\n"; } if(!$PlugData['moraleducationcoin']) { $yContent .= "会员金额:" . $payList['vip_amount'] . "\n"; } if(!$only_mec_pay) { if (!$payList['other_amount_array']) { $yContent .= "其他支付金额:" . $payList['other_amount'] . "\n"; } else { foreach ($payList['other_amount_array'] as $val) { $yContent .= $val['name'] . ':' . $val['money'] . "\n"; } } } if(!$PlugData['moraleducationcoin']) { $yContent .= "会员充值(现金):" . $payList['recharge_cash_amount'] . "\n"; $yContent .= "会员充值(微信):" . $payList['recharge_weChat_amount'] . "\n"; $yContent .= "会员充值(支付宝):" . $payList['recharge_ali_amount'] . "\n"; $yContent .= "会员充值赠送:" . $payList['recharge_give_amount'] . "\n"; $yContent .= "钱箱金额:" . $payList['cash_box'] . "\n"; if ($is_credit == 1) { $yContent .= "赊账金额:" . $creditInfo['data']['arrearage_money'] . "\n"; $yContent .= "赊账还款金额:" . $creditInfo['data']['repayment_money'] . "\n"; } } if (self::$cashier['salesdiction'] == 1 && $type == 1) { if (!empty($goodsList)) { $fContent[] = "销售明细"; $fContent[] = '******************************'; $yContent .= "销售明细" . "\n"; $yContent .= '******************************' . "\n"; foreach ($goodsList as $val) { $fContent[] = $val['class_name']; //分类名称 $fContent[] = "名称 数量 应收  实收"; $yContent .= $val['class_name'] . "\n"; //分类名称 $yContent .= "名称 数量 应收  实收" . "\n"; foreach ($val['goods'] as $v) { $fContent[] = $v['goods_name']; //商品名 $yContent .= $v['goods_name'] . "\n"; //商品名 $str = ''; if ($v['pricing_method'] == 1) { $str .= '  x' . str_pad(round($v['num'], 2), '6', ' ', STR_PAD_RIGHT); } else if ($v['pricing_method'] == 2) { $str .= '  x' . str_pad(round($v['num'], 2) . 'kg', '6', ' ', STR_PAD_RIGHT); } $str .= '' . str_pad($v['before_money'], '9', ' ', STR_PAD_RIGHT); $str .= '' . str_pad($v['all_money'], '9', ' ', STR_PAD_RIGHT); $fContent[] = $str; $yContent .= $str . "\n"; } $fContent[] = ""; $yContent .= "" . "\n"; } $fContent[] = '实收总金额: ' . $sumSellPrice['all_money']; $yContent .= "实收总金额: " . $sumSellPrice['all_money'] . "\n"; $fContent[] = '应收总金额: ' . $sumSellPrice['before_money']; $yContent .= "应收总金额: " . $sumSellPrice['before_money'] . "\n"; if(!$PlugData['moraleducationcoin']) { $fContent[] = '会员价已优惠: ' . $sumSellPrice['vip_less_money']; $yContent .= "会员价已优惠: " . $sumSellPrice['vip_less_money'] . "\n"; $fContent[] = '会员 折扣: ' . $sumSellPrice['vip_dis_money']; $yContent .= "会员 折扣: " . $sumSellPrice['vip_dis_money'] . "\n"; $fContent[] = '积分 抵扣: ' . $sumSellPrice['integral_money']; $yContent .= "积分 抵扣: " . $sumSellPrice['integral_money'] . "\n"; $fContent[] = '优 惠 券: ' . $sumSellPrice['coupon_money']; $yContent .= "优 惠 券: " . $sumSellPrice['coupon_money'] . "\n"; } $fContent[] = '收银员打折: ' . $sumSellPrice['cashier_dis_money']; $yContent .= "收银员打折: " . $sumSellPrice['cashier_dis_money'] . "\n"; $fContent[] = '收银员抹零: ' . $sumSellPrice['small_changes_money']; $yContent .= "收银员抹零: " . $sumSellPrice['small_changes_money'] . "\n"; $fContent[] = '******************************'; $yContent .= '******************************' . "\n"; } } $PrinterService = new PrinterController(); foreach ($printSet as $value) { if ($value['printer_type'] == 1) { //飞蛾打印 $PrinterService->fe_print($value['api_name'], $value['api_key'], $value['printer_sn'], implode('
', $fContent), 1); } else if ($value['printer_type'] == 2) { //易连云 $PrinterService->yly_print($value['api_name'], $value['api_key'], $value['printer_sn'], $yContent); } } $res['status'] = 1; $res['msg'] = '将开始打印'; $this->ajaxReturn($res); } /** * 设置钱箱初始金额 */ public function initCashBox() { $record = self::$record; $WorkRecordModel = new WorkRecordModel(); $cash_box = I('post.cash_box'); $item = [ 'cash_box' => $cash_box, 'cash_box_start' => $cash_box, ]; $update = $WorkRecordModel->updateOrder(['id' => $record['id']], $item); if ($update) { $result = [ 'status' => 1, 'msg' => '钱箱初始金额设置成功' ]; } else { $result = [ 'status' => 1, 'msg' => '钱箱初始金额暂未修改' ]; } $this->ajaxReturn($result); } /** * 收银端修改钱箱金额 * @param edit_money 修改金额 * @param type 修改类型 1增加 2减少 * @param remark 备注 */ public function editCashBox() { $record = self::$record; $money = I('post.edit_money'); $type = I('post.type'); $remark = I('post.remark'); if (!isset($money) || $money === '') { $this->ajaxReturn(['status' => 0, 'msg' => '缺少必要参数']); } $WorkRecordModel = new WorkRecordModel(); $CashBoxRecordModel = new CashBoxRecordModel(); // 更新钱箱金额 switch ($type) { case 1: $realCashMoney = bcadd($record['cash_box'], $money, 2); break; case 2: $realCashMoney = bcsub($record['cash_box'], $money, 2); break; default: $this->ajaxReturn(['status' => 0, 'msg' => '错误的修改类型']); break; } $WorkRecordModel->updateOrder(['id' => $record['id']], ['cash_box' => $realCashMoney]); $newRecordData = [ 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id, 'record_id' => $record['id'], 'operate_id' => self::$cashier_id, 'type' => $type, 'edit_money' => $money ? $money : 0, 'add_time' => time(), 'remark' => $remark, ]; // 添加修改记录 $recordAddRes = $CashBoxRecordModel->addOrder($newRecordData); $result['status'] = 1; if (!$recordAddRes) { $result['msg'] = '钱箱金额修改成功,记录添加失败'; } else { $result['msg'] = '钱箱金额修改成功'; } $this->ajaxReturn($result); } /** * 获取修改钱箱记录 * @param type 类型 1增加 2减少 * @param page 页码 * @param limit 页长 */ public function getCashEditRecord() { $id = self::$record['id']; if (!$id) { $this->ajaxReturn(['status' => 0, 'msg' => '缺少必要参数']); } $type = I('post.type'); $page = I('post.page') ? I('post.page') : 1; $limit = I('post.limit') ? I('post.limit') : 10; $CashBoxRecordModel = new CashBoxRecordModel(); $field = [ 'type', 'remark', 'add_time', 'operate_id', 'edit_money', ]; $map = ['record_id' => $id]; if ($type) { $map['type'] = $type; } $list = $CashBoxRecordModel->getSelect($map, $field, 'id desc', "{$page},{$limit}"); foreach ($list as &$val) { $val['add_time'] = date("Y-m-d H:i:s", $val['add_time']); $val['type_name'] = $val['type'] == 1 ? '增加' : '减少'; } $record = self::$record; $timeArr = date('Y-m-d H:i:s', $record['start_time']) . '-' . date('Y-m-d H:i:s'); $RetailPayOrderModel = new RetailPayOrderModel(); $rmbMap = [ 'cashier_id' => self::$cashier_id, 'add_time' => ['between', [$record['start_time'], time()]], 'order_state' => 'SUCCESS', 'scene_type' => 1, //付款订单 'pay_type' => 3, //现金 ]; $rmbpay = $RetailPayOrderModel->getSum($rmbMap, 'trade_amount'); $order_type1 = $RetailPayOrderModel->getGroupSelect($rmbMap, 'order_type', 'order_type'); $rmbMap['order_state'] = 'REFUND'; $rmbMap['scene_type'] = 2; $rmbpay_refund = $RetailPayOrderModel->getSum($rmbMap, 'trade_amount'); $order_type2 = $RetailPayOrderModel->getGroupSelect($rmbMap, 'order_type', 'order_type'); $result = [ 'status' => 1, 'msg' => empty($list) ? '暂无数据' : '获取成功', 'list' => $list ? $list : [], 'count' => $CashBoxRecordModel->getCount($map), 'cashMoney' => bcadd($record['cash_box'], $rmbpay - $rmbpay_refund, 2), 'timeArr' => $timeArr, '$order_type1' => $order_type1, '$order_type2' => $order_type2, ]; $this->ajaxReturn($result); } }