123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\api\controller;
- use app\api\controller\WeChart;
- use EasyWeChat\Factory;
- use Firebase\JWT\JWT;
- use think\Db;
- class Qc extends Base {
- public function index()
- {
- $order_id = 1226;
- $user_info = Db::table('store_member')->find(41);
- $parent_info = Db::table('store_member')->find($user_info['pid']);
- $order_info = Db::table('goods_order')->find($order_id);
- $first_rate = intval(sysconf('first_rebate'));
- var_dump($first_rate,$order_info['price_total'],$order_info['price_total']*$first_rate/100);
- if($first_rate > 0) {
- $first_money = bcadd($parent_info['crystal'],$order_info['price_total']*$first_rate/100,2);
- Db::table('store_member')->where(['id'=>$user_info['pid']])
- ->update(['crystal'=>$first_money]);
- crystal_log($user_info['pid'],$first_money,'一级推荐线奖励',12,$order_id);
- }
- if($parent_info['pid'] > 0)
- {
- $grand = Db::table('store_member')->find($parent_info['pid']);
- $second_rate = intval(sysconf('second_rate'));
- if($second_rate > 0) {
- $second_money = bcadd($grand['crystal'],$order_info['price_total']*$second_rate/100,2);
- Db::table('store_member')->where(['id'=>$grand['pid']])
- ->update(['crystal'=>$second_money]);
- crystal_log($parent_info['pid'],$second_money,'二级推荐线奖励',13,$order_id);
- }
- }
- }
- /**
- *
- */
- public function getProfit()
- {
- $goods_id = input('goods_id');
- $where = [];
- $where[] = ['id','>',0];
- if($goods_id) $where[] = ['id','=',$goods_id];
- $goods_arr = Db::table('store_goods')
- ->where($where)
- ->order('id desc')
- ->select();
- $data = [];
- foreach ($goods_arr as $value)
- {
- $award = json_decode($value['spec'],true);
- $award_crystal = 0;
- $crystal = 0;
- foreach ($award as $av) {
- $award_crystal = bcadd($award_crystal,($av['base_num'] - $av['store_num']) * $av['crystal'] ,2);
- $crystal = bcadd($crystal,$av['base_num'] * $av['crystal'] ,2);
- }
- $cl = [
- 'goods_price' => $value['goods_price'],
- 'crystal' => $crystal,
- 'stock' => $value['stock'],
- 'award_crystal' => $award_crystal,
- 'sell_money' => bcmul($value['goods_price'],$value['base_stock']- $value['stock'],2),
- 'all_money' => bcmul($value['goods_price'],$value['base_stock'],2),
- 'profit' => bcmul($value['goods_price'],$value['base_stock']- $value['stock'],2) - $award_crystal,
- ];
- $data[$value['id']] = $cl;
- }
- $data[0] = [
- 'goods_price' => '--统计的--',
- 'stock' => '----',
- 'crystal' => array_sum(array_column($data,'crystal')),
- 'award_crystal' => array_sum(array_column($data,'award_crystal')),
- 'sell_money' =>array_sum(array_column($data,'sell_money')),
- 'all_money' => array_sum(array_column($data,'all_money')),
- 'profit' => array_sum(array_column($data,'profit')),
- ];
- var_dump([
- 'goods_price'=>'商品售价',
- 'crystal'=>'明信片成本',
- 'award_crystal'=>'已中明信片',
- 'sell_money'=>'已售金额',
- 'all_money'=>'售完金额',
- 'profit'=>'利润',
- ]);
- var_dump($data);
- }
- }
|