business.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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['originImgList'] = [];
  39. $info['imgList'] = ['normal' => '', 'middle' => ''];
  40. return $info;
  41. }
  42. $arr = json_decode($shopImg, true);
  43. //图片内容转化失败返回空
  44. if (is_array($arr) == false) {
  45. $info['originImgList'] = [];
  46. $info['imgList'] = ['normal' => '', 'middle' => ''];
  47. return $info;
  48. }
  49. $imgList = [];
  50. $prefixImgUrl = Yii::$app->params['imgUrl'];
  51. foreach ($arr as $imgUrl) {
  52. $middleImg = self::getMiddleImg($imgUrl);
  53. $normal = $prefixImgUrl . $imgUrl;
  54. $middle = $prefixImgUrl . $middleImg;
  55. $imgList[] = ['normal' => $normal, 'middle' => $middle];
  56. }
  57. $info['originImgList'] = $arr;
  58. $info['imgList'] = $imgList;
  59. return $info;
  60. }
  61. //对商品款式的转化 shish 2019.12.4
  62. public static function formatGoodsStyleImg($info)
  63. {
  64. $imgUrl = isset($info['picture']) ? $info['picture'] : '';
  65. if (empty($imgUrl)) {
  66. $info['imgList'] = ['normal' => '', 'middle' => ''];
  67. }
  68. $prefixImgUrl = Yii::$app->params['imgUrl'];
  69. $middleImg = self::getMiddleImg($imgUrl);
  70. $middle = $prefixImgUrl . $middleImg;
  71. $info['img'] = $middle;
  72. return $info;
  73. }
  74. //取中图 shish 2019.12.4
  75. public static function getMiddleImg($imgUrl)
  76. {
  77. $pos = strrpos($imgUrl, '.');
  78. $pre = substr($imgUrl, 0, $pos);
  79. $ext = substr($imgUrl, ($pos + 1));
  80. $middleImg = $pre . '_200.' . $ext;
  81. return $middleImg;
  82. }
  83. }