GoodsService.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace biz\goods\services;
  3. use biz\admin\services\AdminService;
  4. use biz\base\services\BaseService;
  5. use biz\goods\classes\GoodsCategoryClass;
  6. use biz\goods\classes\GoodsClass;
  7. use common\components\util;
  8. use Yii;
  9. use linslin\yii2\curl;
  10. class GoodsService extends BaseService
  11. {
  12. public static $baseFile = '\biz\goods\classes\GoodsClass';
  13. //后台列表 shish 2019.12.7
  14. public static function getGoodsList($where)
  15. {
  16. if (isset($where['cId'])) {
  17. $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC', 'goods');
  18. $list = [];
  19. if (isset($data['list']) && !empty($data['list'])) {
  20. foreach ($data['list'] as $val) {
  21. $list[] = $val['goods'];
  22. }
  23. }
  24. } else {
  25. $data = GoodsClass::getList('*', $where, 'inTurn DESC,updateTime DESC');
  26. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  27. }
  28. if (empty($list)) {
  29. return $data;
  30. }
  31. $data['list'] = GoodsClass::groupGoodsBaseInfo($list);
  32. return $data;
  33. }
  34. //获取商品完整详情,包括分类 shish 2019.12.3
  35. public static function getGoodsInfo($id)
  36. {
  37. return GoodsClass::getGoodsInfo($id);
  38. }
  39. //删除商品 shish 2019.12.7
  40. public static function deleteGoods($goods)
  41. {
  42. $id = $goods['id'];
  43. GoodsClass::updateById($id, ['delStatus' => 1]);
  44. GoodsCategoryClass::updateByCondition(['gId' => $id], ['delStatus' => 1]);
  45. }
  46. //添加商品 shish 2019.12.7
  47. public static function addGoods($data)
  48. {
  49. return GoodsClass::addGoods($data);
  50. }
  51. //更新商品 shish 2019.12.7
  52. public static function updateGoods($id, $data)
  53. {
  54. return GoodsClass::updateGoods($id, $data);
  55. }
  56. //验证对此商品的操作权限 shish 2019.12.7
  57. public static function valid($info, $merchantId)
  58. {
  59. if (empty($info)) {
  60. util::fail('没有找到商品');
  61. }
  62. if ($info['merchantId'] != $merchantId) {
  63. util::fail('您没有权限操作');
  64. }
  65. }
  66. //上下架 shish 2019.12.8
  67. public static function changeStatus($id, $status)
  68. {
  69. GoodsClass::changeStatus($id, $status);
  70. }
  71. }