GoodsGiftcardType.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class GoodsGiftcardType extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'goods_giftcard_type';
  9. public static function getpcarray()
  10. {
  11. $where['weid'] = weid();
  12. $where['status'] = 1;
  13. $list = self::field('id,name')->where($where)
  14. ->order('sort asc')
  15. ->select()
  16. ->toArray();
  17. $array = [];
  18. foreach ($list as $k => $v) {
  19. $array[$k]['val'] = $v['id'];
  20. $array[$k]['key'] = $v['name'];
  21. }
  22. return $array;
  23. }
  24. public static function getbuy_price($id)
  25. {
  26. $data = self::find($id);
  27. if ($data) {
  28. return $data->buy_price;
  29. } else {
  30. return 0;
  31. }
  32. }
  33. public static function getidsbygoods($goods_id)
  34. {
  35. $weid = weid();
  36. $GiftcardTypequery = self::where('weid', $weid)->field('id');
  37. $GiftcardTypequery->where(function ($q) use ($goods_id) {
  38. $Goods = Goods::find($goods_id);
  39. if (!empty($Goods)) {
  40. $Goods = $Goods->toArray();
  41. $parentIds = Category::getParentIdsstr($Goods['cat_id']);
  42. $q->where('use_goods', 0)->whereOr('cat_ids', 'in', $parentIds)->whereOr('goods_ids', $goods_id);
  43. } else {
  44. $q->where('use_goods', 999);
  45. }
  46. });
  47. $dataidsarray = $GiftcardTypequery->select()->toArray();
  48. $returndata = '';
  49. foreach ($dataidsarray as $vo) {
  50. if($returndata){
  51. $returndata = $returndata . "," . $vo['id'];
  52. }else{
  53. $returndata = $vo['id'];
  54. }
  55. }
  56. return $returndata;
  57. }
  58. }