ExchangeLogic.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\mobile\logic;
  3. use app\model\CommonModel;
  4. use app\model\CompanyGoodModel;
  5. use app\model\GoodModel;
  6. use app\model\GroupModel;
  7. use think\response\Json;
  8. class ExchangeLogic extends BaseLogic
  9. {
  10. //商品列表
  11. public static function goodList(array $data = []): Json
  12. {
  13. $group_id = GroupModel::where(['is_del' => CommonModel::$del_normal, 'company_id' => self::$company_id, 'card_id' => self::$card_id])
  14. ->value('id', 0);
  15. if (!$group_id) return json_show(CommonModel::$error_param, '该账户所对应的分组不存在');
  16. $db = CompanyGoodModel::alias('a')
  17. ->leftJoin('good b', 'b.id=a.good_id AND b.type=' . GoodModel::$type_exchange . ' AND b.is_del=' . CommonModel::$del_normal)
  18. ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
  19. ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => $group_id]);
  20. $count = $db->count('a.id');
  21. $list = $db
  22. ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,c.inventory')
  23. ->page($data['page'], $data['size'])
  24. ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
  25. ->select()
  26. ->toArray();
  27. return json_show(CommonModel::$success, '获取兑换商品列表成功', ['count' => $count, 'list' => $list]);
  28. }
  29. //商品详情
  30. public static function goodInfo(string $code = ''): Json
  31. {
  32. $rs = CompanyGoodModel::alias('a')
  33. ->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')
  34. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  35. ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
  36. ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
  37. ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
  38. ->withAttr('good_param', function ($val) {
  39. return json_decode($val, true);
  40. })
  41. ->findOrEmpty()
  42. ->toArray();
  43. return json_show(CommonModel::$success, '获取兑换商品详情成功', $rs);
  44. }
  45. }