Qc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\WeChart;
  4. use EasyWeChat\Factory;
  5. use Firebase\JWT\JWT;
  6. use think\Db;
  7. class Qc extends Base {
  8. public function index()
  9. {
  10. $order_id = 1226;
  11. $user_info = Db::table('store_member')->find(41);
  12. $parent_info = Db::table('store_member')->find($user_info['pid']);
  13. $order_info = Db::table('goods_order')->find($order_id);
  14. $first_rate = intval(sysconf('first_rebate'));
  15. var_dump($first_rate,$order_info['price_total'],$order_info['price_total']*$first_rate/100);
  16. if($first_rate > 0) {
  17. $first_money = bcadd($parent_info['crystal'],$order_info['price_total']*$first_rate/100,2);
  18. Db::table('store_member')->where(['id'=>$user_info['pid']])
  19. ->update(['crystal'=>$first_money]);
  20. crystal_log($user_info['pid'],$first_money,'一级推荐线奖励',12,$order_id);
  21. }
  22. if($parent_info['pid'] > 0)
  23. {
  24. $grand = Db::table('store_member')->find($parent_info['pid']);
  25. $second_rate = intval(sysconf('second_rate'));
  26. if($second_rate > 0) {
  27. $second_money = bcadd($grand['crystal'],$order_info['price_total']*$second_rate/100,2);
  28. Db::table('store_member')->where(['id'=>$grand['pid']])
  29. ->update(['crystal'=>$second_money]);
  30. crystal_log($parent_info['pid'],$second_money,'二级推荐线奖励',13,$order_id);
  31. }
  32. }
  33. }
  34. /**
  35. *
  36. */
  37. public function getProfit()
  38. {
  39. $goods_id = input('goods_id');
  40. $where = [];
  41. $where[] = ['id','>',0];
  42. if($goods_id) $where[] = ['id','=',$goods_id];
  43. $goods_arr = Db::table('store_goods')
  44. ->where($where)
  45. ->order('id desc')
  46. ->select();
  47. $data = [];
  48. foreach ($goods_arr as $value)
  49. {
  50. $award = json_decode($value['spec'],true);
  51. $award_crystal = 0;
  52. $crystal = 0;
  53. foreach ($award as $av) {
  54. $award_crystal = bcadd($award_crystal,($av['base_num'] - $av['store_num']) * $av['crystal'] ,2);
  55. $crystal = bcadd($crystal,$av['base_num'] * $av['crystal'] ,2);
  56. }
  57. $cl = [
  58. 'goods_price' => $value['goods_price'],
  59. 'crystal' => $crystal,
  60. 'stock' => $value['stock'],
  61. 'award_crystal' => $award_crystal,
  62. 'sell_money' => bcmul($value['goods_price'],$value['base_stock']- $value['stock'],2),
  63. 'all_money' => bcmul($value['goods_price'],$value['base_stock'],2),
  64. 'profit' => bcmul($value['goods_price'],$value['base_stock']- $value['stock'],2) - $award_crystal,
  65. ];
  66. $data[$value['id']] = $cl;
  67. }
  68. $data[0] = [
  69. 'goods_price' => '--统计的--',
  70. 'stock' => '----',
  71. 'crystal' => array_sum(array_column($data,'crystal')),
  72. 'award_crystal' => array_sum(array_column($data,'award_crystal')),
  73. 'sell_money' =>array_sum(array_column($data,'sell_money')),
  74. 'all_money' => array_sum(array_column($data,'all_money')),
  75. 'profit' => array_sum(array_column($data,'profit')),
  76. ];
  77. var_dump([
  78. 'goods_price'=>'商品售价',
  79. 'crystal'=>'明信片成本',
  80. 'award_crystal'=>'已中明信片',
  81. 'sell_money'=>'已售金额',
  82. 'all_money'=>'售完金额',
  83. 'profit'=>'利润',
  84. ]);
  85. var_dump($data);
  86. }
  87. }