business.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * 通用业务
  4. * shish 2019.8.20
  5. */
  6. namespace common\components;
  7. use Yii;
  8. class business
  9. {
  10. //支付方式对应资金要保存的字段 shish 2019.8.20
  11. public static function savePayWayAmount($object, $amount, $payWay)
  12. {
  13. switch ($payWay) {
  14. case 0:
  15. $object->weixin += $amount;
  16. break;
  17. case 1:
  18. $object->alipay += $amount;
  19. break;
  20. case 2:
  21. $object->balancePay += $amount;
  22. break;
  23. case 3:
  24. $object->cash += $amount;
  25. break;
  26. default:
  27. util::fail('付款方式不存在');
  28. }
  29. return $object;
  30. }
  31. //对商品表shopImg字段的转化 shish 2019.12.2
  32. public static function formatGoodsImg($info)
  33. {
  34. $shopImg = isset($info['shopImg']) ? $info['shopImg'] : [];
  35. unset($info['shopImg']);
  36. //没有保存图片返回空
  37. if (empty($shopImg)) {
  38. $info['imgList'] = ['normal' => '', 'middle' => ''];
  39. return $info;
  40. }
  41. $arr = json_decode($shopImg, true);
  42. //图片内容转化失败返回空
  43. if (is_array($arr) == false) {
  44. $info['imgList'] = ['normal' => '', 'middle' => ''];
  45. return $info;
  46. }
  47. $imgList = [];
  48. $prefixImgUrl = Yii::$app->params['imgUrl'];
  49. foreach ($arr as $imgUrl) {
  50. $pos = strrpos($imgUrl, '.');
  51. $pre = substr($imgUrl, 0, $pos);
  52. $ext = substr($imgUrl, ($pos + 1));
  53. $middleImg = $pre . '_200.' . $ext;
  54. $normal = $prefixImgUrl . $imgUrl;
  55. $middle = $prefixImgUrl . $middleImg;
  56. $imgList[] = ['normal' => $normal, 'middle' => $middle];
  57. }
  58. $info['imgList'] = $imgList;
  59. return $info;
  60. }
  61. }