### 通过时尚顾问ID和日期计算业绩和提成
**位置:**
Common\Lib\UserLib;
**参数:**
* @param $uid 时尚顾问的Id
* @param $month 月份时间
**调用:**
* $user = new UserLib();
* $result = $user->createCommission($uid, $month);
**完整代码:**
~~~
/*
* 计算时尚顾问业绩和提成
* @param $uid 时尚顾问Id
* @param $month 月份时间
*
* @return bool 计算是否成功
*/
function createCommission ($uid, $month) {
//1、获取参数(计算时尚顾问销售业绩)
$days = date("t", strtotime($month)); //计算出某年某月的天数
$map['list.create_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
M()->startTrans();
//2、基于时尚顾问查询当月销售业绩
$map_results['sales_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
$map_results['is_delete'] = 0;
$map_results['sales_uid'] = $uid;
$results_sale = M('results_sales')
->field('id,sales_uid')
->where($map_results)
->select();
if (count($results_sale) < 1) {
return array('success' => false, 'code' => 201, 'msg' => '该月没有录入时尚顾问业绩目标!');
}
//3、统计时尚顾问销售业绩
foreach ($results_sale as $key => $value) {
// 增加一个判断结算方式是否伪删除的条件
$mapB['a.is_delete'] = array('eq', 0);
// 3是礼券的结算方式id,礼券是不能算业绩的
// $mapB['a.pay_id'] = array('neq',3);
$mapB['a.create_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
$mapB['a.sales_uid'] = $value['sales_uid'];
// 计算财务审核后得到每个小票单的业绩金额
$sales = M('order_sales as a')
->field('id,sales_money')
->where($mapB)
->select();
$sales_total = 0;
foreach ($sales as $k => $v) {
$sales_total += $v['sales_money'];
}
$save_sale = M('results_sales')
->where(array('id' => $value['id']))
->save(array('sales_total' => $sales_total));
if ($save_sale === false) {
M()->rollback();
return array('success' => false, 'code' => 201, 'msg' => '销售用户销售总金额保存失败');
}
}
//3、根据规则计算时尚顾问业绩提成
$where['list.create_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
$results_sale = M('results_sales')
->where($map_results)
->select();
foreach ($results_sale as $key => $value) {
$sales_describe = array();
$money_a = 0; //该类销售金额
$money_b = 0; //该类销售业绩
//2.1、循环计算时尚顾问完成率
$results_rate = $value['sales_total'] / $value['sales_target'];
//2.2、根据算的完成率查询适合的业绩计算规则
if ($results_rate >= 0.5 && $results_rate < 0.75) {
$results_rates = 0.5;
} elseif ($results_rate >= 0.75 && $results_rate < 1) {
$results_rates = 0.75;
} elseif ($results_rate >= 1 && $results_rate < 1.25) {
$results_rates = 1;
} elseif ($results_rate > 1.25) {
$results_rates = 1.25;
}
array_push($sales_describe, '个人业绩完成率为:' . $this->getPercent($results_rate));
$whereA['start_time'] = array('elt', strtotime(trim($month) . '-01'));
$whereA['end_time'] = array('egt', strtotime(trim($month) . '-' . $days));
$whereA['is_delete'] = 0;
$rule_list = M('results_rules')
->where($whereA)
->select();
foreach ($rule_list as $k => $v) {
$brang_name = $v['rule_name'];
//针对性的过滤
if (($results_rate < 0.5) && !in_array($brang_name, array('自由品牌', '设计师品牌'))) {
continue;
}
$brand_sum = 0; //记录每条规则业绩
$t_money = 0; //记录每条规则提成
$whereB = array();
$whereC = array();
$brands = json_decode($v['brand_id']);
$cat_ids = json_decode($v['cat_id']);
$percent = object_to_array(json_decode($v['percent']));
//针对性取提点
if (in_array($brang_name, array('自由品牌', '设计师品牌'))) {
$abs = '0.5';
$bai = $percent[$abs];
} else {
$abd = strval($results_rates);
$bai = $percent[$abd];
}
if ($v['is_in'] == 1) {
$is_in = 'in';
} elseif ($v['is_in'] == 2) {
$is_in = 'not in';
}
//有品牌的逻辑
if (count($brands) > 0) {
foreach ($brands as $kk => $vv) {
$a = '';
$string = '';
if (!empty($vv)) {
$whereB['a.brand_id'] = $vv;
$brand_name = get_brand_en($vv);
$a .= $brand_name;
}
if (!empty($cat_ids)) {
$cat_arr = array();
$is_ins = $v['is_in'] == 1 ? '包含' : '不包含';
$a .= $is_ins;
foreach ($cat_ids as $kkk => $vvv) {
if (!empty($vvv)) {
$cat_info = M('goods_category')
->where(array('id' => $vvv))
->find();
$whereB['e.level'] = $cat_info['level'];
array_push($cat_arr, $vvv);
$mall_obj = new MallLib();
$cat_name = $mall_obj->getChFullPath($vvv);
$a .= $cat_name;
}
}
$whereB['e.cat_id'] = array($is_in, $cat_arr);
}
$whereB['a.is_delete'] = 0;
$whereB['e.is_delete'] = 0;
$spu_ids = M('goods_spu as a')
->field('a.id')
->join('coscia_goods_spu_category as e on e.spu_id = a.id', 'left')
->where($whereB)
->select();
if (empty($spu_ids)) {
continue;
}
if (!empty($spu_ids)) {
$spu_where = array();
foreach ($spu_ids as $kk => $vv) {
array_push($spu_where, $vv['id']);
}
$whereC['a.spu_id'] = array('in', $spu_where);
}
//查询对应品牌和品类的销售业绩金额
$whereC['a.create_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
$whereC['b.sale_uid'] = $value['sales_uid'];
$whereC['b.order_status'] = array('not in', array(1, 6, 15, 16, 7));
$data = M('order_sku as a')
->field('a.sku_id,a.goods_num,a.subtotal,a.create_time')
->join('coscia_order_list as b on a.order_id = b.id', 'left')
->where($whereC)
->select();
//如果该分类没有销售记录就过掉
if (empty($data)) {
continue;
} else {
$string .= $a;
//该业绩规则销售金额汇总
$money_sum = 0;
foreach ($data as $kkk => $vvv) {
$money_sum += $vvv['subtotal'];
}
$money_a += $money_sum;
$brand_sum += $money_sum;
//计算该业绩规则下业绩提成
$money_result = round($money_sum * $bai, 2);
$money_b += $money_result;
$t_money += $money_result;
$string .= '销售业绩' . $money_sum . ',销售提成:' . $money_sum . '*' . ($bai * 100) . '%=' . $money_result;
array_push($sales_describe, $string);
}
}
} else {
if (!empty($cat_ids)) {
foreach ($cat_ids as $kkk => $vvv) {
$a = '';
$string = '';
$cat_arr = array();
$is_ins = $v['is_in'] == 1 ? '包含' : '不包含';
$a .= $is_ins;
if (!empty($vvv)) {
$cat_info = M('goods_category')
->where(array('id' => $vvv))
->find();
$whereB['e.level'] = $cat_info['level'];
array_push($cat_arr, $vvv);
$whereB['e.cat_id'] = array($is_in, $cat_arr);
$mall_obj = new MallLib();
$cat_name = $mall_obj->getChFullPath($vvv);
$a .= $cat_name;
}
$whereB['a.is_delete'] = 0;
$whereB['e.is_delete'] = 0;
$spu_ids = M('goods_spu as a')
->field('a.id')
->join('coscia_goods_spu_category as e on e.spu_id = a.id', 'left')
->where($whereB)
->select();
if (empty($spu_ids)) {
continue;
}
if (!empty($spu_ids)) {
$spu_where = array();
foreach ($spu_ids as $kk => $vv) {
array_push($spu_where, $vv['id']);
}
$whereC['a.spu_id'] = array('in', $spu_where);
}
//查询对应品牌和品类的销售业绩金额
$whereC['a.create_time'] = array('between', array(
strtotime($month), strtotime(trim($month) . '-' . $days . ' 23:59:59')));
$whereC['b.sale_uid'] = $value['sales_uid'];
$whereC['b.order_status'] = array('not in', array(1, 6, 15, 16, 7));
$data = M('order_sku as a')
->field('a.sku_id,a.goods_num,a.subtotal,a.create_time')
->join('coscia_order_list as b on a.order_id = b.id', 'left')
->where($whereC)
->select();
//如果该分类没有销售记录就过掉
if (empty($data)) {
continue;
} else {
$string .= $a;
//该业绩规则销售金额汇总
$money_sum = 0;
foreach ($data as $kkk => $vvv) {
$money_sum += $vvv['subtotal'];
}
$money_a += $money_sum;
$brand_sum += $money_sum;
//计算该业绩规则下业绩提成
$money_result = round($money_sum * $bai, 2);
$money_b += $money_result;
$t_money += $money_result;
$string .= '销售业绩' . $money_sum . ',销售提成:' . $money_sum . '*' . ($bai * 100) . '%=' . $money_result;
array_push($sales_describe, $string);
}
}
}
}
if ($brand_sum != 0) {
array_push($sales_describe, $brang_name . '总销售业绩:' . $brand_sum);
array_push($sales_describe, $brang_name . '总销售提成:' . $t_money);
array_push($sales_describe, '');
}
}
//把时尚顾问销售业绩信息存到销售业绩信息表
$save_sales = M('results_sales')
->where(array('id' => $value['id']))
->save(array('sales_amount' => $money_b, 'sales_describe' => json_encode($sales_describe)));
if ($save_sales === false) {
M()->rollback();
return array('success' => false, 'code' => 201, 'msg' => get_user_name($value['sales_uid'], 1) . '的业绩信息保存失败');
}
}
M()->commit();
return array('success' => true, 'code' => 200, 'msg' => '数据生成成功!');
}
~~~
- 模版
- 前言
- 项目架构
- 项目规范
- HTML
- CSS
- Javascript
- PHP
- MySQL
- 注意规范
- 开发版本管理
- 开发流程
- 系统配置
- 阿里云服务器配置
- 计划任务配置说明
- 开发示例
- Page分页
- Search_param搜索结果赋值
- Add新增
- Edit编辑
- Ajax表单验证
- Ajax二级联动
- Excel 导出数据首位不去0的方法
- POS总部控制
- 下载CSV格式的模板
- 订单唯一码表和订单SKU表实收金额生成
- 快捷日期选择
- JS函数
- ajax_send
- ajax_result
- createQrCodes
- createBarCodes
- printTpl
- JS插件
- BootstrapValidator表单验证插件
- Address省市区插件
- Bootstrap-datepicker日期插件
- Bootstrap-select多选框插件
- Toastr消息提示插件
- PalyAudit扫描声音提示插件
- WebUploader多图片上传插件
- Ueditor富文本编辑器插件
- Function
- alert
- object_to_array
- array_to_object
- get_address
- set_param_url
- get_shops_name
- get_user_name
- get_warehouse
- get_cheapest_sku
- print_attr(新)
- print_img(新)
- get_spu_no(新)
- get_type_name(新)
- get_brand_en(新)
- get_cat_name(新)
- get_attr_name(新)
- spu_cat_info(新)
- get_time_event_price
- get_vendors
- check_total_reduce
- check_total_discount
- get_inventory
- get_delivery
- get_sale_inventory
- get_customer_name
- phone_protection
- get_order_no
- get_event_name
- get_order_status
- get_item_status
- get_ditch_name
- get_card_no
- get_shop_sales
- get_pay_name
- get_season
- amt_format
- get_cat_parent
- print_attr_id
- round_bcadd
- round_bcsub
- round_bcmul
- round_bcdiv
- get_account_name
- Controller
- Common_BaseController
- check_membership_card
- get_menu_list
- importErrorMassage
- Wpos_IndexController
- get_customer_vip_card
- get_shops_id
- calculate_active_integral
- check_numbers_active
- check_goods_active
- Woms_IndexController
- Model
- View
- category
- cycle_date.html
- shop_select门店多选搜索框
- 品牌A-Z排序多选brand_mc.html
- 供应商代码A-Z排序vendor_no_mc.html
- Lib
- BuyerLib
- WarehouseLib
- EventLib
- getTimeEventPrice
- getVipType
- getEvent
- orderTotalEvent
- orderTimeEvent
- getTotalReduce
- getTotalDiscount
- SaleLib
- CustomerLib
- addCustomerService
- GiftcardLib
- WechatLib
- wxRefund
- OrdersLib
- orderLog
- calculatePayinAmount
- calculateSubtotal
- correctPayinAmount
- saveOrderAddress
- getOrderAddress
- setDeliveryNo
- SyncLib
- updateOuterStock
- UserLib
- createCommission
- FlowLib
- orderList
- addOrder
- addLog
- orderInfo
- checkSku
- orderSave
- orderStop
- orderExecute
- skuEdit
- orderPrinta
- scanGoods
- boxClose
- orderOut
- take
- bview
- check
- deliveryStatus
- checkGoods
- GoodsLib
- createGoodsNo
- createNewGoodsNo
- getSystemStyleNo
- getDim
- MallLib
- smsLog
- GoodsBaseLib
- getBrandInfo
- getBrandsInfo
- getAttrIdArray
- getPrintAttr
- getMustAttr
- getCatIdInfo
- valTypeId
- valsTypeId
- getCatNoInfo
- getCatInfo
- getAttrArr
- getAttrInfo
- getValInfo
- getAttrId
- getValId
- getAttrSeaon
- getValueId
- PointsLog
- pointsIn
- pointsUp
- EcGoodsLib
- getSkuInventory
- Tools
- CsvTools
- csvImport
- csvExport
- ExcelTools
- importExcel
- exportExcel
- exportHeadExcel
- MailTools
- SmsTools
- sendMessage
- UploadTools
- ExportTools
- exportData
- TaobaoTools
- getOnsaleItems
- getSkusItems
- PicturesTools
- uploadPicture
- Plugins
- WxBase
- Taobao
- 问题反馈