ajaxReturn(array( 'status' => 0, 'msg' => '请求错误', )); } $user = session('jurisdiction_user'); // if (empty($user)) { // $this->ajaxReturn(array('status' => 0, 'msg' => '请登录后再操作')); // } if (empty($user)) { $user = array( 'login_type' => 4, 'user_type' => 4, 'id' => 12, 'merchant_id' => 1, 'store_id' => 1, 'system_user_id' => 41, ); session('jurisdiction_user', $user); } $this->user = $user; } /** * 获取图片可选择的下拉框数据 */ public function getSelectClass() { $from_class = array(); $merchant_class = array(); $store_class = array(); $UICModel = new UploadImageClassModel(); $field = array('id', 'name'); switch ($this->user['login_type']) { case '1': //合伙人、或者合伙人下面的角色 $from_class = $UICModel->getSelect(array('user_type' => 1), $field); array_unshift($from_class, array('id' => 0, 'name' => '合伙人全部')); break; case '2': //代理商 $from_class = $UICModel->getSelect(array('user_type' => 2), $field); array_unshift($from_class, array('id' => 0, 'name' => '所有')); break; case '3': //商户+门店 $StoreModel = new RetailStoreModel(); $from_class = $StoreModel->getSelect(array('merchantid' => $this->user['merchant_id'], 'state' => 0), 'id,storetag as name'); array_unshift($from_class, array('id' => -1, 'name' => '商户')); array_unshift($from_class, array('id' => 0, 'name' => '所有')); $merchant_class = $UICModel->getSelect(array('user_type' => 3), $field); //商户 array_unshift($merchant_class, array('id' => 0, 'name' => '所有')); $store_class = $UICModel->getSelect(array('user_type' => 4)); //门店 array_unshift($store_class, array('id' => 0, 'name' => '所有')); break; case '4': //门店 $store_id = session('store_id'); $auth = M('retail_store_jurisdiction')->where(array('storeid' => $store_id))->find(); $from_class = $UICModel->getSelect(array('user_type' => 4), $field); //是否有查看商户图片权限 if ($auth['merchant_img_use'] == 1) { array_unshift($from_class, array('id' => -1, 'name' => '商户图片')); } array_unshift($from_class, array('id' => 0, 'name' => '所有')); break; } $res['from_class'] = $from_class; $res['merchant_class'] = $merchant_class; $res['store_class'] = $store_class; $res['status'] = 1; $res['msg'] = '获取成功'; $this->ajaxReturn($res); } /** * 获取图库图片 */ public function getGalleryImages() { $page = I('post.page'); $limit = I('post.limit'); $selectTypeC = I('post.selectTypeC'); $selectTypeD = I('post.selectTypeD'); $key = I('post.key'); $fileType = I('post.fileType'); if (!empty($key)) { $where['name|original_name'] = array('like', "%{$key}%"); } if (!empty($fileType)) { $where['type'] = $fileType; } $ImageGalleryModel = new ImageGalleryModel(); $ClassModel = new UploadImageClassModel(); switch ($this->user['login_type']) { case '1': //合伙人 if (!empty($selectTypeC)) { $where['from_type_id'] = $selectTypeC; } break; case '2': //代理商 $where['user_type'] = 2; if (!empty($selectTypeC)) { $where['from_type_id'] = $selectTypeC; } else { $ids = $ClassModel->getFindField(array('user_type' => 2), 'id', true); if (!empty($ids)) { $ids[] = 0; $where['from_type_id'] = array('in', $ids); } } $where['agent_id'] = $this->user['agent_id']; break; case '3': //商户 if ($selectTypeC == -1) { $where['merchant_id'] = $this->user['merchant_id']; if ($selectTypeD != '' && $selectTypeD != 0) { $where['from_type_id'] = $selectTypeD; } else { $ids = $ClassModel->getFindField(array('user_type' => 3), 'id', true); if (!empty($ids)) { $ids[] = 0; $where['from_type_id'] = array('in', $ids); } } } else if ($selectTypeC == 0) { //所有 $where['merchant_id'] = $this->user['merchant_id']; } else { //门店 $where['store_id'] = $selectTypeC; if ($selectTypeD != '' && $selectTypeD != 0) { $where['from_type_id'] = $selectTypeD; } } break; case '4': //门店 if ($selectTypeC == -1) { //商户图片 $where['merchant_id'] = $this->user['merchant_id']; $where['user_type'] = 3; } else if ($selectTypeC == 0) { //所有图片 $where['merchant_id'] = $this->user['merchant_id']; } else { //门店图片 $where['store_id'] = $this->user['store_id'];; $where['from_type_id'] = $selectTypeC; } break; case '5': //导购员 $where['user_type'] = 5; $where['guide_id'] = $this->user['system_user_id']; break; } $images = $ImageGalleryModel->getSelect($where, 'id,path,name,original_name,size,type,storage_type', 'id desc', $page, $limit); if ($images) { foreach ($images as &$val) { if ($val['add_time']) { $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); } if ($val['size']) { $val['size'] = getFileSize($val['size']); } $val['checked'] = false; if ($val['storage_type'] == 1) { $val['path'] = getServerUrl() . $val['path']; } unset($val['storage_type']); } $res['count'] = $ImageGalleryModel->getCount($where); $res['list'] = $images; $res['status'] = 1; $res['msg'] = '获取成功'; } else { $res['list'] = array(); $res['count'] = 0; $res['status'] = 1; $res['msg'] = '暂无数据'; } $this->ajaxReturn($res); } /** * 上传图片 */ public function uploadFile() { if (!$_FILES) { $res['status'] = 0; $res['msg'] = '未上传文件'; $this->ajaxReturn($res); } $selectTypeC = I('post.selectTypeC'); $selectTypeD = I('post.selectTypeD'); $fileType = I('post.fileType'); // if (!$selectTypeC || $this->user['login_type'] == 3 && !$selectTypeD) { // $res['status'] = 0; // $res['msg'] = '请选择图片上传类目'; // $this->ajaxReturn($res); // } if (!in_array($fileType, array('1', '2'))) { $res['status'] = 0; $res['msg'] = '请选择文件类型'; $this->ajaxReturn($res); } $item = array( 'add_time' => time(), 'user_type' => $this->user['login_type'], 'user_id' => $this->user['id'], 'type' => $fileType == 2 ? 2 : 1, 'limit_size' => $fileType == 1 ? 1024000 : 10240000, ); if ($this->user['login_type'] == 3) { $item['from_type_id'] = $selectTypeD; } else { $item['from_type_id'] = $selectTypeC; } $UploadImageClassModel = new UploadImageClassModel(); $uploadClass = $UploadImageClassModel->getFind(array('id' => $item['from_type_id'])); $item['localUrl'] = $uploadClass['directory']; switch ($this->user['login_type']) { case '1': //合伙人 break; case '2': //代理商 $item['agent_id'] = $this->user['agent_id']; break; case '3': //商户 $item['merchant_id'] = $this->user['merchant_id']; if ($selectTypeC > 0) { $item['store_id'] = $selectTypeC; } break; case '4': //门店 $item['merchant_id'] = $this->user['merchant_id']; $item['store_id'] = $this->user['store_id']; break; case '5': //导购员 $item['guide_id'] = $this->user['guide_id']; break; } $uploads = uploadFiles($item); if (!empty($uploads['file'])) { $res['file'] = $uploads; if (count($_FILES) == count($uploads)) { $res['status'] = 1; $res['msg'] = '上传成功'; } else { $res['status'] = 2; $res['msg'] = '部分成功'; } } else { $res['status'] = 0; $res['msg'] = $uploads['msg']; } $this->ajaxReturn($res); } /** * 获取操作权限 * 请求参数为对象 示例{"operate1":"/index.php/Retail/Test/test1","operate2":"/index.php/Retail/Test/test2"} * 返回值data为对象 示例{"operate1":true,"operate2":false} 注:true为有权限 false为无权限 */ public function checkOperateAuth() { $auth_list = I('post.auth_list'); try { $auth_list = json_decode($auth_list, true); if (is_array($auth_list)) { $auth = checkFunction($auth_list); $this->ajaxReturn(array( 'status' => 1, 'msg' => '获取成功', 'data' => $auth ? $auth : array(), )); } else { $this->ajaxReturn(array( 'status' => 0, 'msg' => '操作有误', )); } } catch (\Exception $exception) { $this->ajaxReturn(array( 'status' => 0, 'msg' => '操作有误1', )); } } /** * 获取门店商品列表供选择 */ public function getStoreGoodsList() { $merchant_id = $this->user['merchant_id']; if (!$merchant_id) { $this->ajaxReturn(array('status' => 0, 'msg' => '请登录后再操作')); } $MerchantClass = new Merchant(); $platform_type = $MerchantClass->getMerPlatFormType($merchant_id); //商户平台类型 if (I('post.store_id')) { $store_id = I('post.store_id'); } else { $store_id = session('store_id'); } $page = I('post.page'); $limit = I('post.limit'); $keyword = I('post.keyword'); $online_state = I('post.online_state'); $status = I('post.status'); $distribution_state = I('post.distribution');//是否是获取商品添加为分销商品 $GoodsModel = new RetailGoodsModel(); $map = array( 'merchant_id' => $merchant_id, 'status' => array('in', '0,1'), 'state' => 0, ); if ($store_id) { $map['store_id'] = $store_id; } if (isset($online_state) && $online_state !== '') { $map['online_state'] = $online_state; } if (isset($status) && $status !== '') { $map['status'] = $status; } if ($distribution_state == 1) { $plugModel = new Plug(); $PlugData = $plugModel->PlugPermissions([ 'merchant_id' => $merchant_id, 'identification_arr' => ['malldistribution'] ]); //分销插件权限 if (!empty($PlugData['data']['plug']['malldistribution'])) { $distribution = true; } else { $distribution = false; } if ($distribution) { $map['id'] = ['exp', "NOT IN (select ifnull (goods_id,0) from `ls_distribution_store` where merchant_id = " . $merchant_id . " and goods_status in (0,1))"]; } } if ($keyword) { $map['goods_name|goods_code|goods_number'] = array('like', "%{$keyword}%"); } $fields = array( 'id', 'goods_name', 'goods_code', 'goods_number', 'retail_price', 'online_price', 'online_state', 'attribute_state', 'goods_img_id', 'third_goods_code' ); $list = $GoodsModel->getSelect($map, $fields, 'id desc', "{$page},{$limit}"); $ImageGalleryModel = new ImageGalleryModel(); $InventoryApi = new \Api\Controller\InventoryController(); if (!empty($list)) { if ($platform_type == 2) { //Q3库存 $code_arr = []; $sku_code_arr = []; $sku_where = [ 'state' => 0, ]; $SkuGoodsModel = new RetailSkuGoodsModel(); } foreach ($list as &$val) { if ($platform_type == 2) { if ($val['attribute_state'] == 2) { $sku_where['goods_id'] = $val['id']; $sku_third_goods_code = $SkuGoodsModel->getFindField($sku_where, 'third_goods_code', true); $sku_code_arr[$val['id']] = $sku_third_goods_code; } else { $code_arr[$val['id']] = $val['third_goods_code']; } $val['goods_num'] = 0; } else { $val['goods_num'] = $InventoryApi->goods_num(2, $store_id, $val['id']); } $val['goods_img'] = $ImageGalleryModel->getImagePath($val['goods_img_id']); } if ($platform_type == 2 && (!empty($code_arr) || !empty($sku_code_arr))) { //Q3库存 $StoreModel = new RetailStoreModel(); $GoodsClass = new Goods(); $thirdResult = $GoodsClass->goodsNumQuery([ 'merchant_id' => $merchant_id, 'type' => 1, 'code_arr' => $code_arr, 'sku_code_arr' => $sku_code_arr, 'Customer_Codes' => $StoreModel->getFindField([ 'id' => $store_id ], 'third_code') ]); if ($thirdResult['status'] == 1 && !empty($thirdResult['data'])) { $stock = $thirdResult['data']; foreach ($list as &$val) { if (!empty($stock[$val['id']])) { $val['goods_num'] = $stock[$val['id']]; } } } } } $this->ajaxReturn(array( 'status' => 1, 'msg' => $list ? '获取成功' : '暂无数据', 'data' => $list, )); } /** * 获取门店商品总条数 */ public function getStoreGoodsCount() { $merchant_id = $this->user['merchant_id']; if (!$merchant_id) { $this->ajaxReturn(array('status' => 0, 'msg' => '请登录后再操作')); } if (I('post.store_id')) { $store_id = I('post.store_id'); } else { $store_id = session('store_id'); } $keyword = I('post.keyword'); $online_state = I('post.online_state'); $status = I('post.status'); $GoodsModel = new RetailGoodsModel(); $map = array( 'merchant_id' => $merchant_id, 'status' => array('in', '0,1'), ); if ($store_id) { $map['store_id'] = $store_id; } if (isset($online_state) && $online_state !== '') { $map['online_state'] = $online_state; } if (isset($status) && $status !== '') { $map['status'] = $status; } if ($keyword) { $map['goods_name|goods_code|goods_number'] = array('like', "%{$keyword}%"); } $count = $GoodsModel->getCount($map); $this->ajaxReturn(array( 'status' => 1, 'msg' => '获取成功', 'count' => $count, )); } /** * 获取零售购买商品订单详情 */ public function getOrderDetails() { $merchant_id = $this->user['merchant_id']; if (!$merchant_id) { $this->ajaxReturn(array('status' => 0, 'msg' => '请登录后再操作')); } $order_no = I('post.order_no'); $BillModel = new BillOrderViewModel(); $bMap = array( 'merchant_id' => $merchant_id, 'order_no' => strval($order_no), ); //查找订单 $order = $BillModel->getFind($bMap); if (empty($order)) { $this->ajaxReturn(array('status' => 0, 'msg' => '订单不存在')); } if ($order['type'] == 1 && $order['pickup_type'] == 1) { //商城订单并且自提 $order['user_address'] = '到店自提'; } if ($order['guide_id']) { $GuideModel = new RetailGuideModel(); $order['guide_name'] = $GuideModel->getFindField(array('id' => $order['guide_id']), 'guidename'); } $order['money_dis_integral'] = floatval($order['money_dis_integral']); //金额抵扣积分 $order['integral_dis_money'] = floatval($order['integral_dis_money']); //积分抵扣金额 $order['coupon_money'] = floatval($order['coupon_money']); //优惠券 $order['vip_dis_money'] = floatval($order['vip_dis_money']); //会员折扣优惠金额 $order['cashier_dis_money'] = floatval($order['cashier_dis_money']); //整单折扣优惠金额 $order['cashier_manual_money'] = floatval($order['cashier_manual_money']); //单品折扣优惠总金额 $order['small_changes_money'] = floatval($order['small_changes_money']); //抹零金额 $order['delivery_fee'] = floatval($order['delivery_fee']); //配送费 $order['amount_received'] = floatval($order['amount_received']); //应收 $order['zero_storage'] = floatval($order['zero_storage']); //存零 $order['give_change'] = floatval($order['give_change']); //找零 $order['user_select_time'] = $order['user_select_time'] ? date('Y-m-d H:i:s', $order['user_select_time']) : ''; //用户选择的时间 if ($order['type'] == 2 && $order['third_vip_code']) { $StoreModel = new RetailStoreModel(); $villageId = $StoreModel->getFindField(['id' => $order['store_id']], 'third_code'); $order['villageId'] = $villageId; } if ($order['order_genre'] == 4) { //预售 $AdvanceModel = new RetailBillAdvanceModel(); $aMap = array( 'bill_id' => $order['id'], ); $field = array( 'all_earnest_price', //定金 'all_arrive_price', //定金抵现 'advance_type', //1全额 2定金 'state', //1成功 0失败 'earnest_pay_time', //定金支付时间 'tail_end_time', //尾款结束时间 'tail_pay_order_id', //尾款结束时间 'refuse_earnest_price', //退款不退定金 0关闭 1开启 ); $advance = $AdvanceModel->getFind($aMap, $field); $order = array_merge($order, $advance); if ($order['advance_type'] == 2) { //定金 $order['earnest_pay_time'] = date('Y-m-d H:i:s', $order['earnest_pay_time']); $order['all_earnest_price'] = round($order['all_earnest_price'], 2); $order['all_arrive_price'] = $order['all_arrive_price'] ? round($order['all_arrive_price']) : ''; $order['tail_pay_money'] = bcsub($order['all_money'], $order['all_earnest_price'], 2); //尾款 $order['advance_type_name'] = "定金 + 尾款"; } else { //全额 $order['tail_pay_money'] = floatval($order['all_money']); $order['finish_time'] = date('Y-m-d H:i:s', $order['finish_time']); $order['advance_type_name'] = "全额"; } if ($order['state'] == 2) { $PayOrderModel = new RetailPayOrderModel(); $tail_time = $PayOrderModel->getFindField(array('id' => $order['tail_pay_order_id']), "trade_date"); $order['trade_date'] = date('Y-m-d H:i:s', $tail_time); } } if (!empty($order['vid'])) { $VipModel = new RetailVipModel(); $order['vip_info'] = $VipModel->getFind(['id' => $order['vid']], 'name,nickname,mobile_phone'); } //获取商品 $sMap = array( 'bill_id' => $order['id'], ); $SellModel = new RetailSellModel(); $sellOrder = $SellModel->getSelect($sMap); $AttributeApi = new SkuAttribute(); $SerialClass = new SerialNumberGoods(); foreach ($sellOrder as &$value) { $value['all_money'] = floatval($value['all_money']); // 总价 $value['price'] = floatval($value['price']); // 购买价格 $value['num'] = floatval($value['num']); //商品数量 $value['original_price'] = floatval($value['original_price']); // 原价 $value['vip_discount'] = floatval($value['vip_discount']); // 会员等级折扣 $value['vip_dis_money'] = floatval($value['vip_dis_money']); // 会员等级折扣金额 $value['integral_dis_money'] = floatval($value['integral_dis_money']); // 积分抵扣金额、金额抵扣积分 $value['cashier_manual_discount'] = $value['cashier_manual_discount'] * 1 == 1 ? 1 : floatval($value['cashier_manual_discount']); // 收银员单品打折折扣 $value['cashier_manual_discount_money'] = $value['cashier_manual_discount_money'] * 1 > 0 ? floatval($value['cashier_manual_discount_money']) : 0; // 单品折扣金额 $value['coupon_money'] = floatval($value['coupon_money']); // 优惠券金额 $value['cashier_dis_money'] = floatval($value['cashier_dis_money']); // 整单折扣金额 $value['small_changes_money'] = floatval($value['small_changes_money']); // 抹零金额 $value['use_integral'] = floatval($value['use_integral']); // 使用积分 $value['mem_integral'] = floatval($value['mem_integral']); // 换购所需积分 if ($value['pricing_method'] == 2) { $value['num'] = $value['num'] . ($value['company'] ? $value['company'] : 'kg'); } if (($value['goods_type'] == 2 || $value['goods_id'] == 0) && empty($value['goods_name'])) { $value['goods_name'] = '无码商品'; } if ($value['sku_json_info']) { $sku = json_decode($value['sku_json_info'], true); $value['sku_name'] = $sku['name']; if (empty($value['sku_name'])) { $sku_name = $AttributeApi->basisSkuIdListSkuNameArr($sku['sku_id_list']); $value['sku_name'] = implode(',', $sku_name); } } $value['goods_img'] = getImage($value['goods_img_id']); //串号信息 if ($value['serial_number_state'] == 1) { $value['serial_list'] = $SerialClass->sellSerialList([ 'id' => $value['id'] ])['data']['list']; } } $order['goodsList'] = $sellOrder; //订单获取祝福码 $storeId = $order['store_id']; $plugClass = new Plug(); $storePlugStatusPost = [ 'store_id' => $storeId, 'identification_arr' => ['blessing'], ]; $storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost); if ($storePlugStatus === true) { //门店有权限,并开启插件,查询订单是否有祝福码 $Index = new Index(); $order['extraction_code'] = $Index->obtainExtractionCode($order['id']); } else { $order['extraction_code'] = null; } $result['status'] = 1; $result['msg'] = '获取成功'; $result['data'] = $order; $this->ajaxReturn($result); } /** * 分别获取省市区数据 */ public function getProAndCityList() { $pid = I('post.pid') ? I('post.pid') : 0; $prov = M('citys')->where(array('parentid' => $pid))->select(); $this->ajaxReturn(array( 'status' => 1, 'msg' => '获取成功', 'data' => $prov, )); } /** * 获取商户分类 */ public function getGoodsClass() { $pid = I('post.pid'); $ClassApi = new GoodsClassify(); $param = array( 'pid' => $pid, 'merchant_id' => $this->user['merchant_id'], ); $list = $ClassApi->getAbsolutelyGoodsClass($param); $this->ajaxReturn(array( 'status' => 1, 'msg' => $list ? '获取成功' : '暂无数据', 'data' => $list ? $list : array(), )); } /** * 获取系统腾讯地图配置 */ public function getMapConf() { //腾讯地图ak $SystemSmsModel = new SystemSmsModel(); $type = I('post.type'); switch ($type) { case 1: $key = 'baidukeyid'; break; case 2: $key = 'tencent_key'; break; } $key = $SystemSmsModel->getField($key); if (!$key) { $this->ajaxReturn([ 'status' => 0, 'msg' => '系统暂未设置腾讯地图参数', ]); } else { $this->ajaxReturn([ 'status' => 1, 'msg' => '获取成功', 'data' => ['key' => $key], ]); } } /** * 获取新大陆联行信息 */ public function getXDLWcLBnkNo() { $keyword = I('post.keyword'); $precise = I('post.precise') == 1 ? true : false; $Api = new RetailPaySetController(); $res = $Api->getWcLbnkNo($keyword, $precise); $this->ajaxReturn($res); } /** * 获取系统银行列表 */ public function getSystemBank() { $list = M('bank')->field('id,bank_name')->cache(true, 86400)->select(); $this->ajaxReturn([ 'status' => 1, 'message' => '获取成功', 'data' => $list, ]); } }