CpLogic.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * MemberModel.php UTF-8
  4. * 玩家Model
  5. *
  6. * @date : 2017/11/18 17:18
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\member;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\CpModel;
  15. use huolib\constant\CommonConst;
  16. use huolib\constant\GameConst;
  17. class CpLogic extends CommonModel {
  18. public function getList() {
  19. $_model = (new CpModel())->select()->toArray();
  20. return $_model;
  21. }
  22. /**
  23. * 获取CP列表
  24. *
  25. * @param array $map
  26. * @param string $order
  27. * @param int $offset
  28. *
  29. * @return \think\Paginator
  30. * @throws \think\exception\DbException
  31. */
  32. public function getCpList($map = [], $order = 'id desc', $offset = 10) {
  33. $field = 'id, company_name, link_man, mobile, position, create_time, update_time';
  34. $_items = (new CpModel())->field($field)->where($map)->order($order)->paginate($offset);
  35. return $_items;
  36. }
  37. /**
  38. * 获取CP名称列表
  39. *
  40. * @param int $type 类型 1 CP 2 媒体
  41. *
  42. * @return array
  43. */
  44. public static function getNamesById($type = GameConst::CP_TYPE_CP) {
  45. $_map = [
  46. 'type' => $type,
  47. 'is_delete' => CommonConst::CONST_NOT_DELETE
  48. ];
  49. $_arr = (new CpModel())->where($_map)->order('id desc')->column('company_name name', 'id');
  50. return $_arr;
  51. }
  52. /***
  53. * 添加cp
  54. *
  55. * @param $param
  56. *
  57. * @param bool $return_id
  58. *
  59. * @return false|int
  60. */
  61. public function addCp($param, $return_id = false) {
  62. $_model = (new CpModel());
  63. $_rs = $_model->allowField(true)->save($param);
  64. if (true == $return_id) {
  65. return $_model->id;
  66. }
  67. return $_rs;
  68. }
  69. /**
  70. * @param $id
  71. *
  72. * @return array|false|\PDOStatement|string|\think\Model
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. */
  77. public function getCpById($id) {
  78. $_rs = (new CpModel())->where('id', $id)->find();
  79. return $_rs;
  80. }
  81. public function getCpNameById($id) {
  82. $_rs = (new CpModel())->where('id', $id)->value('company_name');
  83. return $_rs;
  84. }
  85. public function updateCp($id, $param) {
  86. $_rs = (new CpModel())->allowField(true)->save($param, ['id' => $id]);
  87. return $_rs;
  88. }
  89. /**
  90. * 获取指定CP名称
  91. *
  92. * @return array
  93. */
  94. public static function getNamesByData($where = []) {
  95. $_map = $where;
  96. $_map['is_delete'] = 2;
  97. $_arr = (new CpModel())->where($_map)->order('id desc')->column('company_name name', 'id');
  98. return $_arr;
  99. }
  100. }