Consult.php 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $role=$this->checkRole();
  59. if(!empty($role['write'])){
  60. $where[]=["b.createrid","in",$role['write']];
  61. }
  62. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  63. ->count();
  64. $total = ceil($count / $size);
  65. $page = $page >= $total ? $total : $page;
  66. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  67. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->order("a.id desc")->select();
  68. $data=[];
  69. foreach ($list as $value){
  70. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  71. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  72. true):[];
  73. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  74. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  75. $value['khname']="";
  76. if($value['khNo']!==""){
  77. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  78. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  79. }
  80. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  81. $data[]=$value;
  82. }
  83. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  84. }
  85. public function info(){
  86. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  87. if($id==""){
  88. return error_show(1002,"咨询单编号不能为空");
  89. }
  90. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  91. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  92. $fo['can']=$in;
  93. if(empty($fo)){
  94. return error_show(1002,"未找到咨询单编号");
  95. }else{
  96. return app_show(0,"获取成功",$fo);
  97. }
  98. }
  99. public function del(){
  100. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  101. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  102. if($de==false){
  103. return error_show(1002,'咨询单信息未找到');
  104. }
  105. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  106. if($dell){
  107. return error_show(0,"删除成功");
  108. }else
  109. return error_show(1002,"删除失败");
  110. }
  111. public function create(){
  112. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  113. if($is_project===""){
  114. return error_show(1002,"参数is_project不能为空");
  115. }
  116. if($is_project==1){
  117. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  118. if($projectNo===""){
  119. return error_show(1002,"参数projectNo不能为空");
  120. }
  121. }
  122. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  123. if($khNo===""){
  124. return error_show(1002,"参数khNo不能为空");
  125. }
  126. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  127. if($companyNo===""){
  128. return error_show(1002,"参数companyNo不能为空");
  129. }
  130. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  131. if($endtime===""){
  132. return error_show(1002,"参数endtime不能为空");
  133. }
  134. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  135. "";
  136. if($platform_code===""){
  137. return error_show(1002,"参数platform_code不能为空");
  138. }
  139. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  140. if($ladder==""){
  141. return error_show(1005,"参数ladder不能为空");
  142. }
  143. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  144. if($token==''){
  145. return error_show(105,"参数token不能为空");
  146. }
  147. $user =GetUserInfo($token);
  148. if(empty($user)||$user['code']!=0){
  149. return error_show(102,"用户数据不存在");
  150. }
  151. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  152. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  153. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  154. $zxNo=makeNo("ZX");
  155. Db::startTrans();
  156. try{
  157. $data=[
  158. "zxNo"=>$zxNo,
  159. "createrid"=>$createrid,
  160. "creater"=>$creater,
  161. "is_project"=>$is_project,
  162. "projectNo"=>isset($projectNo) ? $projectNo:"",
  163. "khNo"=>$khNo,
  164. "companyNo"=>$companyNo,
  165. "endtime"=>$endtime,
  166. "salesman"=>$creater,
  167. "platform_code"=>$platform_code,
  168. "saleid"=>$createrid,
  169. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  170. "status"=>0,
  171. "is_del"=>0,
  172. "addtime"=>date("Y-m-d H:i:s"),
  173. "updatetime"=>date("Y-m-d H:i:s"),
  174. ];
  175. $zx = Db::name("consult_order")->insert($data);
  176. if($zx){
  177. foreach ($ladder as $value){
  178. $infoNo=makeNo("IF");
  179. $specinfo=[];
  180. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  181. foreach ($value["specinfo"] as $v){
  182. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  183. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  184. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  185. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  186. $specinfo[]=$v;
  187. }
  188. }
  189. $info=[
  190. "infoNo"=>$infoNo,
  191. "zxNo"=>$zxNo,
  192. "spuCode"=>"",
  193. "good_name"=>$value['good_name'],
  194. "good_img"=>$value['good_img'],
  195. "cat_id"=>$value['cat_id'],
  196. "unit"=>$value['unit'],
  197. "brand_id"=>$value['brand_id'],
  198. "arrival_time"=>$value['arrival_time'],
  199. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  200. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  201. "is_addrs"=>$value['is_addrs'],
  202. "is_custom"=>$value['is_custom'],
  203. "metal_id"=>$value['metal_id'],
  204. "config"=>isset($value['config'])?$value['config']:"",
  205. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  206. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  207. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  208. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  209. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  210. "budget_price"=>$value['budget_price'],
  211. "num"=>$value['num'],
  212. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  213. "use_desc"=>$value['use_desc'],
  214. "remark"=>$value['remark'],
  215. "status"=>1,
  216. "is_del"=>0,
  217. "addtime"=>date("Y-m-d H:i:s"),
  218. "updatetime"=>date("Y-m-d H:i:s"),
  219. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  220. ];
  221. $up = Db::name("consult_info")->insert($info);
  222. if(!$up){
  223. Db::rollback();
  224. return error_show(1004,'添加失败');
  225. }else{
  226. //修改状态,添加待办
  227. ActionLog::logAdd($this->post['token'], [
  228. "order_code" => $infoNo,//咨询单详情编号
  229. "status" => 1,//这里的status是之前的值
  230. "action_remark" => '',//备注
  231. "action_type" => "create"//新建create,编辑edit,更改状态status
  232. ], "ZXD", 1, $info);
  233. // ProcessOrder::AddProcess($this->post['token'], [
  234. // "order_type" => 'ZXD',
  235. // "order_code" => $infoNo,//咨询单详情编号
  236. // "order_id" => 0,
  237. // "order_status" => 1
  238. // ]);
  239. }
  240. }
  241. Db::commit();
  242. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  243. }else{
  244. Db::rollback();
  245. return error_show(1004,"新建失败");
  246. }
  247. }catch (\Exception $e){
  248. Db::rollback();
  249. return error_show(1003,$e->getMessage());
  250. }
  251. }
  252. public function zxinfo(){
  253. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  254. if($infoNo==""){
  255. return error_show(1004,"参数infoNo不能为空");
  256. }
  257. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  258. if($zxinfo==false){
  259. return error_show(1004,"未找到信息数据");
  260. }
  261. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  262. if($zxorder==false){
  263. return error_show(1004,"未找到咨询信息数据");
  264. }
  265. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  266. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  267. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  268. $zxinfo['khname']="";
  269. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  270. $zxinfo['khNo']="";
  271. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  272. $zxinfo['brand']="";
  273. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  274. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  275. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  276. $zxinfo['company']="";
  277. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  278. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  279. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  280. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  281. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  282. $zxinfo['project_name']="";
  283. $zxinfo['budget_total']="";
  284. $zxinfo['departinfo']=[];
  285. $zxinfo['unit_name']="";
  286. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  287. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  288. if($zxorder['khNo']!==""){
  289. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  290. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  291. $zxinfo['khNo']= $zxorder['khNo'];
  292. }
  293. if($zxinfo['unit']!==""){
  294. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  295. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  296. }
  297. if($zxinfo['brand_id']!==""){
  298. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  299. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  300. }
  301. if($zxorder['companyNo']!==""){
  302. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  303. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  304. }
  305. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  306. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  307. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  308. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  309. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  310. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  311. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  312. }
  313. if($zxorder['depart']>0){
  314. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  315. }
  316. if($zxorder['platform_code']>0){
  317. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  318. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  319. }
  320. return app_show(0,"获取成功",$zxinfo);
  321. }
  322. public function zxedit(){
  323. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  324. if($infoNo==""){
  325. return error_show(1004,"参数infoNo不能为空");
  326. }
  327. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  328. if($zxinfo==false){
  329. return error_show(1004,"未找到信息数据");
  330. }
  331. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  332. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  333. if($good_name==""){
  334. return error_show(1003,"参数good_name不能为空");
  335. }
  336. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  337. if($good_img==""){
  338. return error_show(1003,"参数good_img不能为空");
  339. }
  340. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  341. if($cat_id==""){
  342. return error_show(1003,"参数cat_id不能为空");
  343. }
  344. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  345. if($unit==""){
  346. return error_show(1003,"参数unit不能为空");
  347. }
  348. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  349. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  350. if($arrival_time==""){
  351. return error_show(1003,"参数arrival_time不能为空");
  352. }
  353. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  354. if($specin==""){
  355. return error_show(1003,"参数specinfo不能为空");
  356. }
  357. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  358. // if($cost_desc==""){
  359. // return error_show(1003,"参数cost_desc不能为空");
  360. // }
  361. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  362. if($is_addrs===""){
  363. return error_show(1003,"参数is_addrs不能为空");
  364. }
  365. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  366. if($is_custom===""){
  367. return error_show(1003,"参数is_custom不能为空");
  368. }
  369. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  370. if($metal_id===""){
  371. return error_show(1003,"参数metal_id不能为空");
  372. }
  373. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  374. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  375. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  376. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  377. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  378. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  379. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  380. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  381. if($num===""){
  382. return error_show(1003,"参数num不能为空");
  383. }
  384. if($budget_price===""){
  385. return error_show(1003,"参数budget_price不能为空");
  386. }
  387. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  388. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  389. if($use_desc==""){
  390. return error_show(1003,"参数use_desc不能为空");
  391. }
  392. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  393. if($remark==""){
  394. return error_show(1003,"参数remark不能为空");
  395. }
  396. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  397. if($endtime==""){
  398. return error_show(1003,"参数endtime不能为空");
  399. }
  400. if($metal_id!=0){
  401. if($config==""){
  402. return error_show(1003,"参数config不能为空");
  403. }
  404. if($other_config==""){
  405. return error_show(1003,"参数other_config不能为空");
  406. }
  407. if($specs_weight===""){
  408. return error_show(1003,"参数specs_weight不能为空");
  409. }
  410. if($gold_price===""){
  411. return error_show(1003,"参数gold_price不能为空");
  412. }
  413. }
  414. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  415. if($token==''){
  416. return error_show(102,"参数token不能为空");
  417. }
  418. $user =GetUserInfo($token);
  419. if(empty($user)||$user['code']!=0){
  420. return error_show(105,"用户数据不存在");
  421. }
  422. $specinfo=[];
  423. foreach ($specin as $v){
  424. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  425. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  426. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  427. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  428. $specinfo[]=$v;
  429. }
  430. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  431. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  432. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  433. Db::startTrans();
  434. try{
  435. $innew =makeNo("IF");
  436. $info=[
  437. "infoNo"=>$innew,
  438. "zxNo"=>$zxinfo['zxNo'],
  439. "spuCode"=>"",
  440. "good_name"=>$good_name,
  441. "good_img"=>$good_img,
  442. "cat_id"=>$cat_id,
  443. "unit"=>$unit,
  444. "brand_id"=>$brand_id,
  445. "arrival_time"=>$arrival_time,
  446. "specinfo"=>json_encode($specinfo),
  447. // "color"=>$color,
  448. // "material"=>$material,
  449. "cost_desc"=>$cost_desc,
  450. "is_addrs"=>$is_addrs,
  451. "is_custom"=>$is_custom,
  452. "metal_id"=>$metal_id,
  453. "config"=>$config,
  454. "other_config"=>$other_config,
  455. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  456. "gold_price"=>$gold_price===""? 0 : $gold_price,
  457. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  458. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  459. "budget_price"=>$budget_price,
  460. "num"=>$num,
  461. "pgNo"=>$pgNo,
  462. "use_desc"=>$use_desc,
  463. "remark"=>$remark,
  464. "status"=>1,
  465. "is_del"=>0,
  466. "addtime"=>date("Y-m-d H:i:s"),
  467. "updatetime"=>date("Y-m-d H:i:s"),
  468. 'bargain_status'=>1,
  469. 'enclosure_file'=>$enclosure_file
  470. ];
  471. $up = Db::name("consult_info")->insert($info);
  472. if($up){
  473. //操作记录
  474. ActionLog::logAdd($this->post['token'], [
  475. "order_code" => $innew,//咨询单详情编号
  476. "status" => 1,//这里的status是之前的值
  477. "action_remark" => '',//备注
  478. "action_type" => "edit"//新建create,编辑edit,更改状态status
  479. ], "ZXD", 1, $this->post);
  480. // ProcessOrder::AddProcess($this->post['token'], [
  481. // "order_type" => 'ZXD',
  482. // "order_code" => $innew,//咨询单详情编号
  483. // "order_id" => 0,
  484. // "order_status" => 1
  485. // ]);
  486. if (!empty($bidlist)){
  487. foreach ($bidlist as $value){
  488. unset($value['id']);
  489. $value['infoNo']=$innew;
  490. $value['bidNo']=makeNo("BD");
  491. $value['spuCode']=makeNo("SKU");
  492. $value['status'] =0;
  493. $value['updatetime'] =date("Y-m-d H:i:s");
  494. $in = Db::name("consult_bids")->insert($value);
  495. if($in==false){
  496. Db::rollback();
  497. return error_show(1004,"反馈商品新建失败");
  498. }
  499. ActionLog::logAdd($this->post['token'], [
  500. "order_code" => $innew,//咨询单详情编号
  501. "status" => 1,//这里的status是之前的值
  502. "action_remark" => '',//备注
  503. "action_type" => "edit"//新建create,编辑edit,更改状态status
  504. ], "FKD", 1, $this->post);
  505. }
  506. }
  507. $zxinfo["bargain_status"] =1;
  508. $zxinfo["bargain_code"] =$innew;
  509. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  510. $bar=Db::name("consult_info")->save($zxinfo);
  511. if($bar==false){
  512. Db::rollback();
  513. return error_show(1004,"反馈商品更新失败");
  514. }else{
  515. //修改状态,添加待办
  516. ActionLog::logAdd($this->post['token'], [
  517. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  518. "status" => $zxinfo['status'],//这里的status是之前的值
  519. "action_remark" => '',//备注
  520. "action_type" => "edit"//新建create,编辑edit,更改状态status
  521. ], "ZXD", $zxinfo['status'], $zxinfo);
  522. }
  523. //更新consule_order记录
  524. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  525. 'updatetime'=>date('Y-m-d H:i:s')]);
  526. if($op==false){
  527. Db::rollback();
  528. return error_show(1004,'咨询单结束时间更新失败');
  529. }
  530. Db::commit();
  531. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  532. }
  533. }catch (\Exception $e){
  534. Db::rollback();
  535. return error_show(1004,$e->getMessage());
  536. }
  537. }
  538. //** 发布竞标任务 */
  539. public function bargain(){
  540. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  541. if($infoNo==""){
  542. return error_show(1004,"参数infoNo不能为空");
  543. }
  544. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  545. if($zxinfo==false){
  546. return error_show(1004,"未找到信息数据");
  547. }
  548. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  549. if($status===""){
  550. return error_show(1004,"参数status不能为空");
  551. }
  552. // if($status==1&&$zxinfo['status']>1){
  553. // $zxinfo['bargain_num']=+1;
  554. // }
  555. $old_zxinfo_status = $zxinfo['status'];
  556. $zxinfo['status']=$status;
  557. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  558. $up = Db::name("consult_info")->save($zxinfo);
  559. if($up){
  560. //修改状态,添加待办
  561. ActionLog::logAdd($this->post['token'], [
  562. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  563. "status" => $old_zxinfo_status,//这里的status是之前的值
  564. "action_remark" => '',//备注
  565. "action_type" => "status"//新建create,编辑edit,更改状态status
  566. ], "ZXD", $zxinfo['status'], $zxinfo);
  567. return app_show(0,"状态更新成功");
  568. }else{
  569. return error_show(1003,"状态更新失败");
  570. }
  571. }
  572. //反馈商品添加
  573. public function feadback(){
  574. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  575. if($infoNo==""){
  576. return error_show(1002,"参数infoNo不能为空");
  577. }
  578. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  579. if($zxinfo==false){
  580. return error_show(1003,"未找到信息数据");
  581. }
  582. if($zxinfo['status']!=1){
  583. return error_show(1004,"任务未进行");
  584. }
  585. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  586. if($zx==false){
  587. return error_show(1003,"未找咨询信息数据");
  588. }
  589. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  590. if($pname==""){
  591. return error_show(1002,"参数pname不能为空");
  592. }
  593. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  594. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  595. if($cat_id==""){
  596. return error_show(1002,"参数cat_id不能为空");
  597. }
  598. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  599. if($specin==""){
  600. return error_show(1003,"参数specinfo不能为空");
  601. }
  602. $specinfo=[];
  603. foreach ($specin as $v){
  604. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  605. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  606. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  607. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  608. $specinfo[]=$v;
  609. }
  610. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  611. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  612. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  613. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  614. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  615. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  616. :"";
  617. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  618. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  619. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  620. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  621. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  622. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  623. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  624. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  625. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  626. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  627. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  628. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  629. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  630. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  631. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  632. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  633. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  634. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  635. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  636. if($nake_fee==="" ){
  637. return error_show(1004,"参数nake_fee不能为空");
  638. }
  639. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  640. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  641. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  642. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  643. if($delivery_place==''){
  644. return error_show(1002,"参数delivery_place不能为空");
  645. }
  646. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  647. if($token==''){
  648. return error_show(1002,"参数token不能为空");
  649. }
  650. $user =GetUserInfo($token);
  651. if(empty($user)||$user['code']!=0){
  652. return error_show(1005,"用户数据不存在");
  653. }
  654. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  655. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  656. $bidNo=makeNo("BD");
  657. $spucode=makeNo("SKU");
  658. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  659. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  660. //部分参数的大小校验
  661. $vali = Validate::rule([
  662. 'expire_day|有效时长'=>'require|elt:214748364',
  663. 'delivery_day|物流时长'=>'require|elt:214748364',
  664. 'work_day|生产工期'=>'require|elt:214748364',
  665. 'weight|总重量'=>'require|max:10',
  666. ]);
  667. $temp = [
  668. 'expire_day'=>$expire_day,
  669. 'delivery_day'=>$delivery_day,
  670. 'work_day'=>$work_day,
  671. 'weight'=>$weight,
  672. ];
  673. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  674. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  675. $cat_top_list = made($cat_id);
  676. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  677. if ($is_gold_price == 1 && $cat_top_id == 6) {
  678. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  679. ->find();
  680. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  681. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  682. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  683. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  684. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  685. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  686. $saleprice = $total_fee/ (1 - $budget);
  687. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  688. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  689. }else{
  690. if($nake_fee){
  691. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  692. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  693. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  694. }else{
  695. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  696. (1 - $budget);
  697. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  698. }
  699. }
  700. $data=[
  701. "bidNo"=>$bidNo,
  702. "infoNo"=>$infoNo,
  703. "zxNo"=>$zxinfo['zxNo'],
  704. "spuCode"=>$spucode,
  705. "good_name"=>$pname,
  706. "brand_id"=>$brandid,
  707. "cat_id"=>$cat_id,
  708. "specinfo"=>json_encode($specinfo),
  709. "unit_id"=>$unit_id,
  710. "cost_desc"=>$cost_desc,
  711. "work_day"=>$work_day,
  712. "delivery_day"=>$delivery_day,
  713. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  714. "expire_day"=>$expire_day,
  715. "origin_place"=>$origin_place,
  716. "supplierNo"=>$supplierNo,
  717. "pay_way"=>$pay_way,
  718. "tax"=>$tax,
  719. "send_way"=>$send_way,
  720. "metal_id"=>$metal_id,
  721. "is_gold_price"=>$is_gold_price,
  722. "config"=>$config,
  723. "other_config"=>$other_config,
  724. "weight"=>$weight,
  725. "good_weight"=>$good_weight,
  726. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  727. "is_diff"=>$is_diff,
  728. "demo_fee"=>$demo_fee,
  729. "delivery_fee"=>$delivery_fee,
  730. "open_fee"=>$open_fee,
  731. "pakge_fee"=>$pakge_fee,
  732. "nake_fee"=>$nake_fee,
  733. "mark_fee"=>$mark_fee,
  734. "cert_fee"=>$cert_fee,
  735. "cost_fee"=>$cost_fee,
  736. "total_fee"=>$total_fee,
  737. "supply_area"=>$supply_area,
  738. "remark"=>$remark,
  739. "sale_price"=>$saleprice,
  740. "sale_cost_fee"=>$sale_cost_fee,
  741. "origin_cost_fee"=>$sale_cost_fee,
  742. "origin_price"=>$saleprice,
  743. "createrid"=>$createrid,
  744. "creater"=>$creater,
  745. "status"=>$zxinfo['status']==1 ?1 :2,
  746. "is_del"=>0,
  747. "addtime"=>date("Y-m-d H:i:s"),
  748. "updatetime"=>date("Y-m-d H:i:s"),
  749. 'delivery_place'=>$delivery_place//发货地
  750. ];
  751. Db::startTrans();
  752. try{
  753. $insert= Db::name("consult_bids")->insert($data);
  754. if($insert){
  755. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  756. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  757. if($projectinfo==false){
  758. Db::rollback();
  759. return error_show(1006,"未找到项目信息");
  760. }
  761. $temp=[];
  762. $temp['spuCode']=$spucode;
  763. $temp['skuCode']="";
  764. $temp['pgNo']=$zxinfo['pgNo'];
  765. $temp['projectNo']=$zx['projectNo'];
  766. $temp['good_name']=$pname;
  767. $temp['good_type']=$projectinfo['good_type'];
  768. $temp['data_source']=2;
  769. $temp['cat_id']=$cat_id;
  770. $temp['budget_price']=$projectinfo['budget_price'];
  771. $temp['sale_price']=$saleprice;
  772. $temp['origin_price']=$total_fee;
  773. $temp['num']=$zxinfo['num'];
  774. $temp['status']=0;
  775. $temp['is_del']=0;
  776. $temp['creater']=$creater;
  777. $temp['createrid']=$createrid;
  778. $temp['addtime']=date("Y-m-d H:i:s");
  779. $temp['updatetime']=date("Y-m-d H:i:s");
  780. $nu = Db::name("project_feedback")->insert($temp);
  781. if($nu==false){
  782. Db::rollback();
  783. return error_show(1006,"项目反馈失败");
  784. }else{
  785. $old_projectinfo_status = $projectinfo['status'];
  786. $projectinfo['status']=2;
  787. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  788. $up = Db::name("project_info")->save($projectinfo);
  789. if($up){
  790. //修改状态,添加待办,只记录动作
  791. ActionLog::logAdd($this->post['token'], [
  792. "order_code" => $projectinfo['pgNo'],//编码
  793. "status" => $old_projectinfo_status,//这里的status是之前的值
  794. "action_remark" => '',//备注
  795. "action_type" => "status"//新建create,编辑edit,更改状态status
  796. ], "PRI", 2, $projectinfo);
  797. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  798. ->count();
  799. if($count==0){
  800. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  801. if($projetc!=false){
  802. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  803. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  804. if($proc==false){
  805. Db::rollback();
  806. return error_show(1006,"项目反馈失败");
  807. }else{
  808. //修改状态,添加待办
  809. ActionLog::logAdd($this->post['token'], [
  810. "order_code" => $projetc['projectNo'],//项目编码
  811. "status" => 1,//这里的status是之前的值
  812. "action_remark" => '',//备注
  813. "action_type" => "status"//新建create,编辑edit,更改状态status
  814. ], "PRO", 2, $projetc);
  815. ProcessOrder::AddProcess($this->post['token'], [
  816. "order_type" => 'PRO',
  817. "order_code" => $projetc['projectNo'],
  818. "order_id" => $projetc['id'],
  819. "order_status" => 2,"before_status"=>1
  820. ]);
  821. }
  822. }
  823. }
  824. }
  825. }
  826. }
  827. Db::commit();
  828. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  829. }else{
  830. Db::rollback();
  831. return error_show(1006,"反馈失败");
  832. }
  833. }catch (\Exception $e){
  834. Db::rollback();
  835. return error_show(1006,$e->getMessage());
  836. }
  837. }
  838. //反馈商品详情
  839. public function feadinfo(){
  840. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  841. if($bidNo==""){
  842. return error_show(1004,"参数bidNo不能为空");
  843. }
  844. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  845. if($info==false){
  846. return error_show(1004,"未找到商品数据");
  847. }
  848. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  849. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  850. $info['cat_info'] = made($info['cat_id'],[]);
  851. $info['noble_weight'] = $info['good_weight'];
  852. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  853. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  854. if($info['brand_id']!=0){
  855. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  856. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  857. }else{
  858. $info["brand_name"]="";
  859. $info["brand_id"]="";
  860. }
  861. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  862. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  863. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  864. $god=[
  865. "metal_id"=>$info['metal_id'],
  866. "weight"=>$info["good_weight"],
  867. "demo_fee"=>$info["demo_fee"],
  868. "delivery_fee"=>$info["delivery_fee"],
  869. "open_fee"=>$info["open_fee"],
  870. "packing_fee"=>$info["pakge_fee"],
  871. "mark_fee"=>$info["mark_fee"],
  872. "nake_fee"=>$info["nake_fee"],
  873. "cert_fee"=>$info["cert_fee"],
  874. "cost_fee"=>$info["cost_fee"],
  875. "num"=>$bidinfo["num"],
  876. ];
  877. if($info['is_gold_price']==1){
  878. $price = GoldPrice($god, $budget/100);
  879. $info['sale_price'] =round($price,2);
  880. }
  881. $info['specinfo'] = json_decode($info['specinfo'],true);
  882. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  883. if($info['delivery_place']!=""){
  884. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  885. }
  886. $info['delivery_place_cn']=GetAddr(json_encode($place));
  887. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  888. if($info['origin_place']!=""){
  889. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  890. }
  891. $info['origin_place_cn']=GetAddr(json_encode($place));
  892. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  893. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  894. $info['bargain'] =$bargain;
  895. $info['good_img'] = explode(',',$info['good_img']);
  896. return app_show(0,"获取成功",$info);
  897. }
  898. //反馈商品编辑
  899. public function feededit(){
  900. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  901. if($bidNo==""){
  902. return error_show(1002,"参数bidNo不能为空");
  903. }
  904. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  905. if($bidinfo==false){
  906. return error_show(1003,"未找到信息数据");
  907. }
  908. if($bidinfo['status']>=5){
  909. return error_show(1004,"咨询单已确认无法修改");
  910. }
  911. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  912. if($zxinfo==false){
  913. return error_show(1003,"未找到信息数据");
  914. }
  915. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  916. if($zx==false){
  917. return error_show(1003,"未找咨询信息数据");
  918. }
  919. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  920. if($pname==""){
  921. return error_show(1002,"参数pname不能为空");
  922. }
  923. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  924. // if($brandid==""){
  925. // return error_show(1002,"参数brandid不能为空");
  926. // }
  927. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  928. if($cat_id==""){
  929. return error_show(1002,"参数cat_id不能为空");
  930. }
  931. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  932. if($specin==""){
  933. return error_show(1003,"参数specinfo不能为空");
  934. }
  935. $specinfo=[];
  936. foreach ($specin as $v){
  937. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  938. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  939. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  940. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  941. $specinfo[]=$v;
  942. }
  943. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  944. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  945. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  946. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  947. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  948. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  949. :"";
  950. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  951. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  952. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  953. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  954. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  955. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  956. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  957. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  958. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  959. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  960. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  961. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  962. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  963. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  964. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  965. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  966. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  967. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  968. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  969. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  970. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  971. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  972. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  973. if($delivery_place==''){
  974. return error_show(1002,"参数delivery_place不能为空");
  975. }
  976. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  977. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  978. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  979. $cat_top_list = made($cat_id);
  980. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  981. if ($is_gold_price == 1 && $cat_top_id == 6) {
  982. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  983. ->find();
  984. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  985. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  986. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  987. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  988. $saleprice = $total_fee / (1 - $budget);
  989. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  990. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  991. }else{
  992. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  993. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  994. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  995. }
  996. Db::startTrans();
  997. try{
  998. $data=[
  999. "good_name"=>$pname,
  1000. "brand_id"=>$brandid,
  1001. "cat_id"=>$cat_id,
  1002. "specinfo"=>json_encode($specinfo),
  1003. // "material"=>$material,
  1004. "unit_id"=>$unit_id,
  1005. "cost_desc"=>$cost_desc,
  1006. "work_day"=>$work_day,
  1007. "delivery_day"=>$delivery_day,
  1008. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1009. "expire_day"=>$expire_day,
  1010. "origin_place"=>$origin_place,
  1011. "supplierNo"=>$supplierNo,
  1012. "pay_way"=>$pay_way,
  1013. "tax"=>$tax,
  1014. "send_way"=>$send_way,
  1015. "metal_id"=>$metal_id,
  1016. "is_gold_price"=>$is_gold_price,
  1017. "config"=>$config,
  1018. "other_config"=>$other_config,
  1019. "weight"=>$weight,
  1020. "good_weight"=>$noble_weight,
  1021. "is_diff"=>$is_diff,
  1022. "demo_fee"=>$demo_fee,
  1023. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1024. "delivery_fee"=>$delivery_fee,
  1025. "open_fee"=>$open_fee,
  1026. "pakge_fee"=>$pakge_fee,
  1027. "nake_fee"=>$nake_fee,
  1028. "mark_fee"=>$mark_fee,
  1029. "cert_fee"=>$cert_fee,
  1030. "cost_fee"=>$cost_fee,
  1031. "sale_cost_fee"=>$sale_cost_fee,
  1032. "origin_cost_fee"=>$sale_cost_fee,
  1033. "total_fee"=>$total_fee,
  1034. "sale_price"=>$saleprice,
  1035. "origin_price"=>$saleprice,
  1036. "supply_area"=>$supply_area,
  1037. "remark"=>$remark,
  1038. "status"=>0,
  1039. "updatetime"=>date("Y-m-d H:i:s"),
  1040. 'delivery_place' => $delivery_place
  1041. ];
  1042. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1043. if($insert){
  1044. if($zxinfo['bargain_status']==1){
  1045. $zxinfo['bargain_status']=0;
  1046. $infoip =Db::name("consult_info")->save($zxinfo);
  1047. if($infoip==false){
  1048. Db::rollback();
  1049. return error_show(1006,"咨询信息状态更新失败");
  1050. }
  1051. }
  1052. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1053. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1054. if($projectinfo==false){
  1055. Db::rollback();
  1056. return error_show(1006,"未找到项目信息");
  1057. }
  1058. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1059. if($feed==false){
  1060. Db::rollback();
  1061. return error_show(1006,"未找到项目反馈信息");
  1062. }
  1063. $feed['good_name']=$pname;
  1064. $feed['good_type']=$projectinfo['good_type'];
  1065. $feed['cat_id']=$cat_id;
  1066. $feed['sale_price']=$saleprice;
  1067. $feed['origin_price']=$total_fee;
  1068. $feed['updatetime']=date("Y-m-d H:i:s");
  1069. $temp['updatetime']=date("Y-m-d H:i:s");
  1070. $nu = Db::name("project_feedback")->save($feed);
  1071. if($nu==false){
  1072. Db::rollback();
  1073. return error_show(1006,"项目反馈失败");
  1074. }else{
  1075. $old_projectinfo_status = $projectinfo['status'];
  1076. $projectinfo['status']=2;
  1077. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1078. $up = Db::name("project_info")->save($projectinfo);
  1079. if($up){
  1080. //修改状态,添加待办,只记录动作
  1081. ActionLog::logAdd($this->post['token'], [
  1082. "order_code" => $projectinfo['pgNo'],//编码
  1083. "status" => $old_projectinfo_status,//这里的status是之前的值
  1084. "action_remark" => '',//备注
  1085. "action_type" => "status"//新建create,编辑edit,更改状态status
  1086. ], "PRI", 2, $projectinfo);
  1087. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->count();
  1088. if ($count == 0) {
  1089. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1090. $project_id = Db::name("project")->where(["projectNo" => $projectinfo['projectNo'], "status" => 1])->value('id', 0);
  1091. if ($project_id) {
  1092. $proc = Db::name("project")->where(["id" => $project_id])->update(["status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1093. if ($proc == false) {
  1094. Db::rollback();
  1095. return error_show(1006, "项目反馈失败");
  1096. }else{
  1097. //修改状态,添加待办
  1098. ActionLog::logAdd($this->post['token'], [
  1099. "order_code" => $projectinfo['projectNo'],//项目编码
  1100. "status" => 1,//这里的status是之前的值
  1101. "action_remark" => '',//备注
  1102. "action_type" => "status"//新建create,编辑edit,更改状态status
  1103. ], "PRO", 2, $this->post);
  1104. ProcessOrder::AddProcess($this->post['token'], [
  1105. "order_type" => 'PRO',
  1106. "order_code" => $projectinfo['projectNo'],
  1107. "order_id" => $project_id,
  1108. "order_status" => 2,"before_status"=>1
  1109. ]);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116. Db::commit();
  1117. return app_show(0,"编辑成功");
  1118. }else{
  1119. Db::rollback();
  1120. return error_show(1004,"编辑失败");
  1121. }
  1122. }catch (\Exception $e){
  1123. Db::rollback();
  1124. return error_show(1004,$e->getMessage());
  1125. }
  1126. }
  1127. public function bargain_add(){
  1128. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1129. if($bidNo===""){
  1130. return error_show(1004,"参数bidNo不能为空");
  1131. }
  1132. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1133. if($info==false){
  1134. return error_show(1004,"未找到商品数据");
  1135. }
  1136. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1137. if($consult==false){
  1138. return error_show(1004,"未找到咨询数据");
  1139. }
  1140. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1141. if($bargain_price===""){
  1142. return error_show(1004,"参数bargain_price不能为空");
  1143. }
  1144. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1145. if($info['is_gold_price']==1){
  1146. if($cost_price==""){
  1147. return error_show(1004,"参数cost_price不能为空");
  1148. }
  1149. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1150. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1151. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1152. ->find();
  1153. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1154. }
  1155. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1156. // if($bargain_reason===""){
  1157. // return error_show(1004,"参数bargain_reason不能为空");
  1158. // }
  1159. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1160. if($infos==false){
  1161. return error_show(1004,"未找到商品数据");
  1162. }
  1163. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1164. return error_show(1004,"咨询单招标未结束或已确认商品");
  1165. }
  1166. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1167. if($token==''){
  1168. return error_show(105,"参数token不能为空");
  1169. }
  1170. $user =GetUserInfo($token);
  1171. if(empty($user)||$user['code']!=0){
  1172. return error_show(1002,"用户数据不存在");
  1173. }
  1174. //新增两个字段
  1175. //议价备注
  1176. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1177. //议价原因id
  1178. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1179. if ($result_info_id != '') {
  1180. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1181. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1182. }
  1183. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1184. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1185. $bargainNo =makeNo("BA");
  1186. Db::startTrans();//::todo 金价 毛利计算
  1187. try{
  1188. $data=[
  1189. "bidsNo"=>$bidNo,
  1190. "infoNo"=>$info['infoNo'],
  1191. "zxNo"=>$info['zxNo'],
  1192. "bargainNo"=>$bargainNo,
  1193. "bargain_type"=>1,
  1194. "bargain_reason"=>$bargain_reason,
  1195. "sale_price"=>$info['sale_price'],
  1196. "cost_before_price"=>$info['sale_cost_fee'],
  1197. "cost_after_price"=>$cost_price,
  1198. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1199. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1200. "after_price"=>$bargain_price,
  1201. "exam_info"=>"",
  1202. "status"=>0,
  1203. "is_del"=>0,
  1204. "creater"=>$creater,
  1205. "createrid"=>$createrid,
  1206. "addtime"=>date("Y-m-d H:i:s"),
  1207. "updatetime"=>date("Y-m-d H:i:s"),
  1208. 'bargain_remark'=>$bargain_remark,
  1209. 'result_info_id'=>$result_info_id,
  1210. ];
  1211. $int = Db::name("bargain_order")->insert($data);
  1212. if($int){
  1213. //修改状态,添加待办
  1214. ActionLog::logAdd($this->post['token'], [
  1215. "order_code" => $bargainNo,//咨询单详情编号
  1216. "status" => 0,//这里的status是之前的值
  1217. "action_remark" => '',//备注
  1218. "action_type" => "status"//新建create,编辑edit,更改状态status
  1219. ], "YJD", $data['status'], $data);
  1220. ProcessOrder::AddProcess($this->post['token'], [
  1221. "order_type" => 'YJD',
  1222. "order_code" => $bargainNo,
  1223. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1224. "order_status" =>0,"before_status"=>0
  1225. ]);
  1226. $odlstatus=$info['status'];
  1227. $info['status']=3;
  1228. $info['updatetime']=date("Y-m-d H:i:s");
  1229. $up =Db::name("consult_bids")->save($info);
  1230. if($up){
  1231. //修改状态,添加待办
  1232. ActionLog::logAdd($this->post['token'], [
  1233. "order_code" => $bidNo,//咨询单详情编号
  1234. "status" => $odlstatus,//这里的status是之前的值
  1235. "action_remark" => '',//备注
  1236. "action_type" => "status"//新建create,编辑edit,更改状态status
  1237. ], "FKD", $info['status'], $info);
  1238. $old_infos_status = $infos['status'];
  1239. $infos['status']=3;
  1240. $infos['updatetime']=date("Y-m-d H:i:s");
  1241. $ups =Db::name("consult_info")->save($infos);
  1242. if($ups){
  1243. //修改状态,添加待办
  1244. ActionLog::logAdd($this->post['token'], [
  1245. "order_code" => $infos['infoNo'],//咨询单详情编号
  1246. "status" => $old_infos_status,//这里的status是之前的值
  1247. "action_remark" => '',//备注
  1248. "action_type" => "status"//新建create,编辑edit,更改状态status
  1249. ], "ZXD", $infos['status'], $infos);
  1250. Db::commit();
  1251. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1252. }
  1253. }
  1254. }
  1255. Db::rollback();
  1256. return error_show(1004,"议价单新建失败");
  1257. }catch (\Exception $e){
  1258. Db::rollback();
  1259. return error_show(1004,$e->getMessage());
  1260. }
  1261. }
  1262. //选择商品
  1263. public function bids_check(){
  1264. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1265. if($bidNo===""){
  1266. return error_show(1004,"参数bidNo不能为空");
  1267. }
  1268. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1269. if($info==false){
  1270. return error_show(1004,"未找到商品数据");
  1271. }
  1272. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1273. if($infos==false){
  1274. return error_show(1004,"未找到商品数据");
  1275. }
  1276. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1277. return error_show(1004,"咨询单招标未结束或已确认商品");
  1278. }
  1279. Db::startTrans();
  1280. try {
  1281. $oldstattus=$info['status'];
  1282. $info['status']=6;
  1283. $info['updatetime']=date("Y-m-d H:i:s");
  1284. $bids = Db::name("consult_bids")->save($info);
  1285. if($bids){
  1286. //修改状态,添加待办
  1287. ActionLog::logAdd($this->post['token'], [
  1288. "order_code" =>$bidNo,//咨询单详情编号
  1289. "status" => $oldstattus,//这里的status是之前的值
  1290. "action_remark" => '',//备注
  1291. "action_type" => "status"//新建create,编辑edit,更改状态status
  1292. ], "FKD", $info['status'], $info);
  1293. $old_infos_status = $infos['status'];
  1294. $infos['status']=4;
  1295. $infos['updatetime']=date("Y-m-d H:i:s");
  1296. $se = Db::name("consult_info")->save($infos);
  1297. if($se){
  1298. //修改状态,添加待办
  1299. ActionLog::logAdd($this->post['token'], [
  1300. "order_code" => $infos['infoNo'],//咨询单详情编号
  1301. "status" => $old_infos_status,//这里的status是之前的值
  1302. "action_remark" => '',//备注
  1303. "action_type" => "status"//新建create,编辑edit,更改状态status
  1304. ], "ZXD", $infos['status'], $infos);
  1305. Db::commit();
  1306. return app_show(0,"商品确定成功");
  1307. }
  1308. }
  1309. Db::rollback();
  1310. return error_show(1004,"商品确认失败");
  1311. }catch (\Exception $e){
  1312. Db::rollback();
  1313. return error_show(1004,$e->getMessage());
  1314. }
  1315. }
  1316. //议价审核
  1317. /**
  1318. * status:
  1319. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1320. */
  1321. public function bargain_status(){
  1322. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1323. if($bargainNo===""){
  1324. return error_show(1004,"参数bargainNo不能为空");
  1325. }
  1326. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1327. if($info==false){
  1328. return error_show(1004,"未找到议价数据");
  1329. }
  1330. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1331. if($bids==false){
  1332. return error_show(1004,"未找到商品数据");
  1333. }
  1334. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1335. if($coninfo==false){
  1336. return error_show(1004,"未找到咨询单数据");
  1337. }
  1338. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1339. if($status===''){
  1340. return error_show(1005,"参数status不能为空");
  1341. }
  1342. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1343. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1344. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1345. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1346. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1347. if($bids['is_gold_price']==1){
  1348. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1349. ->find();
  1350. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1351. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1352. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1353. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1354. $saleprice =$total_fe / (1 - $budget);
  1355. $rate_price = $total_fe / (1 - $rate);
  1356. $money_price =$total_fe / (1 - $money_rate);
  1357. $lower_price =$total_fe / (1 - $lower_rate);
  1358. }else{
  1359. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1360. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1361. if($bids['nake_fee']!=0){
  1362. $saleprice = ($total_fe)/ (1 - $budget);
  1363. $rate_price = ($total_fe)/ (1 - $rate);
  1364. $money_price =($total_fe)/ (1 - $money_rate);
  1365. $lower_price = ($total_fe) / (1 - $lower_rate);
  1366. }else{
  1367. $saleprice = $total_fe / (1 - $budget);
  1368. $rate_price =$total_fe/ (1 - $rate);
  1369. $money_price =$total_fe / (1 - $money_rate);
  1370. $lower_price = $total_fe/ (1 - $lower_rate);
  1371. }
  1372. }
  1373. $ra_status = $info['status'];
  1374. if($status==1){
  1375. if($info['status']==0){
  1376. if($info['after_price']<$rate_price){
  1377. $info['status']=2;
  1378. }else{
  1379. $info['status']=1;
  1380. }
  1381. }elseif($info['status']==2){
  1382. $info['status']=4;
  1383. }elseif($info['status']==4||$info['status']==5){
  1384. if($info['after_price']<$money_price){
  1385. $info['status']=7;
  1386. }else{
  1387. $info['status']=6;
  1388. }
  1389. }elseif($info['status']==7){
  1390. $info['lower_price'] =$lower_price;
  1391. if($info['after_price']<$lower_price){
  1392. $info['status']=10;
  1393. }else{
  1394. $info['status']=9;
  1395. }
  1396. }
  1397. }else{
  1398. if($info['status']==0){
  1399. $info['status']=3;
  1400. }elseif($info['status']==2){
  1401. $info['status']=4;
  1402. }elseif($info['status']==4||$info['status']==5){
  1403. $info['status']=8;
  1404. }elseif($info['status']==7){
  1405. $info['lower_price'] =$lower_price;
  1406. $info['status']=11;
  1407. }
  1408. }
  1409. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1410. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1411. if($token==''){
  1412. return error_show(105,"参数token不能为空");
  1413. }
  1414. $user =GetUserInfo($token);
  1415. if(empty($user)||$user['code']!=0){
  1416. return error_show(1002,"用户数据不存在");
  1417. }
  1418. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1419. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1420. Db::startTrans();
  1421. try{
  1422. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1423. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1424. "creater"=>$creater];
  1425. // $info['status'] =$status;
  1426. $info['remark'] =$remark;
  1427. $info['exam_info']=json_encode($examinfo) ;
  1428. $info['updatetime'] =date("Y-m-d H:i:s");
  1429. $up =Db::name("bargain_order")->save($info);
  1430. if($up){
  1431. //修改状态,添加待办
  1432. ActionLog::logAdd($this->post['token'], [
  1433. "order_code" => $bargainNo,//咨询单详情编号
  1434. "status" =>$ra_status,//这里的status是之前的值
  1435. "action_remark" => '',//备注
  1436. "action_type" => "status"//新建create,编辑edit,更改状态status
  1437. ], "YJD", $info['status'], $info);
  1438. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1439. ProcessOrder::AddProcess($token,$process);
  1440. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1441. $bidstatus=$bids['status'];
  1442. $bids['status']=5;
  1443. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1444. $bids['sale_price']=$info['after_price'];
  1445. if($bids['is_gold_price']==1){
  1446. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1447. // ->find();
  1448. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1449. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1450. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1451. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1452. }
  1453. }
  1454. $bids['updatetime']=date("Y-m-d H:i:s");
  1455. $up =Db::name("consult_bids")->save($bids);
  1456. if($up==false){
  1457. Db::rollback();
  1458. return error_show(1004,"数据更新失败");
  1459. }
  1460. ActionLog::logAdd($this->post['token'], [
  1461. "order_code" => $info["bidsNo"],//咨询单详情编号
  1462. "status" => $bidstatus,//这里的status是之前的值
  1463. "action_remark" => '',//备注
  1464. "action_type" => "status"//新建create,编辑edit,更改状态status
  1465. ], "FKD", $bids['status'], $bids);
  1466. }
  1467. Db::commit();
  1468. return app_show(0,"更新成功");
  1469. }
  1470. }catch (\Exception $e){
  1471. Db::rollback();
  1472. return error_show(1004,$e->getMessage());
  1473. }
  1474. }
  1475. public function bargain_info(){
  1476. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1477. if($bargainNo===""){
  1478. return error_show(1004,"参数bargainNo不能为空");
  1479. }
  1480. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1481. if($info==false){
  1482. return error_show(1004,"未找到议价数据");
  1483. }
  1484. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1485. if($bidinfos==false){
  1486. return error_show(1004,"未找到商品数据");
  1487. }
  1488. $consultinfos = Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])
  1489. ->find();
  1490. if($consultinfos==false){
  1491. return error_show(1004,"未找到咨询商品数据");
  1492. }
  1493. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1494. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1495. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1496. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1497. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1498. $info['before_rate'] =round($info['before_rate']*100,2);
  1499. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1500. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1501. $info['after_rate'] = round($info['after_rate']*100,2);
  1502. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1503. if($bidinfos['brand_id']!=0){
  1504. $info['brand_id'] = $bidinfos['brand_id'];
  1505. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1506. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1507. }else{
  1508. $info["brand_name"]="";
  1509. $info["brand_id"]="";
  1510. }
  1511. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1512. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1513. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1514. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1515. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1516. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1517. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1518. $info['budget'] =$budget;
  1519. $god=[
  1520. "metal_id"=>$bidinfos['metal_id'],
  1521. "weight"=>$bidinfos["good_weight"],
  1522. "demo_fee"=>$bidinfos["demo_fee"],
  1523. "delivery_fee"=>$bidinfos["delivery_fee"],
  1524. "open_fee"=>$bidinfos["open_fee"],
  1525. "packing_fee"=>$bidinfos["pakge_fee"],
  1526. "mark_fee"=>$bidinfos["mark_fee"],
  1527. "nake_fee"=>$bidinfos["nake_fee"],
  1528. "cert_fee"=>$bidinfos["cert_fee"],
  1529. "cost_fee"=>$bidinfos["cost_fee"],
  1530. "num"=>$bidinfoe["num"],
  1531. ];
  1532. $info['gold_price']=0;
  1533. $info['noble_weight']=$bidinfos['good_weight'];
  1534. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1535. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1536. ->find();
  1537. $info['gold_price'] =$gold['price'];
  1538. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1539. }else{
  1540. if($bidinfos['nake_fee']!=0){
  1541. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1542. }else{
  1543. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1544. }
  1545. }
  1546. $info['cost_desc'] =$bidinfos['cost_desc'];
  1547. $info['work_day'] =$bidinfos['work_day'];
  1548. $info['delivery_day'] =$bidinfos['delivery_day'];
  1549. $info['expire_day'] =$bidinfos['expire_day'];
  1550. $info['origin_place'] =$bidinfos['origin_place'];
  1551. $info['origin_addr'] ="";
  1552. if($bidinfos['origin_place']!=''){
  1553. $code = explode(",",$bidinfos['origin_place']);
  1554. $temp=[];
  1555. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1556. $temp['city_code']=isset($code[1])?$code[1]:"";
  1557. $temp['area_code']=isset($code[2])?$code[2]:"";
  1558. $addr= GetAddr(json_encode($temp));
  1559. $info['origin_addr'] = $addr;
  1560. }
  1561. $info['supplierNo'] =$bidinfos['supplierNo'];
  1562. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1563. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1564. $info['pay_way'] =$bidinfos['pay_way'];
  1565. $info['tax'] =$bidinfos['tax'];
  1566. $info['send_way'] =$bidinfos['send_way'];
  1567. $info['metal_id'] =$bidinfos['metal_id'];
  1568. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1569. $info['config'] =$bidinfos['config'];
  1570. $info['other_config'] =$bidinfos['other_config'];
  1571. $info['weight'] =$bidinfos['weight'];
  1572. $info['good_weight'] =$bidinfos['good_weight'];
  1573. $info['is_diff'] =$bidinfos['is_diff'];
  1574. $info['demo_fee'] =$bidinfos['demo_fee'];
  1575. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1576. $info['open_fee'] =$bidinfos['open_fee'];
  1577. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1578. $info['nake_fee'] =$bidinfos['nake_fee'];
  1579. $info['mark_fee'] =$bidinfos['mark_fee'];
  1580. $info['cert_fee'] =$bidinfos['cert_fee'];
  1581. $info['cost_fee'] =$bidinfos['cost_fee'];
  1582. $info['total_fee'] =$bidinfos['total_fee'];
  1583. $info['supply_area'] =$bidinfos['supply_area'];
  1584. $info['remark'] =$bidinfos['remark'];
  1585. $info['is_addrs'] =$consultinfos['is_addrs'];
  1586. $info['is_custom'] =$consultinfos['is_custom'];
  1587. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1588. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1589. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1590. if($info['status']==7){
  1591. $info['lower_price'] =round($lower_price,2);
  1592. }
  1593. //获取议价原因
  1594. if ($info['result_info_id'] != 0) {
  1595. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1596. } else {
  1597. $info['result_info'] = '';
  1598. }
  1599. return app_show(0,"获取成功",$info);
  1600. }
  1601. public function bidlist(){
  1602. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1603. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1604. $where=[['is_del',"=",0]];
  1605. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1606. if ($zxNo !== "") {
  1607. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1608. }
  1609. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1610. if ($infoNo !== "") {
  1611. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1612. }
  1613. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1614. if ($bidNo !== "") {
  1615. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1616. }
  1617. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1618. if ($pgNo !== "") {
  1619. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1620. $where[] = ['infoNo','in',$bidinfo];
  1621. }
  1622. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1623. if ($bargain_status !== "") {
  1624. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1625. $where[] = ['infoNo','in',$bidinfo];
  1626. }
  1627. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1628. if ($projectNo !== "") {
  1629. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1630. ("zxNo");
  1631. $where[] = ['zxNo','in',$zxlist];
  1632. }
  1633. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1634. if($is_own==1){
  1635. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1636. if($token==""){
  1637. return error_show(101,'token不能为空');
  1638. }
  1639. $apply_id =GetUserInfo($token);
  1640. if(empty($apply_id)||$apply_id['code']!=0){
  1641. return error_show(1002,"申请人数据不存在");
  1642. }
  1643. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1644. $where[]=['createrid',"=",$rm];
  1645. }
  1646. $count = Db::name('consult_bids')->where($where)->count();
  1647. $total = ceil($count / $size);
  1648. $page = $page >= $total ? $total : $page;
  1649. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1650. $data=[];
  1651. foreach ($list as $value){
  1652. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1653. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1654. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1655. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1656. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1657. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1658. if($value['brand_id']!=0){
  1659. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1660. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1661. }else{
  1662. $value["brand_name"]="";
  1663. $value["brand_id"]="";
  1664. }
  1665. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1666. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1667. $god=[
  1668. "metal_id"=>$value['metal_id'],
  1669. "weight"=>$value["good_weight"],
  1670. "demo_fee"=>$value["demo_fee"],
  1671. "delivery_fee"=>$value["delivery_fee"],
  1672. "open_fee"=>$value["open_fee"],
  1673. "packing_fee"=>$value["pakge_fee"],
  1674. "mark_fee"=>$value["mark_fee"],
  1675. "nake_fee"=>$value["nake_fee"],
  1676. "cert_fee"=>$value["cert_fee"],
  1677. "cost_fee"=>$value['status']>=5? $value["sale_cost_fee"]: $value["cost_fee"],
  1678. "num"=>$bidinfo["num"],
  1679. ];
  1680. if($value['is_gold_price']==1){
  1681. $price = GoldPrice($god, $budget/100);
  1682. $value['sale_price'] = round($price,2);
  1683. }
  1684. $value['cost_fee'] =$value['origin_cost_fee'];
  1685. $value['specinfo'] = json_decode($value['specinfo'],true);
  1686. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1687. $value['bargain_status']=$bidinfo['bargain_status'];
  1688. //reject驳回原因,status==5表示驳回
  1689. $value['reject']=[];
  1690. if ($value['status'] >=5) {
  1691. $value['reject'] = Db::name('bargain_order')
  1692. ->field('id,remark,status')
  1693. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1694. ->whereIn('status', [3,8,11])->order("id desc")
  1695. ->find();
  1696. }
  1697. //产地
  1698. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1699. if($value['delivery_place']!=""){
  1700. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1701. }
  1702. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1703. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1704. if($value['origin_place']!=""){
  1705. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1706. }
  1707. $value['origin_addr']=GetAddr(json_encode($place));
  1708. // if($value['origin_place']!=''){
  1709. // $code = explode(",",$value['origin_place']);
  1710. // $temp=[];
  1711. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1712. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1713. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1714. // $addr= GetAddr(json_encode($temp));
  1715. // $value['origin_addr'] = $addr;
  1716. // }
  1717. $data[] = $value;
  1718. }
  1719. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1720. }
  1721. public function feedlist(){
  1722. $where=[['is_del',"=",0]];
  1723. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1724. if ($zxNo !== "") {
  1725. $where[] = ['zxNo','=',$zxNo];
  1726. }
  1727. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1728. if ($infoNo !== "") {
  1729. $where[] = ['infoNo','=',$infoNo];
  1730. }
  1731. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1732. if ($bidNo !== "") {
  1733. $where[] = ['bidNo','=',$bidNo];
  1734. }
  1735. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1736. if ($projectNo !== "") {
  1737. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1738. ("zxNo");
  1739. $where[] = ['zxNo','in',$zxlist];
  1740. }
  1741. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1742. if($token==''){
  1743. return error_show(102,"参数token不能为空");
  1744. }
  1745. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1746. if($is_own==1){
  1747. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1748. if($token==""){
  1749. return error_show(101,'token不能为空');
  1750. }
  1751. $apply_id =GetUserInfo($token);
  1752. if(empty($apply_id)||$apply_id['code']!=0){
  1753. return error_show(1002,"申请人数据不存在");
  1754. }
  1755. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1756. $where[]=['createrid',"=",$rm];
  1757. }
  1758. $list =Db::name('consult_bids')->where($where)->select();
  1759. $data=[];
  1760. foreach ($list as $value){
  1761. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1762. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1763. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1764. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1765. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1766. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1767. if($value['brand_id']!=0){
  1768. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1769. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1770. }else{
  1771. $value["brand_name"]="";
  1772. $value["brand_id"]="";
  1773. }
  1774. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1775. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1776. $god=[
  1777. "metal_id"=>$value['metal_id'],
  1778. "weight"=>$value["good_weight"],
  1779. "demo_fee"=>$value["demo_fee"],
  1780. "delivery_fee"=>$value["delivery_fee"],
  1781. "open_fee"=>$value["open_fee"],
  1782. "packing_fee"=>$value["pakge_fee"],
  1783. "mark_fee"=>$value["mark_fee"],
  1784. "nake_fee"=>$value["nake_fee"],
  1785. "cert_fee"=>$value["cert_fee"],
  1786. "cost_fee"=>$value["cost_fee"],
  1787. "num"=>$bidinfo["num"],
  1788. ];
  1789. if ($value['is_gold_price'] == 1 ) {
  1790. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1791. ->find();
  1792. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1793. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1794. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1795. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1796. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1797. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1798. }else{
  1799. if($value["nake_fee"]){
  1800. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1801. }else{
  1802. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1803. (1 - $budget);
  1804. }
  1805. }
  1806. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1807. $value['specinfo'] = json_decode($value['specinfo'],true);
  1808. $value['bargain_status']=$bidinfo['bargain_status'];
  1809. $data[]=$value;
  1810. }
  1811. return app_show(0,"获取成功",$data);
  1812. }
  1813. public function bragain_list(){
  1814. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1815. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1816. $where=[['is_del',"=",0]];
  1817. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1818. if($bidsNo!=""){
  1819. $where[]=["bidsNo","=",$bidsNo];
  1820. }
  1821. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1822. if ($zxNo !== "") {
  1823. $where[] = ['zxNo','=',$zxNo];
  1824. }
  1825. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1826. if ($bargainNo !== "") {
  1827. $where[] = ['bargainNo','=',$bargainNo];
  1828. }
  1829. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1830. if ($status!== "") {
  1831. $where[] = ['status','=',$status];
  1832. }
  1833. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1834. if ($infoNo !== "") {
  1835. $where[] = ['infoNo','=',$infoNo];
  1836. }
  1837. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1838. if ($projectNo !== "") {
  1839. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1840. ("zxNo");
  1841. $where[] = ['zxNo','in',$zxlist];
  1842. }
  1843. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1844. if ($pgNo !== "") {
  1845. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1846. $where[] = ['infoNo','in',$bidinfo];
  1847. }
  1848. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1849. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1850. if($start!=""){
  1851. $where[]=["addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1852. }
  1853. if($end!=""){
  1854. $where[]=["addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1855. }
  1856. $role=$this->checkRole();
  1857. if(!empty($role['write'])){
  1858. $where[]=["createrid","in",$role['write']];
  1859. }
  1860. $count=Db::name("bargain_order")->where($where)->count();
  1861. $total = ceil($count / $size);
  1862. $page = $page >= $total ? $total : $page;
  1863. $list =Db::name('bargain_order')->where($where)->page($page,$size)->order('addtime','desc')->select();
  1864. $data=[];
  1865. foreach ($list as $value){
  1866. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1867. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1868. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1869. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1870. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1871. if($bidinfos['brand_id']!=0){
  1872. $value['brand_id'] = $bidinfos['brand_id'];
  1873. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1874. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1875. }else{
  1876. $value["brand_name"]="";
  1877. $value["brand_id"]="";
  1878. }
  1879. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1880. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1881. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1882. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1883. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1884. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1885. $value['budget'] =$budget;
  1886. $god=[
  1887. "metal_id"=>$bidinfos['metal_id'],
  1888. "weight"=>$bidinfos["good_weight"],
  1889. "demo_fee"=>$bidinfos["demo_fee"],
  1890. "delivery_fee"=>$bidinfos["delivery_fee"],
  1891. "open_fee"=>$bidinfos["open_fee"],
  1892. "packing_fee"=>$bidinfos["pakge_fee"],
  1893. "mark_fee"=>$bidinfos["mark_fee"],
  1894. "nake_fee"=>$bidinfos["nake_fee"],
  1895. "cert_fee"=>$bidinfos["cert_fee"],
  1896. "cost_fee"=>$bidinfos["cost_fee"],
  1897. "num"=>$bidinfoe["num"],
  1898. ];
  1899. // if($bidinfos['is_gold_price']==1){
  1900. // $price = GoldPrice($god, $budget/100);
  1901. // }else{
  1902. // $price = GoodPrice($god, $budget/100);
  1903. // }
  1904. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1905. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1906. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1907. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1908. $data[]=$value;
  1909. }
  1910. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1911. }
  1912. public function crontablist(){
  1913. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1914. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1915. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1916. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1917. if ($zxNo !== "") {
  1918. $where[] = ['a.zxNo','=',$zxNo];
  1919. }
  1920. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1921. if ($salesman !== "") {
  1922. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1923. $where[]= ["b.salesman",'like',"%$salesman%"];
  1924. }
  1925. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1926. if ($cpName !== "") {
  1927. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1928. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1929. }
  1930. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1931. if ($khNo !== "") {
  1932. // $where['khNo'] = $khNo;
  1933. $where[]= ["b.khNo",'like',"%$khNo%"];
  1934. }
  1935. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  1936. if ($start !="") {
  1937. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  1938. $where[]= ["a.addtime",'>=',$start];
  1939. }
  1940. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  1941. if($end !=""){
  1942. $where[]= ["a.addtime",'<=',$end];
  1943. }
  1944. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1945. if ($status !== "") {
  1946. $where[]= ["a.status",'=',$status];
  1947. }
  1948. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  1949. ->count();
  1950. $total = ceil($count / $size);
  1951. $page = $page >= $total ? $total : $page;
  1952. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  1953. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  1954. $data=[];
  1955. foreach ($list as $value){
  1956. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1957. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  1958. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  1959. $value['khname']="";
  1960. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  1961. true):[];
  1962. if($value['khNo']!==""){
  1963. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  1964. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  1965. }
  1966. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1967. $data[]=$value;
  1968. }
  1969. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1970. }
  1971. }