ShoppingLogic.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\mobile\logic;
  3. use app\model\AddrModel;
  4. use app\model\CommonModel;
  5. use app\model\CompanyGoodModel;
  6. use app\model\GoodModel;
  7. use app\model\GroupModel;
  8. use app\model\InventoryExchangeModel;
  9. use app\model\OrderModel;
  10. use think\Exception;
  11. use think\facade\Db;
  12. use think\response\Json;
  13. class ShoppingLogic extends BaseLogic
  14. {
  15. //商品列表
  16. public static function goodList(array $data = []): Json
  17. {
  18. $db = CompanyGoodModel::alias('a')
  19. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  20. ->leftJoin('inventory_shopping c', ' c.good_id=a.good_id')
  21. ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'b.type' => GoodModel::$type_shopping]);
  22. $count = $db->count('a.id');
  23. $list = $db
  24. ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,c.inventory,b.price')
  25. ->page($data['page'], $data['size'])
  26. ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
  27. ->select()
  28. ->toArray();
  29. return json_show(CommonModel::$success, '获取商城商品列表成功', ['count' => $count, 'list' => $list]);
  30. }
  31. //商品详情
  32. public static function goodInfo(string $code = ''): Json
  33. {
  34. $rs = CompanyGoodModel::alias('a')
  35. ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_code,b.good_name,b.moq,b.step,b.good_banner_img,b.good_img,b.good_param,b.status,c.inventory,d.unit,b.price')
  36. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  37. ->leftJoin('inventory_shopping c', 'c.good_id=a.good_id')
  38. ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
  39. ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
  40. ->withAttr('good_param', function ($val) {
  41. return json_decode($val, true);
  42. })
  43. ->withAttr('good_img', function ($val) {
  44. return explode(',', $val);
  45. })->withAttr('good_banner_img', function ($val) {
  46. return explode(',', $val);
  47. })
  48. ->findOrEmpty()
  49. ->toArray();
  50. return json_show(CommonModel::$success, '获取商城商品详情成功', $rs);
  51. }
  52. }