StatYjClass.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace bizGhs\stat\classes;
  3. use bizGhs\shop\classes\ShopAdminClass;
  4. use bizGhs\shop\models\ShopAdmin;
  5. use common\components\arrayUtil;
  6. use Yii;
  7. use bizGhs\base\classes\BaseClass;
  8. class StatYjClass extends BaseClass
  9. {
  10. public static $baseFile = '\bizGhs\stat\models\StatYj';
  11. //业绩列表 ssh 2021.3.15
  12. public static function getYjList($where)
  13. {
  14. $data = self::getList('*', $where, 'addTime DESC');
  15. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  16. if (empty($list)) {
  17. return $data;
  18. }
  19. $arr = [];
  20. foreach ($data['list'] as $key => $val) {
  21. $shopAdminId = $val['shopAdminId'];
  22. if (isset($arr[$shopAdminId]) == false) {
  23. $arr[$shopAdminId] = ['amount' => 0, 'num' => 0];
  24. }
  25. $arr[$shopAdminId]['amount'] = bcadd($val['amount'], $arr[$shopAdminId]['amount'], 2);
  26. $arr[$shopAdminId]['num'] = bcadd($val['num'], $arr[$shopAdminId]['num']);
  27. }
  28. $ids = array_keys($arr);
  29. $admin = ShopAdminClass::getByIds($ids);
  30. $show = [];
  31. foreach ($admin as $key => $val) {
  32. $adminId = $val['id'];
  33. $name = $val['name'] ?? '';
  34. $amount = $arr[$adminId]['amount'] ?? 0.00;
  35. $num = $arr[$adminId]['num'] ?? 0;
  36. $show[] = [
  37. 'name' => $name,
  38. 'amount' => $amount,
  39. 'num' => $num,
  40. 'id' => $val['id'],
  41. ];
  42. }
  43. //排序
  44. $show = arrayUtil::arraySort($show, 'amount');
  45. return ['list' => $show];
  46. }
  47. //增加业绩 ssh 2021.3.20
  48. public static function addYj($main, $shop, $shopAdminId, $amount, $date = null)
  49. {
  50. $sjId = $shop->sjId ?? 0;
  51. $mainId = $main->id ?? 0;
  52. $date = isset($date) ? $date : date("Ymd");
  53. $stat = self::getByCondition(['shopAdminId' => $shopAdminId, 'mainId' => $mainId, 'sjId' => $sjId, 'time' => $date], true);
  54. if (empty($stat)) {
  55. $stat = self::add(['sjId' => $sjId, 'shopAdminId' => $shopAdminId, 'mainId' => $mainId, 'time' => $date], true);
  56. }
  57. $stat->num += 1;
  58. $stat->totalNum += 1;
  59. $stat->amount = bcadd($amount, $stat->amount, 2);
  60. $stat->totalAmount = bcadd($amount, $stat->totalAmount, 2);
  61. $stat->save();
  62. StatYjMonthClass::addYj($main, $shop, $shopAdminId, $amount);
  63. }
  64. }